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
add view for wp calendar
ulfertsc6723187f0dc
diff --git a/app/contracts/views/calendar_strategy.rb b/app/contracts/views/calendar_strategy.rbnew file mode 100644index 00000000000..b66fbaba628--- /dev/null+++ b/app/contracts/views/calendar_strategy.rb@@ -0,0 +1,21 @@+module Views+ class CalendarStrategy < ::BaseContract+ validate :manageable++ private++ def manageable+ return if model.query.blank?++ errors.add(:base, :error_unauthorized) unless query_permissions?+ end++ def query_permissions?+ user_allowed_on_query?(:view_calendar)+ end++ def user_allowed_on_query?(permission)+ user.allowed_to?(permission, model.query.project, global: model.query.project.nil?)+ end+ end+enddiff --git a/config/initializers/register_views.rb b/config/initializers/register_views.rbindex 78ec3178fc9..f0877b2bd1d 100644--- a/config/initializers/register_views.rb+++ b/config/initializers/register_views.rb@@ -29,3 +29,5 @@require Rails.root.join('config/constants/views')Constants::Views.add :WorkPackagesTable+Constants::Views.add :WorkPackagesCalendar,+ contract_strategy: 'Views::CalendarStrategy'diff --git a/docs/api/apiv3/paths/views_{identifier}.yml b/docs/api/apiv3/paths/views_{identifier}.ymlindex 520f5e836d9..2fdaba94bec 100644--- a/docs/api/apiv3/paths/views_{identifier}.yml+++ b/docs/api/apiv3/paths/views_{identifier}.yml@@ -80,7 +80,11 @@ post:Note that it is only allowed to provide properties or links supporting the write operation.There are different subtypes of `Views` (e.g. `Views::WorkPackagesTable`) with each having its own- endpoint for creating that subtype e.g. `/api/v3/views/work_packages_table` for `Views::WorkPackagesTable` and `/api/v3/views/team_planner` for `Views::TeamPlanner`+ endpoint for creating that subtype e.g.++ * `/api/v3/views/work_packages_table` for `Views::WorkPackagesTable`+ * `/api/v3/views/team_planner` for `Views::TeamPlanner`+ * `/api/v3/views/work_packages_calendar` for `Views::WorkPackagesCalendar`**Not yet implemented** To get the list of available subtypes and by that the endpoints for creating a subtype, use the```diff --git a/spec/contracts/views/create_contract_work_packages_table_spec.rb b/spec/contracts/views/create_contract_work_packages_table_spec.rbindex dd2d113b720..2716dd5c76c 100644--- a/spec/contracts/views/create_contract_work_packages_table_spec.rb+++ b/spec/contracts/views/create_contract_work_packages_table_spec.rb@@ -55,6 +55,20 @@ describe Views::CreateContract doit_behaves_like 'contract is invalid', type: :inclusionend++ context 'with a work_packages_calendar view with the user having the permission to view_calendar' do+ let(:permissions) { %i[view_work_packages save_queries view_calendar] }+ let(:view_type) { 'work_packages_calendar' }++ it_behaves_like 'contract is valid'+ end++ context 'with a work_packages_calendar view with the user not having the permission to view_calendar' do+ let(:permissions) { %i[view_work_packages save_queries] }+ let(:view_type) { 'work_packages_calendar' }++ it_behaves_like 'contract is invalid', base: :error_unauthorized+ endendendenddiff --git a/spec/requests/api/v3/views/create_resource_spec.rb b/spec/requests/api/v3/views/create_resource_spec.rbindex dfb1e1c9a2c..a1199a8a984 100644--- a/spec/requests/api/v3/views/create_resource_spec.rb+++ b/spec/requests/api/v3/views/create_resource_spec.rb@@ -107,6 +107,45 @@ describe ::API::V3::Views::ViewsAPI,endend+ describe 'POST /api/v3/views/work_packages_calendar' do+ let(:send_request) do+ post api_v3_paths.views_type('work_packages_calendar'), body+ end++ context 'with a user allowed to save the query and see the calendar' do+ let(:additional_setup) do+ role.update_attribute(:permissions, role.permissions + [:view_calendar])+ end++ it 'returns 201 CREATED' do+ expect(response.status)+ .to eq(201)+ end++ it 'returns the view' do+ expect(response.body)+ .to be_json_eql('Views::WorkPackagesCalendar'.to_json)+ .at_path('_type')++ expect(response.body)+ .to be_json_eql(View.last.id.to_json)+ .at_path('id')+ end+ end++ context 'with a user allowed to save the query but not to view calendars' do+ it_behaves_like 'unauthorized access'+ end++ context 'with a user not allowed to see the query' do+ let(:additional_setup) do+ role.update_attribute(:permissions, [])+ end++ it_behaves_like 'unauthorized access'+ end+ end+describe 'POST /api/v3/views/bogus' dolet(:send_request) dopost api_v3_paths.views_type('bogus'), body