Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

have hal conforming link to bcf comment in activity

ulferts5861da0d6da7
diff --git a/frontend/src/app/components/wp-activity/user/user-activity.component.html b/frontend/src/app/components/wp-activity/user/user-activity.component.html
index b4d78915e13..32dffe5dc92 100644
--- a/frontend/src/app/components/wp-activity/user/user-activity.component.html
+++ b/frontend/src/app/components/wp-activity/user/user-activity.component.html
@@ -38,8 +38,8 @@
</accessible-by-keyboard>
</div>
</div>
- <img *ngIf="bcfSnapshot"
- [src]="PathHelper.attachmentDownloadPath(bcfSnapshot.id, bcfSnapshot.file_name)"
+ <img *ngIf="bcfSnapshotUrl"
+ [src]="bcfSnapshotUrl"
class="activity-thumbnail">
<div class="user-comment" >
<div *ngIf="active" class="inplace-edit">
diff --git a/frontend/src/app/components/wp-activity/user/user-activity.component.ts b/frontend/src/app/components/wp-activity/user/user-activity.component.ts
index df2850a4561..d32f06c90a3 100644
--- a/frontend/src/app/components/wp-activity/user/user-activity.component.ts
+++ b/frontend/src/app/components/wp-activity/user/user-activity.component.ts
@@ -73,8 +73,6 @@ export class UserActivityComponent extends WorkPackageCommentFieldHandler implem
public isComment:boolean;
public isBcfComment:boolean;
public postedComment:SafeHtml;
- // TODO: turn into HalResource
- public bcfSnapshot:any;
public focused = false;
@@ -107,9 +105,6 @@ export class UserActivityComponent extends WorkPackageCommentFieldHandler implem
this.updateCommentText();
this.isComment = this.activity._type === 'Activity::Comment';
this.isBcfComment = this.activity._type === 'Activity::BcfComment';
- if (this.isBcfComment && _.get(this.activity.bcfComment, 'viewpoint.snapshot')) {
- this.bcfSnapshot = _.get(this.activity.bcfComment, 'viewpoint.snapshot');
- }
this.$element = jQuery(this.elementRef.nativeElement);
this.reset();
@@ -162,6 +157,14 @@ export class UserActivityComponent extends WorkPackageCommentFieldHandler implem
this.commentService.quoteEvents.next(this.quotedText(this.activity.comment.raw));
}
+ public get bcfSnapshotUrl() {
+ if (_.get(this.activity, 'bcfViewpoints[0]')) {
+ return `${_.get(this.activity, 'bcfViewpoints[0]').href}/snapshot`;
+ } else {
+ return null;
+ }
+ }
+
public async updateComment() {
this.inFlight = true;
diff --git a/modules/bim/lib/api/bim/utilities/path_helper.rb b/modules/bim/lib/api/bim/utilities/path_helper.rb
index ccc9413a3ea..c550330df30 100644
--- a/modules/bim/lib/api/bim/utilities/path_helper.rb
+++ b/modules/bim/lib/api/bim/utilities/path_helper.rb
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2020 the OpenProject GmbH
@@ -35,6 +36,7 @@ module API
# rubocop:disable Naming/ClassAndModuleCamelCase
class BCF2_1Path
+ # rubocop:enable Naming/ClassAndModuleCamelCase
extend API::Utilities::UrlHelper
# Determining the root_path on every url we want to render is
diff --git a/modules/bim/lib/open_project/bim/engine.rb b/modules/bim/lib/open_project/bim/engine.rb
index 4a54b039e40..de67100a2e7 100644
--- a/modules/bim/lib/open_project/bim/engine.rb
+++ b/modules/bim/lib/open_project/bim/engine.rb
@@ -141,27 +141,22 @@ module OpenProject::Bim
end
extend_api_response(:v3, :activities, :activity) do
- property :bcf_comment,
- exec_context: :decorator,
- getter: ->(*) {
- bcf_comment = represented.bcf_comment
- comment = {
- id: bcf_comment.id
- }
- if bcf_comment.viewpoint.present?
- comment[:viewpoint] = {
- snapshot: {
- id: bcf_comment.viewpoint.snapshot.id,
- file_name: bcf_comment.viewpoint.snapshot.filename
- }
- }
- end
+ include API::Bim::Utilities::PathHelper
- comment
- },
- if: ->(*) {
- represented.bcf_comment.present?
- }
+ links :bcfViewpoints do
+ journable = represented.journable
+ next unless current_user_allowed_to(:view_linked_issues) && represented.bcf_comment.present? && journable.bcf_issue?
+
+ # There will only be one viewpoint per comment but we nevertheless return a collection here so that it is more
+ # similar to the work package representer.
+ Array(represented.bcf_comment.viewpoint).map do |viewpoint|
+ {
+ href: bcf_v2_1_paths.viewpoint(journable.project.identifier,
+ journable.bcf_issue.uuid,
+ viewpoint.uuid)
+ }
+ end
+ end
end
add_api_path :bcf_xml do |project_id|
diff --git a/modules/bim/spec/api/v3/activities/activity_representer_spec.rb b/modules/bim/spec/api/v3/activities/activity_representer_spec.rb
new file mode 100644
index 00000000000..53554829592
--- /dev/null
+++ b/modules/bim/spec/api/v3/activities/activity_representer_spec.rb
@@ -0,0 +1,135 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2020 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2017 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'spec_helper'
+
+describe ::API::V3::Activities::ActivityRepresenter do
+ include API::Bim::Utilities::PathHelper
+
+ let(:current_user) do
+ FactoryBot.build_stubbed(:user).tap do |u|
+ allow(u)
+ .to receive(:allowed_to?) do |checked_permission, project|
+ project == work_package.project && permissions.include?(checked_permission)
+ end
+ end
+ end
+ let(:other_user) { FactoryBot.build_stubbed(:user) }
+ let(:work_package) do
+ journal.journable.tap do |wp|
+ allow(wp)
+ .to receive(:bcf_issue)
+ .and_return(bcf_topic)
+ end
+ end
+ let(:journal) do
+ FactoryBot.build_stubbed(:work_package_journal).tap do |journal|
+ allow(journal)
+ .to receive(:notes_id)
+ .and_return(journal.id)
+ allow(journal)
+ .to receive(:get_changes)
+ .and_return(changes)
+ allow(journal)
+ .to receive(:bcf_comment)
+ .and_return(bcf_comment)
+ end
+ end
+ let(:changes) { { subject: ["first subject", "second subject"] } }
+ let(:bcf_topic) do
+ FactoryBot.build_stubbed(:bcf_issue_with_comment)
+ end
+ let(:bcf_comment) { bcf_topic.comments.first }
+ let(:permissions) { %i(edit_work_package_notes view_linked_issues) }
+ let(:representer) { described_class.new(journal, current_user: current_user) }
+
+ before do
+ login_as(current_user)
+ end
+
+ subject(:generated) { representer.to_json }
+
+ describe 'type' do
+ context 'if a bcf_comment is present' do
+ let(:notes) { '' }
+ it 'is Activity::BcfComment' do
+ is_expected
+ .to be_json_eql('Activity::BcfComment'.to_json)
+ .at_path('_type')
+ end
+ end
+ end
+
+ describe '_links' do
+ describe 'bcfViewpoints' do
+ context 'if a viewpoint is present' do
+ it_behaves_like 'has a link collection' do
+ let(:link) { 'bcfViewpoints' }
+ let(:hrefs) do
+ [
+ {
+ href: bcf_v2_1_paths.viewpoint(work_package.project.identifier, bcf_topic.uuid, bcf_topic.viewpoints[0].uuid)
+ }
+ ]
+ end
+ end
+
+ context 'if no comment is present' do
+ let(:bcf_comment) { nil }
+
+ it_behaves_like 'has no link' do
+ let(:link) { 'bcfViewpoints' }
+ end
+ end
+
+ context 'if no viewpoint is linked' do
+ before do
+ allow(bcf_comment)
+ .to receive(:viewpoint)
+ .and_return nil
+ end
+
+ it_behaves_like 'has a link collection' do
+ let(:link) { 'bcfViewpoints' }
+ let(:hrefs) do
+ []
+ end
+ end
+ end
+
+ context 'if permission is lacking' do
+ let(:permissions) { %i[] }
+
+ it_behaves_like 'has no link' do
+ let(:link) { 'bcfViewpoints' }
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/lib/api/v3/activities/activity_representer_spec.rb b/spec/lib/api/v3/activities/activity_representer_spec.rb
index c3e3099cee9..dfb79af68db 100644
--- a/spec/lib/api/v3/activities/activity_representer_spec.rb
+++ b/spec/lib/api/v3/activities/activity_representer_spec.rb
@@ -51,9 +51,6 @@ describe ::API::V3::Activities::ActivityRepresenter do
end
end
let(:changes) { { subject: ["first subject", "second subject"] } }
- let(:aggregated_journal) do
- Journal::AggregatedJournal.new(journal)
- end
let(:permissions) { %i(edit_work_package_notes) }
let(:representer) { described_class.new(journal, current_user: current_user) }