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
[36296] Add PlaceholderUsers API (#9033)
Oliver Günther0a84a0b6717f
diff --git a/docs/api/apiv3/endpoints/placeholder_users.apib b/docs/api/apiv3/endpoints/placeholder_users.apibnew file mode 100644index 00000000000..0651e7b8c12--- /dev/null+++ b/docs/api/apiv3/endpoints/placeholder_users.apib@@ -0,0 +1,356 @@+# Group Placeholder Users++## Actions+| Link | Description | Condition |+|:-------------------:| -------------------------------------------------------------------- | ---------------------------------------------------------------- |+| showUser | Link to the OpenProject placeholder user page (HTML) | |+| updateImmediately | Update a placeholder from the instance | **Permission**: manage_placeholder_user |+| delete | Permanently remove a placeholder from the instance | **Permission**: manage_placeholder_user |++## Linked Properties+| Link | Description | Type | Constraints | Supported operations | Condition |+|:-----------:|-------------------------------------------------------------- | ------------- | --------------------- | -------------------- | ----------------------------------------- |+| self | This user | User | not null | READ | |+| memberships | Link to collection of all the user's memberships. The list will only include the memberships in projects in which the requesting user has the necessary permissions. | MemberCollection | | READ | **Permission**: view members or manage members in any project |++## Local Properties+| Property | Description | Type | Constraints | Supported operations | Condition |+| :----------: | --------------------------------------------------------- | -------- | ---------------------------------------------------- | -------------------- | ----------------------------------------------------------- |+| id | Placeholder user's id | Integer | x > 0 | READ | |+| name | Placeholder user's full name, formatting depends on instance settings | String | | READ | |+| createdAt | Time of creation | DateTime | | READ | |+| updatedAt | Time of the most recent change to the user | DateTime | | READ | |++## PlaceholderUser [/api/v3/placeholder_users/{id}]+++ Model+ + Body++ {+ "_type": "PlaceholderUser",+ "_links": {+ "self": {+ "href": "/api/v3/placeholder_users/1",+ "title": "placeholder"+ },+ "show": {+ "href": "/placeholder_users/1",+ "type": 'text/html'+ },+ "delete": {+ "href": "/api/v3/placeholder_users/1",+ "method": "DELETE"+ },+ },+ "id": 1,+ "name": "placeholder",+ "createdAt": "2014-05-21T08:51:20Z",+ "updatedAt": "2014-05-21T08:51:20Z"+ }++## View placeholder user [GET]+++ Parameters+ + id (required, integer)+++ Response 200 (application/hal+json)++ [PlaceholderUser][]+++ Response 404 (application/hal+json)++ Returned if the user does not exist or if the API user does not have permission to view them.++ **Required permission** The user needs to have the manage_placeholder_user permission++ + Body++ {+ "_type": "Error",+ "errorIdentifier": "urn:openproject-org:api:v3:errors:NotFound",+ "message": "The specified user does not exist or you do not have permission to view them."+ }++## Update placeholder user [PATCH]++Updates the placeholder user's writable attributes.+When calling this endpoint the client provides a single object, containing at least the properties and links that are required, in the body.+++ Parameters+ + id (required, integer, `1`) ... Placeholder user id+++ Request Update PlaceholderUser (application/json)++ + Body++ {+ "name": "New name"+ }+++ Response 200++ [PlaceholderUser][]+++ Response 400 (application/hal+json)++ Occurs when the client did not send a valid JSON object in the request body.++ + Body++ {+ "_type": "Error",+ "errorIdentifier": "urn:openproject-org:api:v3:errors:InvalidRequestBody",+ "message": "The request body was not a single JSON object."+ }+++ Response 403 (application/hal+json)++ Returned if the client does not have sufficient permissions.++ **Required permission:** Administrators, manage_placeholder_user global permission++ + Body++ {+ "_type": "Error",+ "errorIdentifier": "urn:openproject-org:api:v3:errors:MissingPermission",+ "message": "You are not allowed to access this resource."+ }+++ Response 404 (application/hal+json)++ Returned if the user does not exist.++ **Required permission:** Administrators, manage_placeholder_user global permission++ + Body++ {+ "_type": "Error",+ "errorIdentifier": "urn:openproject-org:api:v3:errors:NotFound",+ "message": "The requested resource could not be found."+ }++++ Response 422 (application/hal+json)++ Returned if:++ * the client tries to modify a read-only property (`PropertyIsReadOnly`)+ * a constraint for a property was violated (`PropertyConstraintViolation`)++ + Body++ {+ "_type": "Error",+ "errorIdentifier": "urn:openproject-org:api:v3:errors:PropertyConstraintViolation",+ "message": "Name is already taken.",+ "_embedded": {+ "details": {+ "attribute": "name"+ }+ }+ }++## Delete placeholder user [DELETE]++Permanently deletes the specified placeholder. This action will be performed asynchronously+and the response will only accept the deletion request. The actual deletion will then potentially take a while.+++ Parameters+ + id (required, integer, `1`) ... Placeholder user id+++ Response 202++ Returned if the account was successfully scheduled for deletion.++ + Body+++ Response 403 (application/hal+json)++ Returned if the client does not have sufficient permissions.++ **Required permission:** Administrators or manage_placeholder_user permission++ + Body++ {+ "_type": "Error",+ "errorIdentifier": "urn:openproject-org:api:v3:errors:MissingPermission",+ "message": "You are not authorized to access this resource"+ }+++ Response 404 (application/hal+json)++ Returned if the user does not exist.++ + Body++ {+ "_type": "Error",+ "errorIdentifier": "urn:openproject-org:api:v3:errors:NotFound",+ "message": "The requested resource could not be found."+ }++## PlaceholderUsers [/api/v3/users{?offset,pageSize,filters,sortBy}]+++ Model+ + Body++ {+ "_links": {+ "self": { "href": "/api/v3/placeholder_users" }+ },+ "total": 2,+ "count": 1,+ "_type": "Collection",+ "_embedded": {+ "elements": [+ {+ "_type": "PlaceholderUser",+ "_links": {+ "self": {+ "href": "/api/v3/placeholder_users/1",+ "title": "placeholder"+ },+ "showUser": {+ "href": "/placeholder_users/1",+ "type": 'text/html'+ },+ "updateImmediately": {+ "href": "/api/v3/placeholder_users/1",+ "title": "Update placeholder"+ "method": "PATCH"+ },+ "delete": {+ "href": "/api/v3/placeholder_users/1",+ "title": "Delete placeholder"+ "method": "DELETE"+ }+ },+ "id": 1,+ "name": "placeholder",+ "createdAt": "2014-05-21T08:51:20Z",+ "updatedAt": "2014-05-21T08:51:20Z"+ }+ ]+ }+ }++## List Placeholder Users [GET]++Lists placeholders. Only administrators or users with manage_placeholder_user global permission have permission to do this.+++ Parameters+ + offset = `1` (optional, integer, `25`) ... Page number inside the requested collection.++ + pageSize (optional, integer, `25`) ... Number of elements to display per page.++ + filters (optional, string, `[{ "group": { "operator": "=", "values": ["1"] } }, { "name": { "operator": "=", "values": ["placeholder"] } }]`) ... JSON specifying filter conditions.+ Accepts the same format as returned by the [queries](#queries) endpoint. Currently supported filters are:+ + group: Name of the group in which to-be-listed placeholder users are members.+ + name: Filter placeholder users in whose first or last names, or email addresses the given string occurs.+ + status: Filter placeholder users by their status. Possible values are "active" and "locked"++ + sortBy (optional, string, `[["name", "asc"]]`) ... JSON specifying sort criteria.+ Accepts the same format as returned by the [queries](#queries) endpoint.++ Currently supported orders are:+ + id+ + name+ + group+++ Response 200 (application/hal+json)++ [PlaceholderUsers][]+++ Response 400 (application/hal+json)++ Returned if the client sends an unknown sort column.++ + Body++ {+ "_type": "Error",+ "errorIdentifier": "urn:openproject-org:api:v3:errors:InvalidQuery",+ "message": "Unknown sort column."+ }++++ Response 403 (application/hal+json)++ Returned if the client does not have sufficient permissions.++ **Required permission:** Administrator or manage_placeholder_user permission++ + Body++ {+ "_type": "Error",+ "errorIdentifier": "urn:openproject-org:api:v3:errors:MissingPermission",+ "message": "You are not authorized to access this resource."+ }++## Create placeholder user [/api/v3/placeholder_users]++## Create Placeholder User [POST]++Creates a new placeholder user. Only administrators and users with manage_placeholder_user global permission are allowed to do so.+When calling this endpoint the client provides a single object, containing at least the properties and links that are required, in the body.+++ Request Create User (application/json)++ + Body++ {+ "name": "placeholder"+ }+++ Response 201++ [PlaceholderUser][]+++ Response 400 (application/hal+json)++ Occurs when the client did not send a valid JSON object in the request body.++ + Body++ {+ "_type": "Error",+ "errorIdentifier": "urn:openproject-org:api:v3:errors:InvalidRequestBody",+ "message": "The request body was not a single JSON object."+ }+++ Response 403 (application/hal+json)++ Returned if the client does not have sufficient permissions.++ **Required permission:** Administrator or manage_placeholder_user++ + Body++ {+ "_type": "Error",+ "errorIdentifier": "urn:openproject-org:api:v3:errors:MissingPermission",+ "message": "You are not authorized to access this resource."+ }+++ Response 422 (application/hal+json)++ Returned if:++ * a constraint for a property was violated (`PropertyConstraintViolation`)++ + Body++ {+ "_type": "Error",+ "errorIdentifier": "urn:openproject-org:api:v3:errors:PropertyConstraintViolation",+ "message": "Name is already taken.",+ "_embedded": {+ "details": {+ "attribute": "name"+ }+ }+ }diff --git a/lib/api/decorators/collection.rb b/lib/api/decorators/collection.rbindex fd6340a177f..91b6711d071 100644--- a/lib/api/decorators/collection.rb+++ b/lib/api/decorators/collection.rb@@ -47,7 +47,19 @@ module APIenddef element_decorator- self.class.element_decorator_class+ self.class.element_decorator_class || deduce_element_decorator+ end++ def deduce_element_decorator+ name = self.class.name++ unless name.end_with?('CollectionRepresenter')+ raise ArgumentError, "Can't deduce representer name from #{name}, please specify it with `element_decorator ClassName`"+ end++ name+ .gsub("CollectionRepresenter", "Representer")+ .constantizeendlink :self dodiff --git a/lib/api/v3/activities/activity_collection_representer.rb b/lib/api/v3/activities/activity_collection_representer.rbindex 9db95db4764..e48634d6e26 100644--- a/lib/api/v3/activities/activity_collection_representer.rb+++ b/lib/api/v3/activities/activity_collection_representer.rb@@ -32,7 +32,6 @@ module APImodule V3module Activitiesclass ActivityCollectionRepresenter < ::API::Decorators::UnpaginatedCollection- element_decorator ::API::V3::Activities::ActivityRepresenterendendenddiff --git a/lib/api/v3/attachments/attachment_collection_representer.rb b/lib/api/v3/attachments/attachment_collection_representer.rbindex 7b21060e1e0..8f60c6704a3 100644--- a/lib/api/v3/attachments/attachment_collection_representer.rb+++ b/lib/api/v3/attachments/attachment_collection_representer.rb@@ -32,7 +32,6 @@ module APImodule V3module Attachmentsclass AttachmentCollectionRepresenter < ::API::Decorators::UnpaginatedCollection- element_decorator ::API::V3::Attachments::AttachmentRepresenterendendenddiff --git a/lib/api/v3/categories/category_collection_representer.rb b/lib/api/v3/categories/category_collection_representer.rbindex 184edda880c..f07ad94cd42 100644--- a/lib/api/v3/categories/category_collection_representer.rb+++ b/lib/api/v3/categories/category_collection_representer.rb@@ -32,7 +32,6 @@ module APImodule V3module Categoriesclass CategoryCollectionRepresenter < ::API::Decorators::UnpaginatedCollection- element_decorator ::API::V3::Categories::CategoryRepresenterendendenddiff --git a/lib/api/v3/help_texts/help_text_collection_representer.rb b/lib/api/v3/help_texts/help_text_collection_representer.rbindex 9e28fb65c5c..4de88b23c33 100644--- a/lib/api/v3/help_texts/help_text_collection_representer.rb+++ b/lib/api/v3/help_texts/help_text_collection_representer.rb@@ -32,7 +32,6 @@ module APImodule V3module HelpTextsclass HelpTextCollectionRepresenter < ::API::Decorators::UnpaginatedCollection- element_decorator ::API::V3::HelpTexts::HelpTextRepresenterendendenddiff --git a/lib/api/v3/memberships/membership_collection_representer.rb b/lib/api/v3/memberships/membership_collection_representer.rbindex 123a9087a43..c1d3d862295 100644--- a/lib/api/v3/memberships/membership_collection_representer.rb+++ b/lib/api/v3/memberships/membership_collection_representer.rb@@ -32,7 +32,6 @@ module APImodule V3module Membershipsclass MembershipCollectionRepresenter < ::API::Decorators::OffsetPaginatedCollection- element_decorator ::API::V3::Memberships::MembershipRepresenterendendenddiff --git a/lib/api/v3/news/news_collection_representer.rb b/lib/api/v3/news/news_collection_representer.rbindex 938ba68044b..3a31d4c196a 100644--- a/lib/api/v3/news/news_collection_representer.rb+++ b/lib/api/v3/news/news_collection_representer.rb@@ -32,7 +32,6 @@ module APImodule V3module Newsclass NewsCollectionRepresenter < ::API::Decorators::OffsetPaginatedCollection- element_decorator ::API::V3::News::NewsRepresenterendendenddiff --git a/lib/api/v3/placeholder_users/placeholder_user_collection_representer.rb b/lib/api/v3/placeholder_users/placeholder_user_collection_representer.rbnew file mode 100644index 00000000000..68885bffc86--- /dev/null+++ b/lib/api/v3/placeholder_users/placeholder_user_collection_representer.rb@@ -0,0 +1,38 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++module API+ module V3+ module PlaceholderUsers+ class PlaceholderUserCollectionRepresenter < ::API::Decorators::OffsetPaginatedCollection+ end+ end+ end+enddiff --git a/lib/api/v3/placeholder_users/placeholder_user_payload_representer.rb b/lib/api/v3/placeholder_users/placeholder_user_payload_representer.rbnew file mode 100644index 00000000000..6a3c87d4640--- /dev/null+++ b/lib/api/v3/placeholder_users/placeholder_user_payload_representer.rb@@ -0,0 +1,39 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++module API+ module V3+ module PlaceholderUsers+ class PlaceholderUserPayloadRepresenter < PlaceholderUserRepresenter+ include ::API::Utilities::PayloadRepresenter+ end+ end+ end+enddiff --git a/lib/api/v3/placeholder_users/placeholder_user_representer.rb b/lib/api/v3/placeholder_users/placeholder_user_representer.rbindex bc3e8f8a472..b1d66f8541a 100644--- a/lib/api/v3/placeholder_users/placeholder_user_representer.rb+++ b/lib/api/v3/placeholder_users/placeholder_user_representer.rb@@ -32,9 +32,39 @@ module APImodule V3module PlaceholderUsersclass PlaceholderUserRepresenter < ::API::V3::Principals::PrincipalRepresenter+ link :updateImmediately,+ cache_if: -> { current_user_can_manage? } do+ {+ href: api_v3_paths.placeholder_user(represented.id),+ title: "Update #{represented.name}",+ method: :patch+ }+ end++ link :delete,+ cache_if: -> { current_user_can_manage? } do+ {+ href: api_v3_paths.placeholder_user(represented.id),+ title: "Delete #{represented.name}",+ method: :delete+ }+ end++ link :showUser do+ {+ href: api_v3_paths.placeholder_user_path(represented.id),+ type: 'text/html'+ }+ end++def _type'PlaceholderUser'end++ def current_user_can_manage?+ current_user&.allowed_to_globally?(:manage_placeholder_user)+ endendendenddiff --git a/lib/api/v3/placeholder_users/placeholder_users_api.rb b/lib/api/v3/placeholder_users/placeholder_users_api.rbnew file mode 100644index 00000000000..3d75bc2bb2c--- /dev/null+++ b/lib/api/v3/placeholder_users/placeholder_users_api.rb@@ -0,0 +1,59 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++module API+ module V3+ module PlaceholderUsers+ class PlaceholderUsersAPI < ::API::OpenProjectAPI+ resources :placeholder_users do+ after_validation do+ authorize_any %i[manage_placeholder_user], global: true+ end++ get &::API::V3::Utilities::Endpoints::Index+ .new(model: PlaceholderUser)+ .mount++ post &::API::V3::Utilities::Endpoints::Create+ .new(model: PlaceholderUser)+ .mount++ route_param :id, type: Integer, desc: 'Placeholder user ID' do+ after_validation do+ @placeholder_user = PlaceholderUser.find(params[:id])+ end++ 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: 202).mount+ end+ end+ end+ end+ end+enddiff --git a/lib/api/v3/priorities/priority_collection_representer.rb b/lib/api/v3/priorities/priority_collection_representer.rbindex 6c6b72e17db..502cc92699a 100644--- a/lib/api/v3/priorities/priority_collection_representer.rb+++ b/lib/api/v3/priorities/priority_collection_representer.rb@@ -32,7 +32,6 @@ module APImodule V3module Prioritiesclass PriorityCollectionRepresenter < ::API::Decorators::UnpaginatedCollection- element_decorator ::API::V3::Priorities::PriorityRepresenterendendenddiff --git a/lib/api/v3/projects/project_collection_representer.rb b/lib/api/v3/projects/project_collection_representer.rbindex 0d6d9d46b55..da365802812 100644--- a/lib/api/v3/projects/project_collection_representer.rb+++ b/lib/api/v3/projects/project_collection_representer.rb@@ -37,8 +37,6 @@ module APImodule V3module Projectsclass ProjectCollectionRepresenter < ::API::Decorators::UnpaginatedCollection- element_decorator ::API::V3::Projects::ProjectRepresenter-self.to_eager_load = ::API::V3::Projects::ProjectRepresenter.to_eager_loadself.checked_permissions = ::API::V3::Projects::ProjectRepresenter.checked_permissionsdiff --git a/lib/api/v3/queries/query_collection_representer.rb b/lib/api/v3/queries/query_collection_representer.rbindex e356c39b7c2..0162e6004a8 100644--- a/lib/api/v3/queries/query_collection_representer.rb+++ b/lib/api/v3/queries/query_collection_representer.rb@@ -32,8 +32,6 @@ module APImodule V3module Queriesclass QueryCollectionRepresenter < ::API::Decorators::UnpaginatedCollection- element_decorator ::API::V3::Queries::QueryRepresenter-def initialize(models, self_link:, current_user:)super(models.includes(::API::V3::Queries::QueryRepresenter.to_eager_load),self_link: self_link,diff --git a/lib/api/v3/queries/schemas/query_filter_instance_schema_collection_representer.rb b/lib/api/v3/queries/schemas/query_filter_instance_schema_collection_representer.rbindex 2039671bb75..61924554f42 100644--- a/lib/api/v3/queries/schemas/query_filter_instance_schema_collection_representer.rb+++ b/lib/api/v3/queries/schemas/query_filter_instance_schema_collection_representer.rb@@ -34,7 +34,6 @@ module APImodule Schemasclass QueryFilterInstanceSchemaCollectionRepresenter <::API::V3::Schemas::SchemaCollectionRepresenter- element_decorator ::API::V3::Queries::Schemas::QueryFilterInstanceSchemaRepresenterdef model_self_link(model)converted_name = API::Utilities::PropertyNameConverter.from_ar_name(model.name)diff --git a/lib/api/v3/relations/relation_collection_representer.rb b/lib/api/v3/relations/relation_collection_representer.rbindex 5979c7375ad..d3a99dbbcfe 100644--- a/lib/api/v3/relations/relation_collection_representer.rb+++ b/lib/api/v3/relations/relation_collection_representer.rb@@ -32,7 +32,6 @@ module APImodule V3module Relationsclass RelationCollectionRepresenter < ::API::Decorators::UnpaginatedCollection- element_decorator ::API::V3::Relations::RelationRepresenterself.to_eager_load = ::API::V3::Relations::RelationRepresenter.to_eager_loadendenddiff --git a/lib/api/v3/repositories/revisions_collection_representer.rb b/lib/api/v3/repositories/revision_collection_representer.rbsimilarity index 89%rename from lib/api/v3/repositories/revisions_collection_representer.rbrename to lib/api/v3/repositories/revision_collection_representer.rbindex 8b3023f2a7b..e16aa2400af 100644--- a/lib/api/v3/repositories/revisions_collection_representer.rb+++ b/lib/api/v3/repositories/revision_collection_representer.rb@@ -31,8 +31,7 @@module APImodule V3module Repositories- class RevisionsCollectionRepresenter < ::API::Decorators::UnpaginatedCollection- element_decorator ::API::V3::Repositories::RevisionRepresenter+ class RevisionCollectionRepresenter < ::API::Decorators::UnpaginatedCollectionendendenddiff --git a/lib/api/v3/repositories/revisions_by_work_package_api.rb b/lib/api/v3/repositories/revisions_by_work_package_api.rbindex 4827af031ae..fb18c9f270a 100644--- a/lib/api/v3/repositories/revisions_by_work_package_api.rb+++ b/lib/api/v3/repositories/revisions_by_work_package_api.rb@@ -26,7 +26,7 @@# See docs/COPYRIGHT.rdoc for more details.#++-require 'api/v3/repositories/revisions_collection_representer'+require 'api/v3/repositories/revision_collection_representer'module APImodule V3@@ -41,7 +41,7 @@ module APIself_path = api_v3_paths.work_package_revisions(work_package.id)revisions = work_package.changesets.visible- RevisionsCollectionRepresenter.new(revisions, self_link: self_path, current_user: current_user)+ RevisionCollectionRepresenter.new(revisions, self_link: self_path, current_user: current_user)endendenddiff --git a/lib/api/v3/roles/role_collection_representer.rb b/lib/api/v3/roles/role_collection_representer.rbindex 96b61a064ca..164550fa772 100644--- a/lib/api/v3/roles/role_collection_representer.rb+++ b/lib/api/v3/roles/role_collection_representer.rb@@ -32,7 +32,6 @@ module APImodule V3module Rolesclass RoleCollectionRepresenter < ::API::Decorators::UnpaginatedCollection- element_decorator ::API::V3::Roles::RoleRepresenterendendenddiff --git a/lib/api/v3/root.rb b/lib/api/v3/root.rbindex b3929f76df3..b035f59bfb2 100644--- a/lib/api/v3/root.rb+++ b/lib/api/v3/root.rb@@ -64,6 +64,7 @@ module APImount ::API::V3::StringObjects::StringObjectsAPImount ::API::V3::Types::TypesAPImount ::API::V3::Users::UsersAPI+ mount ::API::V3::PlaceholderUsers::PlaceholderUsersAPImount ::API::V3::UserPreferences::UserPreferencesAPImount ::API::V3::Groups::GroupsAPImount ::API::V3::Versions::VersionsAPIdiff --git a/lib/api/v3/statuses/status_collection_representer.rb b/lib/api/v3/statuses/status_collection_representer.rbindex 9e176e3a972..eeaab07babe 100644--- a/lib/api/v3/statuses/status_collection_representer.rb+++ b/lib/api/v3/statuses/status_collection_representer.rb@@ -32,7 +32,6 @@ module APImodule V3module Statusesclass StatusCollectionRepresenter < ::API::Decorators::UnpaginatedCollection- element_decorator ::API::V3::Statuses::StatusRepresenterendendenddiff --git a/lib/api/v3/types/type_collection_representer.rb b/lib/api/v3/types/type_collection_representer.rbindex b2d88008c99..b27e82063a2 100644--- a/lib/api/v3/types/type_collection_representer.rb+++ b/lib/api/v3/types/type_collection_representer.rb@@ -32,7 +32,6 @@ module APImodule V3module Typesclass TypeCollectionRepresenter < ::API::Decorators::UnpaginatedCollection- element_decorator ::API::V3::Types::TypeRepresenterendendenddiff --git a/lib/api/v3/versions/version_collection_representer.rb b/lib/api/v3/versions/version_collection_representer.rbindex 1efd494331d..8a98f2964f2 100644--- a/lib/api/v3/versions/version_collection_representer.rb+++ b/lib/api/v3/versions/version_collection_representer.rb@@ -37,8 +37,6 @@ module APImodule V3module Versionsclass VersionCollectionRepresenter < ::API::Decorators::UnpaginatedCollection- element_decorator ::API::V3::Versions::VersionRepresenter-link :createVersionImmediately donext unless current_user.allowed_to_globally?(:manage_versions)diff --git a/lib/api/v3/work_packages/schema/work_package_schema_collection_representer.rb b/lib/api/v3/work_packages/schema/work_package_schema_collection_representer.rbindex 80a9513c957..a4740d8207a 100644--- a/lib/api/v3/work_packages/schema/work_package_schema_collection_representer.rb+++ b/lib/api/v3/work_packages/schema/work_package_schema_collection_representer.rb@@ -34,8 +34,6 @@ module APImodule Schemaclass WorkPackageSchemaCollectionRepresenter <::API::V3::Schemas::SchemaCollectionRepresenter- element_decorator ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter-privatedef model_self_link(model)diff --git a/lib/api/v3/work_packages/work_package_collection_representer.rb b/lib/api/v3/work_packages/work_package_collection_representer.rbindex 2062a1eaa06..42494714974 100644--- a/lib/api/v3/work_packages/work_package_collection_representer.rb+++ b/lib/api/v3/work_packages/work_package_collection_representer.rb@@ -32,8 +32,6 @@ module APImodule V3module WorkPackagesclass WorkPackageCollectionRepresenter < ::API::Decorators::OffsetPaginatedCollection- element_decorator ::API::V3::WorkPackages::WorkPackageRepresenter-def initialize(models,self_link:,groups:, total_sums:, current_user:, query: {},diff --git a/modules/budgets/lib/api/v3/budgets/budget_collection_representer.rb b/modules/budgets/lib/api/v3/budgets/budget_collection_representer.rbindex 698a25a2736..cb1f0d1de4e 100644--- a/modules/budgets/lib/api/v3/budgets/budget_collection_representer.rb+++ b/modules/budgets/lib/api/v3/budgets/budget_collection_representer.rb@@ -32,7 +32,6 @@ module APImodule V3module Budgetsclass BudgetCollectionRepresenter < ::API::Decorators::Collection- element_decorator ::API::V3::Budgets::BudgetRepresenterendendenddiff --git a/modules/costs/lib/api/v3/cost_entries/cost_entry_collection_representer.rb b/modules/costs/lib/api/v3/cost_entries/cost_entry_collection_representer.rbindex e34b618e278..963b73742af 100644--- a/modules/costs/lib/api/v3/cost_entries/cost_entry_collection_representer.rb+++ b/modules/costs/lib/api/v3/cost_entries/cost_entry_collection_representer.rb@@ -32,7 +32,6 @@ module APImodule V3module CostEntriesclass CostEntryCollectionRepresenter < ::API::Decorators::Collection- element_decorator ::API::V3::CostEntries::CostEntryRepresenterendendenddiff --git a/modules/costs/lib/api/v3/time_entries/time_entry_collection_representer.rb b/modules/costs/lib/api/v3/time_entries/time_entry_collection_representer.rbindex e1c8b190bc8..177555392a7 100644--- a/modules/costs/lib/api/v3/time_entries/time_entry_collection_representer.rb+++ b/modules/costs/lib/api/v3/time_entries/time_entry_collection_representer.rb@@ -32,8 +32,6 @@ module APImodule V3module TimeEntriesclass TimeEntryCollectionRepresenter < ::API::Decorators::OffsetPaginatedCollection- element_decorator ::API::V3::TimeEntries::TimeEntryRepresenter-link :createTimeEntry donext unless current_user.allowed_to_globally?(:log_time)diff --git a/modules/documents/lib/api/v3/documents/document_collection_representer.rb b/modules/documents/lib/api/v3/documents/document_collection_representer.rbindex a9389d3b20f..d57b0f70d56 100644--- a/modules/documents/lib/api/v3/documents/document_collection_representer.rb+++ b/modules/documents/lib/api/v3/documents/document_collection_representer.rb@@ -32,7 +32,6 @@ module APImodule V3module Documentsclass DocumentCollectionRepresenter < ::API::Decorators::OffsetPaginatedCollection- element_decorator ::API::V3::Documents::DocumentRepresenterendendenddiff --git a/modules/grids/app/representers/api/v3/grids/grid_collection_representer.rb b/modules/grids/app/representers/api/v3/grids/grid_collection_representer.rbindex bc35f0270b9..eca7866f73f 100644--- a/modules/grids/app/representers/api/v3/grids/grid_collection_representer.rb+++ b/modules/grids/app/representers/api/v3/grids/grid_collection_representer.rb@@ -34,8 +34,6 @@ module APIclass GridCollectionRepresenter < ::API::Decorators::OffsetPaginatedCollectionattr_reader :grid_scope, :grid_writable- element_decorator ::API::V3::Grids::GridRepresenter-def initialize(models, self_link:, grid_scope:, **args)super(models, self_link: self_link, **args)@grid_scope = grid_scopediff --git a/spec/lib/api/v3/placeholder_users/placeholder_user_collection_representer_spec.rb b/spec/lib/api/v3/placeholder_users/placeholder_user_collection_representer_spec.rbnew file mode 100644index 00000000000..e37c33f1e0f--- /dev/null+++ b/spec/lib/api/v3/placeholder_users/placeholder_user_collection_representer_spec.rb@@ -0,0 +1,69 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++require 'spec_helper'++describe ::API::V3::PlaceholderUsers::PlaceholderUserCollectionRepresenter do+ let(:self_base_link) { '/api/v3/placeholder_users' }+ let(:collection_inner_type) { 'PlaceholderUser' }+ let(:total) { 3 }+ let(:page) { 1 }+ let(:page_size) { 2 }+ let(:actual_count) { 3 }+ let(:current_user) { FactoryBot.build_stubbed :user }++ let(:placeholders) do+ placeholders = FactoryBot.build_stubbed_list(:placeholder_user,+ actual_count)+ allow(placeholders)+ .to receive(:per_page)+ .with(page_size)+ .and_return(placeholders)++ allow(placeholders)+ .to receive(:page)+ .with(page)+ .and_return(placeholders)++ placeholders+ end++ let(:representer) do+ described_class.new(placeholders,+ self_link: self_base_link,+ per_page: page_size,+ page: page,+ current_user: current_user)+ end++ context 'generation' do+ subject(:collection) { representer.to_json }++ it_behaves_like 'offset-paginated APIv3 collection'+ end+enddiff --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.rbindex dff089a752f..e9f52de98eb 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@@ -66,6 +66,47 @@ describe ::API::V3::PlaceholderUsers::PlaceholderUserRepresenter, 'rendering' doendend+ context 'showUser' do+ it_behaves_like 'has an untitled link' do+ let(:link) { 'showUser' }+ let(:href) { "/placeholder_users/#{placeholder_user.id}" }+ end+ end++ context 'delete' do+ it_behaves_like 'has no link' do+ let(:link) { 'delete' }+ end++ context 'when user allowed to manage' do+ let(:global_permissions) { [:manage_placeholder_user] }++ it_behaves_like 'has a titled link' do+ let(:link) { 'delete' }+ let(:href) { "/api/v3/placeholder_users/#{placeholder_user.id}" }+ let(:method) { :delete }+ let(:title) { "Delete #{placeholder_user.name}" }+ end+ end+ end++ context 'updateImmediately' do+ it_behaves_like 'has no link' do+ let(:link) { 'updateImmediately' }+ end++ context 'when user allowed to manage' do+ let(:global_permissions) { [:manage_placeholder_user] }++ it_behaves_like 'has a titled link' do+ let(:link) { 'updateImmediately' }+ let(:href) { "/api/v3/placeholder_users/#{placeholder_user.id}" }+ let(:method) { :patch }+ let(:title) { "Update #{placeholder_user.name}" }+ end+ end+ end+context 'memberships' doit_behaves_like 'has no link' dolet(:link) { 'memberships' }@@ -141,8 +182,8 @@ describe ::API::V3::PlaceholderUsers::PlaceholderUserRepresenter, 'rendering' doit 'is based on the representer\'s cache_key' doexpect(OpenProject::Cache).to receive(:fetch)- .with(representer.json_cache_key)- .and_call_original+ .with(representer.json_cache_key)+ .and_call_originalrepresenter.to_jsonenddiff --git a/spec/requests/api/v3/placeholder_users/create_resource_spec.rb b/spec/requests/api/v3/placeholder_users/create_resource_spec.rbnew file mode 100644index 00000000000..378854721ab--- /dev/null+++ b/spec/requests/api/v3/placeholder_users/create_resource_spec.rb@@ -0,0 +1,61 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.++require 'spec_helper'+require 'rack/test'+require_relative './create_shared_examples'++describe ::API::V3::PlaceholderUsers::PlaceholderUsersAPI,+ 'create',+ type: :request do++ current_user { user }++ describe 'admin user' do+ let(:user) { FactoryBot.build(:admin) }++ it_behaves_like 'create placeholder user request flow'+ end++ describe 'user with manage_placeholder_user permission' do+ let(:user) { FactoryBot.create(:user, global_permission: %i[manage_placeholder_user]) }++ it_behaves_like 'create placeholder user request flow'+ end++ describe 'unauthorized user' do+ include_context 'create placeholder user request context'+ let(:user) { FactoryBot.build(:user) }++ it 'returns an erroneous response' do+ send_request+ expect(last_response.status).to eq(403)+ end+ end+enddiff --git a/spec/requests/api/v3/placeholder_users/create_shared_examples.rb b/spec/requests/api/v3/placeholder_users/create_shared_examples.rbnew file mode 100644index 00000000000..a52b560528a--- /dev/null+++ b/spec/requests/api/v3/placeholder_users/create_shared_examples.rb@@ -0,0 +1,106 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.++shared_context 'create placeholder user request context' do+ include API::V3::Utilities::PathHelper++ let(:parameters) do+ { name: 'PLACEHOLDER' }+ end++ let(:send_request) do+ header "Content-Type", "application/json"+ post api_v3_paths.placeholder_users, parameters.to_json+ end++ let(:parsed_response) { JSON.parse(last_response.body) }+end++shared_examples 'create placeholder user request flow' do+ include_context 'create placeholder user request context'++ describe 'with EE', with_ee: %i[placeholder_users] do+ describe 'empty request body' do+ let(:parameters) { {} }++ it 'returns an erroneous response' do+ send_request++ expect(last_response.status).to eq(422)+ expect(last_response.body)+ .to be_json_eql('urn:openproject-org:api:v3:errors:PropertyConstraintViolation'.to_json)+ .at_path('errorIdentifier')++ expect(parsed_response['_embedded']['details']['attribute'])+ .to eq 'name'+ end+ end++ it 'creates the placeholder when valid' do+ send_request++ expect(last_response.status).to eq(201)+ placeholder = PlaceholderUser.find_by(name: parameters[:name])+ expect(placeholder).to be_present+ end++ describe 'when the user name already exists' do+ let!(:placeholder) { FactoryBot.create :placeholder_user, name: 'PLACEHOLDER' }++ it 'returns an error' do+ send_request++ expect(last_response.status).to eq(422)+ expect(last_response.body)+ .to be_json_eql('urn:openproject-org:api:v3:errors:PropertyConstraintViolation'.to_json)+ .at_path('errorIdentifier')++ expect(parsed_response['_embedded']['details']['attribute'])+ .to eq 'name'++ expect(parsed_response['message'])+ .to eq 'Name has already been taken.'+ end+ end+ end++ describe 'without ee' do+ it 'adds an error that its only available in EE' do+ send_request++ expect(last_response.status).to eq(422)+ expect(parsed_response['message'])+ .to eq('is only available in the OpenProject Enterprise Edition')++ expect(last_response.body)+ .to be_json_eql('urn:openproject-org:api:v3:errors:PropertyConstraintViolation'.to_json)+ .at_path('errorIdentifier')+ end+ end+enddiff --git a/spec/requests/api/v3/placeholder_users/delete_resource_examples.rb b/spec/requests/api/v3/placeholder_users/delete_resource_examples.rbnew file mode 100644index 00000000000..84c698d3454--- /dev/null+++ b/spec/requests/api/v3/placeholder_users/delete_resource_examples.rb@@ -0,0 +1,61 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.++shared_examples 'deletion allowed' do+ it 'should respond with 202' do+ expect(last_response.status).to eq 202+ end++ it 'should lock the account and mark for deletion' do+ expect(Principals::DeleteJob)+ .to have_been_enqueued+ .with(placeholder)++ expect(placeholder.reload).to be_locked+ end++ context 'with a non-existent user' do+ let(:path) { api_v3_paths.placeholder_user 1337 }++ it_behaves_like 'not found' do+ let(:id) { 1337 }+ let(:type) { 'PlaceholderUser' }+ end+ end+end++shared_examples 'deletion is not allowed' do+ it 'should respond with 403' do+ expect(last_response.status).to eq 403+ end++ it 'should not delete the user' do+ expect(PlaceholderUser.exists?(placeholder.id)).to be_truthy+ end+enddiff --git a/spec/requests/api/v3/placeholder_users/delete_resource_spec.rb b/spec/requests/api/v3/placeholder_users/delete_resource_spec.rbnew file mode 100644index 00000000000..4ba7a6c2108--- /dev/null+++ b/spec/requests/api/v3/placeholder_users/delete_resource_spec.rb@@ -0,0 +1,83 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.++require 'spec_helper'+require_relative './delete_resource_examples'++describe ::API::V3::PlaceholderUsers::PlaceholderUsersAPI,+ 'delete',+ type: :request do+ include API::V3::Utilities::PathHelper++ shared_let(:placeholder) { FactoryBot.create :placeholder_user, name: 'foo' }++ let(:send_request) do+ header "Content-Type", "application/json"+ end++ let(:path) { api_v3_paths.placeholder_user(placeholder.id) }+ let(:parsed_response) { JSON.parse(last_response.body) }++ current_user { user }++ before do+ header "Content-Type", "application/json"+ delete path+ end++ context 'when admin' do+ let(:user) { FactoryBot.build_stubbed :admin }++ it_behaves_like 'deletion allowed'+ end++ context 'when locked admin' do+ let(:user) { FactoryBot.build_stubbed :admin, status: Principal.statuses[:locked] }++ it_behaves_like 'deletion is not allowed'+ end++ context 'when non-admin' do+ let(:user) { FactoryBot.build_stubbed :user, admin: false }++ it_behaves_like 'deletion is not allowed'+ end++ context 'when user with manage_user permission' do+ let(:user) { FactoryBot.create :user, global_permission: %[manage_placeholder_user] }++ it_behaves_like 'deletion allowed'+ end++ context 'when anonymous user' do+ let(:user) { FactoryBot.create :anonymous }++ it_behaves_like 'deletion is not allowed'+ end+enddiff --git a/spec/requests/api/v3/placeholder_users/index_resource_spec.rb b/spec/requests/api/v3/placeholder_users/index_resource_spec.rbnew file mode 100644index 00000000000..39292f4ceca--- /dev/null+++ b/spec/requests/api/v3/placeholder_users/index_resource_spec.rb@@ -0,0 +1,74 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.++require 'spec_helper'+require 'rack/test'++describe ::API::V3::PlaceholderUsers::PlaceholderUsersAPI,+ 'index',+ type: :request do++ include API::V3::Utilities::PathHelper++ shared_let(:placeholder1) { FactoryBot.create :placeholder_user, name: 'foo' }+ shared_let(:placeholder2) { FactoryBot.create :placeholder_user, name: 'bar' }++ let(:send_request) do+ header "Content-Type", "application/json"+ get api_v3_paths.placeholder_users+ end++ let(:parsed_response) { JSON.parse(last_response.body) }++ current_user { user }++ before do+ send_request+ end++ describe 'admin user' do+ let(:user) { FactoryBot.build(:admin) }++ it_behaves_like 'API V3 collection response', 2, 2, 'PlaceholderUser'+ end++ describe 'user with manage_placeholder_user permission' do+ let(:user) { FactoryBot.create(:user, global_permission: %i[manage_placeholder_user]) }++ it_behaves_like 'API V3 collection response', 2, 2, 'PlaceholderUser'+ end++ describe 'unauthorized user' do+ let(:user) { FactoryBot.build(:user) }++ it 'returns an erroneous response' do+ expect(last_response.status).to eq(403)+ end+ end+enddiff --git a/spec/requests/api/v3/placeholder_users/show_resource_examples.rb b/spec/requests/api/v3/placeholder_users/show_resource_examples.rbnew file mode 100644index 00000000000..59befe23be0--- /dev/null+++ b/spec/requests/api/v3/placeholder_users/show_resource_examples.rb@@ -0,0 +1,42 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.++shared_examples 'represents the placeholder' do+ it do+ expect(last_response.status).to eq(200)+ expect(last_response.body)+ .to(be_json_eql('PlaceholderUser'.to_json).at_path('_type'))++ expect(last_response.body)+ .to(be_json_eql(placeholder.name.to_json).at_path('name'))++ expect(last_response.body)+ .to(be_json_eql(placeholder.id.to_json).at_path('id'))+ end+enddiff --git a/spec/requests/api/v3/placeholder_users/show_resource_spec.rb b/spec/requests/api/v3/placeholder_users/show_resource_spec.rbnew file mode 100644index 00000000000..1dc552880be--- /dev/null+++ b/spec/requests/api/v3/placeholder_users/show_resource_spec.rb@@ -0,0 +1,72 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.++require 'spec_helper'+require_relative './show_resource_examples'++describe ::API::V3::PlaceholderUsers::PlaceholderUsersAPI,+ 'show',+ type: :request do+ include API::V3::Utilities::PathHelper++ shared_let(:placeholder) { FactoryBot.create :placeholder_user, name: 'foo' }++ let(:send_request) do+ header "Content-Type", "application/json"+ get api_v3_paths.placeholder_user(placeholder.id)+ end++ let(:parsed_response) { JSON.parse(last_response.body) }++ current_user { user }++ before do+ send_request+ end++ describe 'admin user' do+ let(:user) { FactoryBot.build(:admin) }++ it_behaves_like 'represents the placeholder'+ end++ describe 'user with manage_placeholder_user permission' do+ let(:user) { FactoryBot.create(:user, global_permission: %i[manage_placeholder_user]) }++ it_behaves_like 'represents the placeholder'+ end++ describe 'unauthorized user' do+ let(:user) { FactoryBot.build(:user) }++ it 'returns an erroneous response' do+ expect(last_response.status).to eq(403)+ end+ end+enddiff --git a/spec/requests/api/v3/placeholder_users/update_resource_examples.rb b/spec/requests/api/v3/placeholder_users/update_resource_examples.rbnew file mode 100644index 00000000000..2e2561804c3--- /dev/null+++ b/spec/requests/api/v3/placeholder_users/update_resource_examples.rb@@ -0,0 +1,63 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.++shared_examples 'updates the placeholder' do+ context 'with an empty name' do+ let(:parameters) do+ { name: '' }+ end++ it 'returns an error' do+ expect(last_response.status).to eq(422)+ expect(last_response.body)+ .to be_json_eql('urn:openproject-org:api:v3:errors:PropertyConstraintViolation'.to_json)+ .at_path('errorIdentifier')++ expect(parsed_response['_embedded']['details']['attribute'])+ .to eq 'name'++ expect(parsed_response['message'])+ .to eq "Name can't be blank."+ end+ end++ context 'with a new name' do+ let(:parameters) do+ { name: 'my new name' }+ end++ it 'updates the placeholder' do+ expect(last_response.status).to eq(200)++ placeholder.reload++ expect(placeholder.name).to eq 'my new name'+ end+ end+enddiff --git a/spec/requests/api/v3/placeholder_users/update_resource_spec.rb b/spec/requests/api/v3/placeholder_users/update_resource_spec.rbnew file mode 100644index 00000000000..55586a6a2fb--- /dev/null+++ b/spec/requests/api/v3/placeholder_users/update_resource_spec.rb@@ -0,0 +1,76 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.++require 'spec_helper'+require_relative './update_resource_examples'++describe ::API::V3::PlaceholderUsers::PlaceholderUsersAPI,+ 'update',+ type: :request do+ include API::V3::Utilities::PathHelper++ shared_let(:placeholder) { FactoryBot.create :placeholder_user, name: 'foo' }++ let(:parameters) do+ {}+ end++ let(:send_request) do+ header "Content-Type", "application/json"+ patch api_v3_paths.placeholder_user(placeholder.id), parameters.to_json+ end++ let(:parsed_response) { JSON.parse(last_response.body) }++ current_user { user }++ before do+ send_request+ end++ describe 'admin user' do+ let(:user) { FactoryBot.build(:admin) }++ it_behaves_like 'updates the placeholder'+ end++ describe 'user with manage_placeholder_user permission' do+ let(:user) { FactoryBot.create(:user, global_permission: %i[manage_placeholder_user]) }++ it_behaves_like 'updates the placeholder'+ end++ describe 'unauthorized user' do+ let(:user) { FactoryBot.build(:user) }++ it 'returns an erroneous response' do+ expect(last_response.status).to eq(403)+ end+ end+end