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

[#41299] updated placeholder user api spec

Eric Schubert1d77a71a615b
diff --git a/docs/api/apiv3/components/schemas/group_model.yml b/docs/api/apiv3/components/schemas/group_model.yml
index 00c68d09675..e5818c4f088 100644
--- a/docs/api/apiv3/components/schemas/group_model.yml
+++ b/docs/api/apiv3/components/schemas/group_model.yml
@@ -4,8 +4,13 @@ allOf:
- $ref: './principal_model.yml'
- type: object
required:
+ - _type
- _embedded
properties:
+ _type:
+ type: string
+ enum:
+ - Group
_embedded:
type: object
properties:
diff --git a/docs/api/apiv3/components/schemas/placeholder_user_model.yml b/docs/api/apiv3/components/schemas/placeholder_user_model.yml
index 563758b9542..7193afd18cc 100644
--- a/docs/api/apiv3/components/schemas/placeholder_user_model.yml
+++ b/docs/api/apiv3/components/schemas/placeholder_user_model.yml
@@ -3,7 +3,21 @@
allOf:
- $ref: './principal_model.yml'
- type: object
+ required:
+ - _type
properties:
+ _type:
+ type: string
+ enum:
+ - PlaceholderUser
+ status:
+ type: string
+ description: |-
+ The current activation status of the placeholder user.
+
+ # Conditions
+
+ - User has `manage_placeholder_user` permission globally
_links:
type: object
required:
diff --git a/docs/api/apiv3/components/schemas/user_model.yml b/docs/api/apiv3/components/schemas/user_model.yml
index 4cce47faa1a..97a850cb8a4 100644
--- a/docs/api/apiv3/components/schemas/user_model.yml
+++ b/docs/api/apiv3/components/schemas/user_model.yml
@@ -4,8 +4,13 @@ allOf:
- $ref: './principal_model.yml'
- type: object
required:
+ - _type
- avatar
properties:
+ _type:
+ type: string
+ enum:
+ - User
avatar:
type: string
format: uri
diff --git a/docs/api/apiv3/paths/group.yml b/docs/api/apiv3/paths/group.yml
index 2e181bd0daa..f45dd4465fb 100644
--- a/docs/api/apiv3/paths/group.yml
+++ b/docs/api/apiv3/paths/group.yml
@@ -17,7 +17,7 @@ delete:
responses:
'202':
description: |-
- Returned if the group was successfully deleted
+ Returned if the group was marked for deletion.
Note that the response body is empty as of now. In future versions of the API a body
*might* be returned, indicating the progress of deletion.
diff --git a/docs/api/apiv3/paths/placeholder_user.yml b/docs/api/apiv3/paths/placeholder_user.yml
index 693abca4b10..f4609c601da 100644
--- a/docs/api/apiv3/paths/placeholder_user.yml
+++ b/docs/api/apiv3/paths/placeholder_user.yml
@@ -15,8 +15,12 @@ delete:
schema:
type: integer
responses:
- '204':
- description: Returned if the placeholder user was deleted successfully.
+ '202':
+ description: |-
+ Returned if the group was marked for deletion.
+
+ Note that the response body is empty as of now. In future versions of the API a body
+ *might* be returned, indicating the progress of deletion.
'403':
content:
application/hal+json:
diff --git a/lib/api/v3/placeholder_users/placeholder_user_representer.rb b/lib/api/v3/placeholder_users/placeholder_user_representer.rb
index 758b3f662ec..f783a96eda8 100644
--- a/lib/api/v3/placeholder_users/placeholder_user_representer.rb
+++ b/lib/api/v3/placeholder_users/placeholder_user_representer.rb
@@ -55,10 +55,21 @@ module API
}
end
+ property :status,
+ getter: ->(*) { represented.status },
+ setter: ->(fragment:, represented:, **) { represented.status = User.statuses[fragment.to_sym] },
+ exec_context: :decorator,
+ render_nil: true,
+ cache_if: -> { current_user_can_manage? }
+
def _type
'PlaceholderUser'
end
+ def current_user_can_see_date_properties?
+ current_user_can_manage?
+ end
+
def current_user_can_manage?
current_user&.allowed_globally?(:manage_placeholder_user)
end
diff --git a/lib/api/v3/placeholder_users/placeholder_users_api.rb b/lib/api/v3/placeholder_users/placeholder_users_api.rb
index 012293616a5..4b986ac0e5d 100644
--- a/lib/api/v3/placeholder_users/placeholder_users_api.rb
+++ b/lib/api/v3/placeholder_users/placeholder_users_api.rb
@@ -49,7 +49,7 @@ module API
get &::API::V3::Utilities::Endpoints::Show.new(model: PlaceholderUser).mount
patch &::API::V3::Utilities::Endpoints::Update.new(model: PlaceholderUser).mount
- delete &::API::V3::Utilities::Endpoints::Delete.new(model: PlaceholderUser, success_status: 204).mount
+ delete &::API::V3::Utilities::Endpoints::Delete.new(model: PlaceholderUser, success_status: 202).mount
end
end
end
diff --git a/lib/api/v3/principals/principal_representer.rb b/lib/api/v3/principals/principal_representer.rb
index c02ef31d3db..7a9c07b6a36 100644
--- a/lib/api/v3/principals/principal_representer.rb
+++ b/lib/api/v3/principals/principal_representer.rb
@@ -63,10 +63,14 @@ module API
render_nil: true
date_time_property :created_at,
- cache_if: -> { current_user_is_admin_or_self }
+ cache_if: -> { current_user_can_see_date_properties? }
date_time_property :updated_at,
- cache_if: -> { current_user_is_admin_or_self }
+ cache_if: -> { current_user_can_see_date_properties? }
+
+ def current_user_can_see_date_properties?
+ current_user_is_admin_or_self
+ end
def current_user_is_admin_or_self
current_user_is_admin? || current_user_is_self?
diff --git a/spec/lib/api/v3/placeholder_users/placeholder_user_representer_rendering_spec.rb b/spec/lib/api/v3/placeholder_users/placeholder_user_representer_rendering_spec.rb
index 3648a4f8441..030fa8d2c30 100644
--- a/spec/lib/api/v3/placeholder_users/placeholder_user_representer_rendering_spec.rb
+++ b/spec/lib/api/v3/placeholder_users/placeholder_user_representer_rendering_spec.rb
@@ -140,15 +140,15 @@ RSpec.describe API::V3::PlaceholderUsers::PlaceholderUserRepresenter, 'rendering
let(:value) { 'PlaceholderUser' }
end
- context 'as regular user' do
- it_behaves_like 'property', :id do
- let(:value) { placeholder_user.id }
- end
+ it_behaves_like 'property', :id do
+ let(:value) { placeholder_user.id }
+ end
- it_behaves_like 'property', :name do
- let(:value) { placeholder_user.name }
- end
+ it_behaves_like 'property', :name do
+ let(:value) { placeholder_user.name }
+ end
+ context 'as regular user' do
it 'hides the updatedAt property' do
expect(subject).not_to have_json_path('updatedAt')
end
@@ -158,15 +158,11 @@ RSpec.describe API::V3::PlaceholderUsers::PlaceholderUserRepresenter, 'rendering
end
end
- context 'as admin' do
- let(:current_user) { build_stubbed(:admin) }
-
- it_behaves_like 'property', :id do
- let(:value) { placeholder_user.id }
- end
+ context 'if user is allowed to manage placeholder users' do
+ let(:global_permissions) { [:manage_placeholder_user] }
- it_behaves_like 'property', :name do
- let(:value) { placeholder_user.name }
+ it_behaves_like 'property', :status do
+ let(:value) { 'active' }
end
it_behaves_like 'datetime property', :createdAt do
diff --git a/spec/requests/api/v3/placeholder_users/delete_resource_examples.rb b/spec/requests/api/v3/placeholder_users/delete_resource_examples.rb
index 562f0dbf73b..41478c989d3 100644
--- a/spec/requests/api/v3/placeholder_users/delete_resource_examples.rb
+++ b/spec/requests/api/v3/placeholder_users/delete_resource_examples.rb
@@ -26,8 +26,8 @@
# See COPYRIGHT and LICENSE files for more details.
RSpec.shared_examples 'deletion allowed' do
- it 'responds with 204' do
- expect(last_response.status).to eq 204
+ it 'responds with 202' do
+ expect(last_response.status).to eq 202
end
it 'locks the account and mark for deletion' do