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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
visibility check for relations api
ulferts1b7d66bea7fe
diff --git a/lib/api/v3/relations/relations_api.rb b/lib/api/v3/relations/relations_api.rbindex cf40459e507..ee1ac75a3b2 100644--- a/lib/api/v3/relations/relations_api.rb+++ b/lib/api/v3/relations/relations_api.rb@@ -50,19 +50,17 @@ module APIendroute_param :id, type: Integer, desc: 'Relation ID' do- get do- representer.new(- Relation.find_by_id!(params[:id]),- current_user: current_user,- embed_links: true- )+ after_validation do+ @relation = Relation.visible.find(params[:id])end+ get &::API::V3::Utilities::Endpoints::Show.new(model: Relation).mount+patch dorep = parse_representer.new Relation.new, current_user: current_userrelation = rep.from_json request.body.readattributes = filter_attributes relation- service = ::Relations::UpdateService.new relation: Relation.find_by_id!(params[:id]),+ service = ::Relations::UpdateService.new relation: @relation,user: current_usercall = service.call attributes: attributes,send_notifications: (params[:notify] != 'false')diff --git a/spec/requests/api/v3/relations/relations_api_spec.rb b/spec/requests/api/v3/relations/relations_api_spec.rbindex b572c5575b4..e134e61abec 100644--- a/spec/requests/api/v3/relations/relations_api_spec.rb+++ b/spec/requests/api/v3/relations/relations_api_spec.rb@@ -32,6 +32,7 @@ describe 'API v3 Relation resource', type: :request, content_type: :json doinclude API::V3::Utilities::PathHelperlet(:user) { FactoryBot.create :admin }+ let(:current_user) { user }let!(:from) { FactoryBot.create :work_package }let!(:to) { FactoryBot.create :work_package }@@ -65,7 +66,7 @@ describe 'API v3 Relation resource', type: :request, content_type: :json doendbefore do- login_as user+ login_as current_userenddescribe "creating a relation" do@@ -446,4 +447,58 @@ describe 'API v3 Relation resource', type: :request, content_type: :json do.at_path('_embedded/elements/0/id')endend++ describe 'GET /api/v3/relations/:id' do+ let(:path) do+ api_v3_paths.relation(relation.id)+ end++ let(:role) { FactoryBot.create(:role, permissions: [:view_work_packages]) }++ let(:current_user) do+ FactoryBot.create(:user).tap do |user|+ FactoryBot.create(:member,+ project: to.project,+ user: user,+ roles: [role])+ FactoryBot.create(:member,+ project: from.project,+ user: user,+ roles: [role])+ end+ end++ before do+ get path+ end++ context 'for a relation with visible work packages' do+ it 'returns 200' do+ expect(last_response.status).to eql 200+ end++ it 'returns the relation' do+ expect(last_response.body)+ .to be_json_eql API::V3::Relations::RelationRepresenter.new(relation, current_user: current_user, embed_links: true).to_json+ end+ end++ context 'for a relation with an invisible work package' do+ let(:invisible_relation) do+ invisible_wp = FactoryBot.create(:work_package)++ FactoryBot.create :relation,+ from: from,+ to: invisible_wp+ end++ let(:path) do+ api_v3_paths.relation(invisible_relation.id)+ end++ it 'returns 404 NOT FOUND' do+ expect(last_response.status).to eql 404+ end+ end+ endenddiff --git a/spec/requests/api/v3/relations_resource_spec.rb b/spec/requests/api/v3/relations_resource_spec.rbindex 2582d51a4a2..57c6416b4db 100644--- a/spec/requests/api/v3/relations_resource_spec.rb+++ b/spec/requests/api/v3/relations_resource_spec.rb@@ -36,21 +36,21 @@ describe 'API v3 Relation resource', type: :request dolet(:project) { FactoryBot.create(:project_with_types) }let(:current_user) doFactoryBot.create(:user,- member_in_project: project,- member_through_role: role)+ member_in_project: project,+ member_through_role: role)endlet(:permissions) { [] }let(:role) { FactoryBot.create(:role, permissions: permissions) }let(:work_package) doFactoryBot.create(:work_package,- project: project,- type: project.types.first)+ project: project,+ type: project.types.first)endlet(:visible_work_package) doFactoryBot.create(:work_package,- project: project,- type: project.types.first)+ project: project,+ type: project.types.first)endlet(:invisible_work_package) do# will be inside another project@@ -58,13 +58,13 @@ describe 'API v3 Relation resource', type: :request doendlet(:visible_relation) doFactoryBot.create(:relation,- from: work_package,- to: visible_work_package)+ from: work_package,+ to: visible_work_package)endlet(:invisible_relation) doFactoryBot.create(:relation,- from: work_package,- to: invisible_work_package)+ from: work_package,+ to: invisible_work_package)endbefore do