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
Implement hasReadonlyStatus
Oliver Günthere4df121ca4d3
diff --git a/app/models/status.rb b/app/models/status.rbindex 52f4832465e..ddb77b955cd 100644--- a/app/models/status.rb+++ b/app/models/status.rb@@ -79,6 +79,11 @@ class Status < ApplicationRecordorder(:position)end+ def self.can_readonly?+ EnterpriseToken.allows_to?(:readonly_work_packages)+ end+ delegate :can_readonly?, to: :class+def <=>(other)position <=> other.positionend@@ -98,10 +103,6 @@ class Status < ApplicationRecordsuper + '/' + can_readonly?.to_send- def can_readonly?- EnterpriseToken.allows_to?(:readonly_work_packages)- end-privatedef check_integritydiff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rbindex e70c9c2ad51..732a20a64f1 100644--- a/lib/api/v3/work_packages/work_package_representer.rb+++ b/lib/api/v3/work_packages/work_package_representer.rb@@ -352,10 +352,10 @@ module APInext unless doc.key?('date')date = decorator- .datetime_formatter- .parse_date(doc['date'],- name.to_s.camelize(:lower),- allow_nil: true)+ .datetime_formatter+ .parse_date(doc['date'],+ name.to_s.camelize(:lower),+ allow_nil: true)self.due_date = self.start_date = date},@@ -427,6 +427,15 @@ module APIif: ->(*) { embed_links },uncacheable: true+ property :hasReadonlyStatus,+ writeable: false,+ render_nil: false,+ getter: ->(*) do+ if status_id && ::Status.can_readonly?+ status.is_readonly?+ end+ end+associated_resource :categoryassociated_resource :type@@ -443,19 +452,19 @@ module APIassociated_resource :responsible,getter: ::API::V3::Principals::PrincipalRepresenterFactory- .create_getter_lambda(:responsible),+ .create_getter_lambda(:responsible),setter: ::API::V3::Principals::PrincipalRepresenterFactory- .create_setter_lambda(:responsible),+ .create_setter_lambda(:responsible),link: ::API::V3::Principals::PrincipalRepresenterFactory- .create_link_lambda(:responsible)+ .create_link_lambda(:responsible)associated_resource :assignee,getter: ::API::V3::Principals::PrincipalRepresenterFactory- .create_getter_lambda(:assigned_to),+ .create_getter_lambda(:assigned_to),setter: ::API::V3::Principals::PrincipalRepresenterFactory- .create_setter_lambda(:assigned_to, property_name: :assignee),+ .create_setter_lambda(:assigned_to, property_name: :assignee),link: ::API::V3::Principals::PrincipalRepresenterFactory- .create_link_lambda(:assigned_to)+ .create_link_lambda(:assigned_to)associated_resource :version,v3_path: :version,@@ -485,16 +494,17 @@ module APIhref = fragment['href']- new_parent = if href- id = ::API::Utilities::ResourceLinkParser- .parse_id href,- property: 'parent',- expected_version: '3',- expected_namespace: 'work_packages'+ new_parent =+ if href+ id = ::API::Utilities::ResourceLinkParser+ .parse_id href,+ property: 'parent',+ expected_version: '3',+ expected_namespace: 'work_packages'- WorkPackage.find_by(id:) ||- ::WorkPackage::InexistentWorkPackage.new(id:)- end+ WorkPackage.find_by(id:) ||+ ::WorkPackage::InexistentWorkPackage.new(id:)+ endrepresented.parent = new_parentend@@ -550,8 +560,8 @@ module APIdef relationsself_path = api_v3_paths.work_package_relations(represented.id)visible_relations = represented- .visible_relations(current_user)- .includes(::API::V3::Relations::RelationCollectionRepresenter.to_eager_load)+ .visible_relations(current_user)+ .includes(::API::V3::Relations::RelationCollectionRepresenter.to_eager_load)::API::V3::Relations::RelationCollectionRepresenter.new(visible_relations,self_link: self_path,@@ -572,7 +582,7 @@ module APIdef derived_estimated_time=(value)represented.derived_estimated_hours = datetime_formatter- .parse_duration_to_hours(value, 'derivedEstimatedTime', allow_nil: true)+ .parse_duration_to_hours(value, 'derivedEstimatedTime', allow_nil: true)enddef spent_time=(value)diff --git a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_representer_spec.rbindex df0ebb1a0d6..f033ce59491 100644--- a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb+++ b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb@@ -363,6 +363,31 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter doit { is_expected.to be_json_eql(work_package.lock_version.to_json).at_path('lockVersion') }end++ describe 'hasReadonlyStatus' do+ context 'no status' do+ let(:status) { nil }+ it 'renders nothing' do+ is_expected.not_to have_json_path('hasReadonlyStatus')+ end+ end++ context 'false', with_ee: %i[readonly_work_packages] do+ let(:status) { build_stubbed :status, is_readonly: false }++ it 'renders as false' do+ is_expected.to be_json_eql(false.to_json).at_path('hasReadonlyStatus')+ end+ end++ context 'true', with_ee: %i[readonly_work_packages] do+ let(:status) { build_stubbed :status, is_readonly: true }++ it 'renders as true' do+ is_expected.to be_json_eql(true.to_json).at_path('hasReadonlyStatus')+ end+ end+ endenddescribe 'estimatedTime' do