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
[#42362] added storages link to project representer
Eric Schubert6140875b141f
diff --git a/lib/api/v3/projects/project_representer.rb b/lib/api/v3/projects/project_representer.rbindex 886c71cb1a1..83429a65180 100644--- a/lib/api/v3/projects/project_representer.rb+++ b/lib/api/v3/projects/project_representer.rb@@ -88,6 +88,18 @@ module API{ href: api_v3_paths.work_packages_by_project(represented.id) }end+ links :storages,+ cache_if: -> {+ current_user_allowed_to(:view_file_links, context: represented)+ } do+ represented.storages.map do |storage|+ {+ href: api_v3_paths.storage(storage.id),+ title: storage.name+ }+ end+ end+link :categories do{ href: api_v3_paths.categories_by_project(represented.id) }enddiff --git a/spec/lib/api/v3/projects/project_representer_rendering_spec.rb b/spec/lib/api/v3/projects/project_representer_rendering_spec.rbindex 6b4447781db..a3fd4a06592 100644--- a/spec/lib/api/v3/projects/project_representer_rendering_spec.rb+++ b/spec/lib/api/v3/projects/project_representer_rendering_spec.rb@@ -40,16 +40,16 @@ describe ::API::V3::Projects::ProjectRepresenter, 'rendering' dostatus: status).tap do |p|allow(p).to receive(:available_custom_fields)- .and_return([int_custom_field, version_custom_field])+ .and_return([int_custom_field, version_custom_field])allow(p).to receive(:"custom_field_#{int_custom_field.id}")- .and_return(int_custom_value.value)+ .and_return(int_custom_value.value)allow(p).to receive(:custom_value_for)- .with(version_custom_field)- .and_return(version_custom_value)+ .with(version_custom_field)+ .and_return(version_custom_value)allow(p).to receive(:ancestors_from_root)@@ -91,10 +91,10 @@ describe ::API::V3::Projects::ProjectRepresenter, 'rendering' doCustomValue.new(custom_field: version_custom_field,value: version.id,customized: nil).tap do |cv|- allow(cv)- .to receive(:typed_value)- .and_return(version)- end+ allow(cv)+ .to receive(:typed_value)+ .and_return(version)+ endendlet(:permissions) { %i[add_work_packages view_members] }@@ -130,10 +130,8 @@ describe ::API::V3::Projects::ProjectRepresenter, 'rendering' dolet(:value) { project.description }end- context 'statusExplanation' do- it_behaves_like 'formattable property', 'statusExplanation' do- let(:value) { status.explanation }- end+ it_behaves_like 'formattable property', 'statusExplanation' do+ let(:value) { status.explanation }endit_behaves_like 'has UTC ISO 8601 date and time' do@@ -146,25 +144,23 @@ describe ::API::V3::Projects::ProjectRepresenter, 'rendering' dolet(:json_path) { 'updatedAt' }end- context 'int custom field' do+ describe 'int custom field' docontext 'if the user is admin' dobefore doallow(user).to receive(:admin?)- .and_return(true)+ .and_return(true)endit "has a property for the int custom field" do- is_expected- .to be_json_eql(int_custom_value.value.to_json)- .at_path("customField#{int_custom_field.id}")+ expect(subject).to be_json_eql(int_custom_value.value.to_json)+ .at_path("customField#{int_custom_field.id}")endendcontext 'if the user is no admin' doit "has no property for the int custom field" do- is_expected- .not_to have_json_path("customField#{int_custom_field.id}")+ expect(subject).not_to have_json_path("customField#{int_custom_field.id}")endendend@@ -176,25 +172,25 @@ describe ::API::V3::Projects::ProjectRepresenter, 'rendering' doit 'links to self' doexpect(subject).to have_json_path('_links/self/href')end+it 'has a title for link to self' doexpect(subject).to have_json_path('_links/self/title')enddescribe 'create work packages' do- context 'user allowed to create work packages' do+ context 'if user is allowed to create work packages' doit 'has the correct path for a create form' do- is_expected- .to be_json_eql(api_v3_paths.create_project_work_package_form(project.id).to_json)- .at_path('_links/createWorkPackage/href')+ expect(subject).to be_json_eql(api_v3_paths.create_project_work_package_form(project.id).to_json)+ .at_path('_links/createWorkPackage/href')endit 'has the correct path to create a work package' do- is_expected.to be_json_eql(api_v3_paths.work_packages_by_project(project.id).to_json)- .at_path('_links/createWorkPackageImmediately/href')+ expect(subject).to be_json_eql(api_v3_paths.work_packages_by_project(project.id).to_json)+ .at_path('_links/createWorkPackageImmediately/href')endend- context 'user not allowed to create work packages' do+ context 'if user is not allowed to create work packages' dolet(:permissions) { [] }it_behaves_like 'has no link' do@@ -249,7 +245,6 @@ describe ::API::V3::Projects::ProjectRepresenter, 'rendering' doendend- # rubocop:disable RSpec/MultipleMemoizedHelpersdescribe 'ancestors' dolet(:link) { 'ancestors' }let(:grandparent_project) do@@ -346,7 +341,6 @@ describe ::API::V3::Projects::ProjectRepresenter, 'rendering' doit_behaves_like 'has an empty link collection'endend- # rubocop:enable RSpec/MultipleMemoizedHelpersdescribe 'status' doit_behaves_like 'has a titled link' do@@ -367,8 +361,8 @@ describe ::API::V3::Projects::ProjectRepresenter, 'rendering' dodescribe 'categories' doit 'has the correct link to its categories' do- is_expected.to be_json_eql(api_v3_paths.categories_by_project(project.id).to_json)- .at_path('_links/categories/href')+ expect(subject).to be_json_eql(api_v3_paths.categories_by_project(project.id).to_json)+ .at_path('_links/categories/href')endend@@ -405,13 +399,13 @@ describe ::API::V3::Projects::ProjectRepresenter, 'rendering' dolet(:permissions) { [:view_work_packages] }it 'links to the types active in the project' do- is_expected.to be_json_eql(api_v3_paths.types_by_project(project.id).to_json)- .at_path('_links/types/href')+ expect(subject).to be_json_eql(api_v3_paths.types_by_project(project.id).to_json)+ .at_path('_links/types/href')endit 'links to the work packages in the project' do- is_expected.to be_json_eql(api_v3_paths.work_packages_by_project(project.id).to_json)- .at_path('_links/workPackages/href')+ expect(subject).to be_json_eql(api_v3_paths.work_packages_by_project(project.id).to_json)+ .at_path('_links/workPackages/href')endend@@ -419,8 +413,8 @@ describe ::API::V3::Projects::ProjectRepresenter, 'rendering' dolet(:permissions) { [:manage_types] }it 'links to the types active in the project' do- is_expected.to be_json_eql(api_v3_paths.types_by_project(project.id).to_json)- .at_path('_links/types/href')+ expect(subject).to be_json_eql(api_v3_paths.types_by_project(project.id).to_json)+ .at_path('_links/types/href')endend@@ -428,11 +422,11 @@ describe ::API::V3::Projects::ProjectRepresenter, 'rendering' dolet(:permission) { [] }it 'has no types link' do- is_expected.to_not have_json_path('_links/types/href')+ expect(subject).not_to have_json_path('_links/types/href')endit 'has no work packages link' do- is_expected.to_not have_json_path('_links/workPackages/href')+ expect(subject).not_to have_json_path('_links/workPackages/href')endendend@@ -452,20 +446,48 @@ describe ::API::V3::Projects::ProjectRepresenter, 'rendering' doendend+ describe 'storages' do+ let(:storage) { build_stubbed(:storage) }+ let(:permissions) { %i[view_file_links] }++ before do+ allow(project).to receive(:storages).and_return([storage])+ end++ it_behaves_like 'has a link collection' do+ let(:link) { 'storages' }+ let(:hrefs) do+ [+ {+ href: api_v3_paths.storage(storage.id),+ title: storage.name+ }+ ]+ end+ end++ context 'if user has no permission to view file links' do+ let(:permissions) { [] }++ it_behaves_like 'has no link' do+ let(:link) { 'storages' }+ end+ end+ end+describe 'link custom field' docontext 'if the user is admin and the field is invisible' dobefore doallow(user).to receive(:admin?)- .and_return(true)+ .and_return(true)version_custom_field.visible = falseendit 'links custom fields' do- is_expected- .to be_json_eql(api_v3_paths.version(version.id).to_json)- .at_path("_links/customField#{version_custom_field.id}/href")+ expect(subject).to be_json_eql(api_v3_paths.version(version.id).to_json)+ .at_path("_links/customField#{version_custom_field.id}/href")endend@@ -475,16 +497,14 @@ describe ::API::V3::Projects::ProjectRepresenter, 'rendering' doendit "has no property for the int custom field" do- is_expected- .not_to have_json_path("links/customField#{version_custom_field.id}")+ expect(subject).not_to have_json_path("links/customField#{version_custom_field.id}")endendcontext 'if the user is no admin and the field is visible' doit 'links custom fields' do- is_expected- .to be_json_eql(api_v3_paths.version(version.id).to_json)- .at_path("_links/customField#{version_custom_field.id}/href")+ expect(subject).to be_json_eql(api_v3_paths.version(version.id).to_json)+ .at_path("_links/customField#{version_custom_field.id}/href")endendend@@ -532,7 +552,7 @@ describe ::API::V3::Projects::ProjectRepresenter, 'rendering' dobefore doallow(user).to receive(:admin?)- .and_return(true)+ .and_return(true)endit_behaves_like 'has an untitled link' do@@ -590,7 +610,7 @@ describe ::API::V3::Projects::ProjectRepresenter, 'rendering' doit 'is based on the representer\'s cache_key' doallow(OpenProject::Cache).to receive(:fetch)- .and_call_original+ .and_call_originalrepresenter.to_json@@ -615,14 +635,14 @@ describe ::API::V3::Projects::ProjectRepresenter, 'rendering' doendit 'changes when the project is updated' do- project.updated_at = Time.now + 20.seconds+ project.updated_at = 20.seconds.from_nowexpect(representer.json_cache_key).not_to eql former_cache_keyendit 'changes when the project status is updated' do- project.status.updated_at = Time.now + 20.seconds+ project.status.updated_at = 20.seconds.from_nowexpect(representer.json_cache_key).not_to eql former_cache_key