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
Allow deletion of placeholder users when permission of :manage_placeholder_user give (#9018)
Wieland Lindenthalffa5ac84a89b
diff --git a/app/cells/placeholder_users/placeholder_user_filter_cell.rb b/app/cells/placeholder_users/placeholder_user_filter_cell.rbindex c1b5514f157..dfe99fa0bed 100644--- a/app/cells/placeholder_users/placeholder_user_filter_cell.rb+++ b/app/cells/placeholder_users/placeholder_user_filter_cell.rb@@ -36,6 +36,14 @@ module PlaceholderUsersdef base_queryQueries::PlaceholderUsers::PlaceholderUserQueryend++ def apply_filters(params, query)+ super++ # Filter for active placeholders+ # to skip to-be-deleted users+ query.where(:status, '=', :active)+ endend# INSTANCE METHODS:diff --git a/app/cells/placeholder_users/row_cell.rb b/app/cells/placeholder_users/row_cell.rbindex aec8386bd76..24960d38b04 100644--- a/app/cells/placeholder_users/row_cell.rb+++ b/app/cells/placeholder_users/row_cell.rb@@ -46,13 +46,11 @@ module PlaceholderUsersenddef delete_link- return nil unless User.current.admin?+ return nil unless PlaceholderUsers::DeleteContract.deletion_allowed?(User.current)link_to '',- placeholder_user_path(placeholder_user),- data: { confirm: I18n.t(:text_are_you_sure) },- class: 'icon icon-delete',- method: :delete+ deletion_info_placeholder_user_path(placeholder_user),+ class: 'icon icon-delete'endendenddiff --git a/app/contracts/placeholder_users/base_contract.rb b/app/contracts/placeholder_users/base_contract.rbindex 4b64fb6e031..ba528ffb2dc 100644--- a/app/contracts/placeholder_users/base_contract.rb+++ b/app/contracts/placeholder_users/base_contract.rb@@ -53,7 +53,7 @@ module PlaceholderUsersenddef user_allowed_to_add?- user.allowed_to_globally?(:add_placeholder_user)+ user.allowed_to_globally?(:manage_placeholder_user)endendenddiff --git a/app/contracts/placeholder_users/delete_contract.rb b/app/contracts/placeholder_users/delete_contract.rbindex c39310922f5..f8cd946a303 100644--- a/app/contracts/placeholder_users/delete_contract.rb+++ b/app/contracts/placeholder_users/delete_contract.rb@@ -39,19 +39,11 @@ module PlaceholderUsers## @param actor [User] User who wants to delete the given placeholder user.def self.deletion_allowed?(actor)- actor.admin? && actor.active?+ actor.allowed_to_globally?(:manage_placeholder_user)endprotected- ##- # PlaceholderUsers can only be deleted by Admins- def user_allowed_to_modify- unless deletion_allowed?- errors.add :base, :error_unauthorized- end- end-def deletion_allowed?self.class.deletion_allowed? userenddiff --git a/app/contracts/users/base_contract.rb b/app/contracts/users/base_contract.rbindex 2776c80a709..8733bdabcf8 100644--- a/app/contracts/users/base_contract.rb+++ b/app/contracts/users/base_contract.rb@@ -40,7 +40,7 @@ module Usersattribute :languageattribute :auth_source_id,- writeable: ->(*) { user.allowed_to_globally?(:add_user) }+ writeable: ->(*) { user.allowed_to_globally?(:manage_user) }attribute :identity_url,writeable: ->(*) { user.admin? }diff --git a/app/contracts/users/create_contract.rb b/app/contracts/users/create_contract.rbindex 79ccac20d5b..f4bcb80a6a3 100644--- a/app/contracts/users/create_contract.rb+++ b/app/contracts/users/create_contract.rb@@ -56,7 +56,7 @@ module Users### Users can only be created by Adminsdef user_allowed_to_add- unless user.admin? || user.allowed_to_globally?(:add_user)+ unless user.allowed_to_globally?(:manage_user)errors.add :base, :error_unauthorizedendenddiff --git a/app/contracts/users/update_contract.rb b/app/contracts/users/update_contract.rbindex 1ec0b8a74af..46ae2273049 100644--- a/app/contracts/users/update_contract.rb+++ b/app/contracts/users/update_contract.rb@@ -37,10 +37,10 @@ module Users### Users can only be updated when# - the user is editing herself- # - the user has the global add_user CRU permission+ # - the user has the global manage_user CRU permission# - the user is an admindef user_allowed_to_update- unless user == model || user.admin? || user.allowed_to_globally?(:add_user)+ unless user == model || user.allowed_to_globally?(:manage_user)errors.add :base, :error_unauthorizedendenddiff --git a/app/controllers/placeholder_users_controller.rb b/app/controllers/placeholder_users_controller.rbindex b79c23ae07b..7643f7d26b0 100644--- a/app/controllers/placeholder_users_controller.rb+++ b/app/controllers/placeholder_users_controller.rb@@ -38,8 +38,8 @@ class PlaceholderUsersController < ApplicationControllerbefore_action :find_placeholder_user, only: %i[showeditupdate+ deletion_infodestroy]- before_action :check_if_deletion_allowed, only: [:destroy]def index@placeholder_users = PlaceholderUsers::PlaceholderUserFilterCell.filter params@@ -121,6 +121,10 @@ class PlaceholderUsersController < ApplicationControllerendend+ def deletion_info+ respond_to :html+ end+def destroyPlaceholderUsers::DeleteService.new(user: User.current, model: @placeholder_user)@@ -143,10 +147,6 @@ class PlaceholderUsersController < ApplicationControllerrender_404end- def check_if_deletion_allowed- render_404 unless PlaceholderUsers::DeleteContract.deletion_allowed?(current_user)- end-protecteddef default_breadcrumbdiff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rbindex da9d7addc20..061420b9621 100644--- a/app/controllers/users_controller.rb+++ b/app/controllers/users_controller.rb@@ -82,7 +82,7 @@ class UsersController < ApplicationControllerevents = Activities::Fetcher.new(User.current, author: @user).events(nil, nil, limit: 10)@events_by_day = events.group_by { |e| e.event_datetime.to_date }- if !current_user.allowed_to_globally?(:add_user) &&+ if !current_user.allowed_to_globally?(:manage_user) &&(!(@user.active? ||@user.registered?) ||(@user != User.current && @memberships.empty? && events.empty?))diff --git a/app/models/queries/placeholder_users.rb b/app/models/queries/placeholder_users.rbindex 1a083c301ac..0d8922daef1 100644--- a/app/models/queries/placeholder_users.rb+++ b/app/models/queries/placeholder_users.rb@@ -38,6 +38,9 @@ module Queries::PlaceholderUsersQueries::Register.filter Queries::PlaceholderUsers::PlaceholderUserQuery,Queries::PlaceholderUsers::Filters::GroupFilter+ Queries::Register.filter Queries::PlaceholderUsers::PlaceholderUserQuery,+ Queries::PlaceholderUsers::Filters::StatusFilter+Queries::Register.order Queries::PlaceholderUsers::PlaceholderUserQuery,Queries::PlaceholderUsers::Orders::DefaultOrderdiff --git a/app/models/queries/placeholder_users/filters/status_filter.rb b/app/models/queries/placeholder_users/filters/status_filter.rbnew file mode 100644index 00000000000..60672e10599--- /dev/null+++ b/app/models/queries/placeholder_users/filters/status_filter.rb@@ -0,0 +1,33 @@+#-- 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.+#++++class Queries::PlaceholderUsers::Filters::StatusFilter < Queries::PlaceholderUsers::Filters::PlaceholderUserFilter+ include Queries::Filters::Shared::UserStatusFilter+enddiff --git a/app/services/placeholder_users/delete_service.rb b/app/services/placeholder_users/delete_service.rbindex a4b83b9080c..c31d350c7cd 100644--- a/app/services/placeholder_users/delete_service.rb+++ b/app/services/placeholder_users/delete_service.rb@@ -30,6 +30,7 @@class PlaceholderUsers::DeleteService < ::BaseServices::Deletedef destroy(placeholder)+ placeholder.locked!::Principals::DeleteJob.perform_later(placeholder)truediff --git a/app/views/placeholder_users/_toolbar.html.erb b/app/views/placeholder_users/_toolbar.html.erbindex ac430856157..02a004aa18b 100644--- a/app/views/placeholder_users/_toolbar.html.erb+++ b/app/views/placeholder_users/_toolbar.html.erb@@ -34,5 +34,12 @@ See docs/COPYRIGHT.rdoc for more details.<span class="button--text"><%= t(:label_profile) %></span><% end %></li>+ <li class="toolbar-item">+ <%= link_to deletion_info_placeholder_user_path(@placeholder_user),+ class: 'button' do %>+ <%= op_icon('button--icon icon-delete') %>+ <span class="button--text"><%= t(:button_delete) %></span>+ <% end %>+ </li><% end %><% end %>diff --git a/app/views/placeholder_users/deletion_info.html.erb b/app/views/placeholder_users/deletion_info.html.erbnew file mode 100644index 00000000000..a7c96d71f7d--- /dev/null+++ b/app/views/placeholder_users/deletion_info.html.erb@@ -0,0 +1,68 @@+<%#-- 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.++++#%>+<% name = @placeholder_user.name %>+<% html_title(t(:label_administration), "#{ t('placeholder_users.deletion_info.heading', name: name)}") -%>++<%= labelled_tabular_form_for(+ :placeholder_user,+ url: placeholder_user_path(@placeholder_user),+ html: {+ method: :delete,+ class: 'form danger-zone',+ }) do %>+ <div class='wiki'>+ <section class="form--section">+ <h3 class="form--section-title">+ <%= t('placeholder_users.deletion_info.heading',+ name: content_tag(:em, name))+ .html_safe %>+ </h3>++ <p>+ <%= simple_format t("placeholder_users.deletion_info.data_consequences") %>+ </p>+ <p class="danger-zone--warning">+ <span class="icon icon-error"></span>+ <span><%= t("placeholder_users.deletion_info.irreversible") %></span>+ </p>+ <p>+ <%= t("placeholder_users.deletion_info.confirmation",+ name: content_tag(:em, name, class: "danger-zone--expected-value")+ ).html_safe %>+ </p>+ <div class="danger-zone--verification">+ <input type="text" name="name_verification"/>+ <%= styled_button_tag '', class: '-highlight', disabled: true do+ concat content_tag :i, '', class: 'button--icon icon-delete'+ concat content_tag :span, t(:button_delete), class: 'button--text'+ end %>+ </div>+ </section>+ </div>+<% end %>diff --git a/app/views/placeholder_users/show.html.erb b/app/views/placeholder_users/show.html.erbindex a95b45fcb50..93a1207cb8a 100644--- a/app/views/placeholder_users/show.html.erb+++ b/app/views/placeholder_users/show.html.erb@@ -32,13 +32,20 @@ See docs/COPYRIGHT.rdoc for more details.<% end %><% html_title t(:label_administration), t(:label_placeholder_user_plural) -%><%= toolbar title: "#{avatar @placeholder_user} #{h(@placeholder_user.name)}".html_safe do %>- <% if User.current.admin? %>+ <% if current_user.allowed_to_globally?(:manage_placeholder_user) %><li class="toolbar-item"><%= link_to edit_placeholder_user_path(@placeholder_user), class: 'button', accesskey: accesskey(:edit) do %><%= op_icon('button--icon icon-edit') %><span class="button--text"><%= t(:button_edit) %></span><% end %></li>+ <li class="toolbar-item">+ <%= link_to deletion_info_placeholder_user_path(@placeholder_user),+ class: 'button' do %>+ <%= op_icon('button--icon icon-delete') %>+ <span class="button--text"><%= t(:button_delete) %></span>+ <% end %>+ </li><% end %><% end %>diff --git a/app/views/users/_toolbar.html.erb b/app/views/users/_toolbar.html.erbindex d1ca9de59eb..80b5a728d8c 100644--- a/app/views/users/_toolbar.html.erb+++ b/app/views/users/_toolbar.html.erb@@ -33,7 +33,7 @@ See docs/COPYRIGHT.rdoc for more details.<span class="button--text"><%= t(:label_profile) %></span><% end %></li>- <% if current_user.allowed_to_globally?(:add_user) %>+ <% if current_user.allowed_to_globally?(:manage_user) %><li class="toolbar-item hidden-for-mobile"><%= form_for(@user, html: { class: 'toolbar-item' },url: { action: :resend_invitation },diff --git a/config/initializers/menus.rb b/config/initializers/menus.rbindex 2ef71402106..90df898f3d0 100644--- a/config/initializers/menus.rb+++ b/config/initializers/menus.rb@@ -76,7 +76,7 @@ Redmine::MenuManager.map :account_menu do |menu|if: Proc.new { User.current.logged? }menu.push :administration,{ controller: '/admin', action: 'index' },- if: Proc.new { User.current.allowed_to_globally?(:add_placeholder_user) || User.current.allowed_to_globally?(:add_user) }+ if: Proc.new { User.current.allowed_to_globally?(:manage_placeholder_user) || User.current.allowed_to_globally?(:manage_user) }menu.push :logout,:signout_path,if: Proc.new { User.current.logged? }@@ -132,13 +132,13 @@ Redmine::MenuManager.map :admin_menu do |menu|menu.push :users,{ controller: '/users' },- if: Proc.new { !User.current.admin? && User.current.allowed_to_globally?(:add_user) },+ if: Proc.new { !User.current.admin? && User.current.allowed_to_globally?(:manage_user) },caption: :label_user_plural,icon: 'icon2 icon-group'menu.push :placeholder_users,{ controller: '/placeholder_users' },- if: Proc.new { !User.current.admin? && User.current.allowed_to_globally?(:add_placeholder_user) },+ if: Proc.new { !User.current.admin? && User.current.allowed_to_globally?(:manage_placeholder_user) },caption: :label_placeholder_user_plural,icon: 'icon2 icon-group'diff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rbindex 1d6bb1b9423..cbdfbbde1e0 100644--- a/config/initializers/permissions.rb+++ b/config/initializers/permissions.rb@@ -49,7 +49,7 @@ OpenProject::AccessControl.map do |map|require: :loggedin,global: true- map.permission :add_user,+ map.permission :manage_user,{users: %i[index show new create edit update resend_invitation],"users/memberships": %i[create update destroy],@@ -58,18 +58,9 @@ OpenProject::AccessControl.map do |map|require: :loggedin,global: true- map.permission :add_placeholder_user,+ map.permission :manage_placeholder_user,{- placeholder_users: %i[index show new create edit update],- "placeholder_users/memberships": %i[create update destroy],- admin: %i[index]- },- require: :loggedin,- global: true-- map.permission :add_placeholder_user,- {- placeholder_users: %i[index show new create edit update],+ placeholder_users: %i[index show new create edit update deletion_info destroy],"placeholder_users/memberships": %i[create update destroy],admin: %i[index]},diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 39103a23dc8..765c2909ebe 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1982,8 +1982,8 @@ en:permission_add_work_packages: "Add work packages"permission_add_messages: "Post messages"permission_add_project: "Create project"- permission_add_user: "Create and edit users"- permission_add_placeholder_user: "Create and edit placeholder users"+ permission_manage_user: "Create and edit users"+ permission_manage_placeholder_user: "Create, edit and delete placeholder users"permission_add_subprojects: "Create subprojects"permission_add_work_package_watchers: "Add watchers"permission_assign_versions: "Assign versions"@@ -2049,6 +2049,21 @@ en:placeholders:default: "-"+ placeholder_users:+ deletion_info:+ heading: "Delete placeholder user %{name}"+ data_consequences: >+ All occurrences of the placeholder user (e.g., as assignee, responsible or other user values)+ will be reassigned to an account called "Deleted user".++ As the data of every deleted account is reassigned to this account+ it will not be possible to distinguish the data the user created from+ the data of another deleted account.+ irreversible: "This action is irreversible"+ confirmation: "Enter the placeholder name %{name} to confirm the deletion."+++project:destroy:confirmation: "If you continue, the project %{identifier} and all related data will be permanently destroyed."diff --git a/config/routes.rb b/config/routes.rbindex e6fc18e5efb..0d3e7caea5b 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -469,6 +469,7 @@ OpenProject::Application.routes.draw domember doget '/edit(/:tab)' => 'placeholder_users#edit', as: 'edit'+ get :deletion_infoendenddiff --git a/docs/api/apiv3/endpoints/users.apib b/docs/api/apiv3/endpoints/users.apibindex 6cd182a01ef..32c31ff1fba 100644--- a/docs/api/apiv3/endpoints/users.apib+++ b/docs/api/apiv3/endpoints/users.apib@@ -6,7 +6,7 @@| lock | Restrict the user from logging in and performing any actions | not locked; **Permission**: Administrator || show | Link to the OpenProject user page (HTML) | || unlock | Allow a locked user to login and act again | locked; **Permission**: Administrator |-| updateImmediately | Updates the user's attributes. | **Permission**: Administrator, add_users global permission |+| updateImmediately | Updates the user's attributes. | **Permission**: Administrator, manage_users global permission || delete | Permanently remove a user from the instance | **Permission**: Administrator, self-delete |## Linked Properties@@ -20,15 +20,15 @@| Property | Description | Type | Constraints | Supported operations | Condition || :----------: | --------------------------------------------------------- | -------- | ---------------------------------------------------- | -------------------- | ----------------------------------------------------------- || id | User's id | Integer | x > 0 | READ | |-| login | User's login name | String | unique, 256 max length | READ / WRITE | **Permission**: Administrator, add_users global permission |-| firstName | User's first name | String | 30 max length | READ / WRITE | **Permission**: Administrator, add_users global permission |-| lastName | User's last name | String | 30 max length | READ / WRITE | **Permission**: Administrator, add_users global permission |+| login | User's login name | String | unique, 256 max length | READ / WRITE | **Permission**: Administrator, manage_users global permission |+| firstName | User's first name | String | 30 max length | READ / WRITE | **Permission**: Administrator, manage_users global permission |+| lastName | User's last name | String | 30 max length | READ / WRITE | **Permission**: Administrator, manage_users global permission || name | User's full name, formatting depends on instance settings | String | | READ | |-| email | User's email address | String | unique, 60 max length | READ / WRITE | E-Mail address not hidden, **Permission**: Administrator, add_users global permission |+| email | User's email address | String | unique, 60 max length | READ / WRITE | E-Mail address not hidden, **Permission**: Administrator, manage_users global permission || admin | Flag indicating whether or not the user is an admin | Boolean | in: [true, false] | READ / WRITE | **Permission**: Administrator || avatar | URL to user's avatar | Url | | READ | || status | The current activation status of the user (see below) | String | in: ["active", "registered", "locked", "invited"] | READ | |-| language | User's language | String | ISO 639-1 | READ / WRITE | **Permission**: Administrator, add_users global permission |+| language | User's language | String | ISO 639-1 | READ / WRITE | **Permission**: Administrator, manage_users global permission || password | User's password for the default password authentication | String | | WRITE | **Permission**: Administrator || identity_url | User's identity_url for OmniAuth authentication | String | | READ / WRITE | **Permission**: Administrator || createdAt | Time of creation | DateTime | | READ | |@@ -162,7 +162,7 @@ When calling this endpoint the client provides a single object, containing at leReturned if the client does not have sufficient permissions.- **Required permission:** Administrators, add_users global permission+ **Required permission:** Administrators, manage_users global permission+ Body@@ -409,7 +409,7 @@ Permanently deletes the specified user account.## List Users [GET]-Lists users. Only administrators or users with add_users global permission have permission to do this.+Lists users. Only administrators or users with manage_users global permission have permission to do this.+ Parameters+ offset = `1` (optional, integer, `25`) ... Page number inside the requested collection.@@ -459,7 +459,7 @@ Lists users. Only administrators or users with add_users global permission have## Create User [POST]-Creates a new user. Only administrators and users with add_users global permission are allowed to do so.+Creates a new user. Only administrators and users with manage_users 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.Valid values for `status`:diff --git a/lib/api/v3/users/users_api.rb b/lib/api/v3/users/users_api.rbindex 268c8c8ec83..342789fffbb 100644--- a/lib/api/v3/users/users_api.rb+++ b/lib/api/v3/users/users_api.rb@@ -49,7 +49,7 @@ module APIenddef authorize_user_cru_allowed- authorize_by_with_raise(current_user.allowed_to_globally?(:add_user))+ authorize_by_with_raise(current_user.allowed_to_globally?(:manage_user))endenddiff --git a/spec/contracts/placeholder_users/create_contract_spec.rb b/spec/contracts/placeholder_users/create_contract_spec.rbindex 843830f16a6..d48992c56b8 100644--- a/spec/contracts/placeholder_users/create_contract_spec.rb+++ b/spec/contracts/placeholder_users/create_contract_spec.rb@@ -39,7 +39,7 @@ describe PlaceholderUsers::CreateContract dolet(:contract) { described_class.new(placeholder_user, current_user) }context 'when user with global permission' do- let(:current_user) { FactoryBot.create(:user, global_permission: %i[add_placeholder_user]) }+ let(:current_user) { FactoryBot.create(:user, global_permission: %i[manage_placeholder_user]) }it_behaves_like 'contract is invalid', base: :error_enterprise_onlyenddiff --git a/spec/contracts/placeholder_users/delete_contract_spec.rb b/spec/contracts/placeholder_users/delete_contract_spec.rbindex 3c785359c6c..18e5267d7ed 100644--- a/spec/contracts/placeholder_users/delete_contract_spec.rb+++ b/spec/contracts/placeholder_users/delete_contract_spec.rb@@ -38,4 +38,10 @@ describe PlaceholderUsers::DeleteContract dolet(:contract) { described_class.new(placeholder_user, current_user) }it_behaves_like 'contract is valid for active admins and invalid for regular users'++ context 'when user with global permission' do+ let(:current_user) { FactoryBot.create(:user, global_permission: %i[manage_placeholder_user]) }++ it_behaves_like 'contract is valid'+ endenddiff --git a/spec/contracts/placeholder_users/shared_contract_examples.rb b/spec/contracts/placeholder_users/shared_contract_examples.rbindex dfe9ac00d7c..ff90c11e8d5 100644--- a/spec/contracts/placeholder_users/shared_contract_examples.rb+++ b/spec/contracts/placeholder_users/shared_contract_examples.rb@@ -34,7 +34,7 @@ shared_examples_for 'placeholder user contract' dolet(:placeholder_user_name) { 'UX Designer' }context 'when user with global permission' do- let(:current_user) { FactoryBot.create(:user, global_permission: %i[add_placeholder_user]) }+ let(:current_user) { FactoryBot.create(:user, global_permission: %i[manage_placeholder_user]) }it_behaves_like 'contract is valid'enddiff --git a/spec/contracts/users/create_contract_spec.rb b/spec/contracts/users/create_contract_spec.rbindex c27c95a8eab..e330ba70c35 100644--- a/spec/contracts/users/create_contract_spec.rb+++ b/spec/contracts/users/create_contract_spec.rb@@ -61,7 +61,7 @@ describe Users::CreateContract doendcontext 'when global user' do- shared_let(:current_user) { FactoryBot.create :user, global_permission: :add_user }+ shared_let(:current_user) { FactoryBot.create :user, global_permission: :manage_user }describe 'can invite user' dobefore dodiff --git a/spec/controllers/placeholder_users/memberships_controller_spec.rb b/spec/controllers/placeholder_users/memberships_controller_spec.rbindex 789bb84b7e3..deb01079c9f 100644--- a/spec/controllers/placeholder_users/memberships_controller_spec.rb+++ b/spec/controllers/placeholder_users/memberships_controller_spec.rb@@ -104,7 +104,7 @@ describe PlaceholderUsers::MembershipsController, type: :controller doendcontext 'as user with global permission' do- current_user { FactoryBot.create :user, global_permission: %i[add_placeholder_user] }+ current_user { FactoryBot.create :user, global_permission: %i[manage_placeholder_user] }it_behaves_like 'update memberships flow'enddiff --git a/spec/controllers/placeholder_users_controller_spec.rb b/spec/controllers/placeholder_users_controller_spec.rbindex e35181919c2..9a0ddb58463 100644--- a/spec/controllers/placeholder_users_controller_spec.rb+++ b/spec/controllers/placeholder_users_controller_spec.rb@@ -215,12 +215,29 @@ describe PlaceholderUsersController, type: :controller doendend+ describe 'GET deletion_info' do+ before do+ get :deletion_info, params: { id: placeholder_user.id }+ end++ it 'should render the deletion info response' do+ expect(response).to be_successful+ expect(response).to render_template 'placeholder_users/deletion_info'+ end+ end+describe 'POST destroy' dobefore dodelete :destroy, params: { id: placeholder_user.id }end- pending 'not yet implemented'+ it 'should trigger the deletion' do+ expect(response).to redirect_to action: :index+ expect(flash[:info]).to include I18n.t(:notice_deletion_scheduled)++ expect(Principals::DeleteJob)+ .to(have_been_enqueued.with(placeholder_user))+ endendend@@ -231,8 +248,7 @@ describe PlaceholderUsersController, type: :controller doendcontext 'as a user with global permission' do- current_user { FactoryBot.create :user, global_permission: %i[add_placeholder_user] }-+ current_user { FactoryBot.create :user, global_permission: %i[manage_placeholder_user] }it_behaves_like 'authorized flows'end@@ -300,6 +316,14 @@ describe PlaceholderUsersController, type: :controller doit_behaves_like 'do not allow non-admins'end+ describe 'GET deletion_info' do+ before do+ get :deletion_info, params: { id: placeholder_user.id }+ end++ it_behaves_like 'do not allow non-admins'+ end+describe 'POST destroy' dobefore dodelete :destroy, params: { id: placeholder_user.id }diff --git a/spec/features/placeholder_users/create_spec.rb b/spec/features/placeholder_users/create_spec.rbindex 965297aed9a..81159feafb3 100644--- a/spec/features/placeholder_users/create_spec.rb+++ b/spec/features/placeholder_users/create_spec.rb@@ -69,7 +69,7 @@ describe 'create placeholder users', type: :feature, selenium: true doendcontext 'as user with global permission' do- current_user { FactoryBot.create :user, global_permission: %i[add_placeholder_user] }+ current_user { FactoryBot.create :user, global_permission: %i[manage_placeholder_user] }it_behaves_like 'placeholders creation flow'enddiff --git a/spec/features/placeholder_users/delete_spec.rb b/spec/features/placeholder_users/delete_spec.rbnew file mode 100644index 00000000000..048ea75d7ad--- /dev/null+++ b/spec/features/placeholder_users/delete_spec.rb@@ -0,0 +1,83 @@+#-- 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 'delete placeholder user', type: :feature, js: true do+ shared_let(:placeholder_user) { FactoryBot.create :placeholder_user, name: 'UX Developer' }++ shared_examples 'placeholders delete flow' do+ it 'can delete name' do+ visit placeholder_user_path(placeholder_user)++ expect(page).to have_selector '.button', text: 'Delete'++ visit edit_placeholder_user_path(placeholder_user)++ expect(page).to have_selector '.button', text: 'Delete'+ click_on 'Delete'++ # Expect to be on delete confirmation+ expect(page).to have_selector('.danger-zone--verification button[disabled]')+ fill_in 'name_verification', with: placeholder_user.name++ expect(page).to have_selector('.danger-zone--verification button:not([disabled])')+ click_on 'Delete'++ expect(page).to have_selector('.flash.info', text: I18n.t(:notice_deletion_scheduled))++ # The user is still there+ placeholder_user.reload++ perform_enqueued_jobs++ expect { placeholder_user.reload }.to raise_error(ActiveRecord::RecordNotFound)+ end+ end++ context 'as admin' do+ current_user { FactoryBot.create :admin }++ it_behaves_like 'placeholders delete flow'+ end++ context 'as user with global permission' do+ current_user { FactoryBot.create :user, global_permission: %i[manage_placeholder_user] }++ it_behaves_like 'placeholders delete flow'+ end++ context 'as user without global permission' do+ current_user { FactoryBot.create :user }++ it 'returns an error' do+ visit deletion_info_placeholder_user_path(placeholder_user)+ expect(page).to have_text 'You are not authorized to access this page.'+ end+ end+enddiff --git a/spec/features/placeholder_users/edit_placeholder_users_spec.rb b/spec/features/placeholder_users/edit_placeholder_users_spec.rbindex c8922c37444..98338598d29 100644--- a/spec/features/placeholder_users/edit_placeholder_users_spec.rb+++ b/spec/features/placeholder_users/edit_placeholder_users_spec.rb@@ -56,7 +56,7 @@ describe 'edit placeholder users', type: :feature, js: true doendcontext 'as user with global permission' do- current_user { FactoryBot.create :user, global_permission: %i[add_placeholder_user] }+ current_user { FactoryBot.create :user, global_permission: %i[manage_placeholder_user] }it_behaves_like 'placeholders edit flow'enddiff --git a/spec/features/placeholder_users/index_spec.rb b/spec/features/placeholder_users/index_spec.rbindex 9d77ab12aae..ce12534816d 100644--- a/spec/features/placeholder_users/index_spec.rb+++ b/spec/features/placeholder_users/index_spec.rb@@ -77,7 +77,7 @@ describe 'index placeholder users', type: :feature doendcontext 'as user with global permission' do- current_user { FactoryBot.create :user, global_permission: %i[add_placeholder_user] }+ current_user { FactoryBot.create :user, global_permission: %i[manage_placeholder_user] }it_behaves_like 'placeholders index flow'enddiff --git a/spec/features/placeholder_users/placeholder_user_memberships_spec.rb b/spec/features/placeholder_users/placeholder_user_memberships_spec.rbindex e265911c232..51ea4bd7526 100644--- a/spec/features/placeholder_users/placeholder_user_memberships_spec.rb+++ b/spec/features/placeholder_users/placeholder_user_memberships_spec.rb@@ -41,5 +41,5 @@ feature 'placeholder user memberships through placeholder user page', type: :feait_behaves_like 'principal membership management flows'end- it_behaves_like 'global user principal membership management flows', :add_placeholder_user+ it_behaves_like 'global user principal membership management flows', :manage_placeholder_userenddiff --git a/spec/features/users/create_spec.rb b/spec/features/users/create_spec.rbindex bb85d502072..fee6345577a 100644--- a/spec/features/users/create_spec.rb+++ b/spec/features/users/create_spec.rb@@ -144,8 +144,8 @@ describe 'create users', type: :feature, selenium: true doendcontext 'as global user' do- shared_let(:global_add_user) { FactoryBot.create :user, global_permission: :add_user }- let(:current_user) { global_add_user }+ shared_let(:global_manage_user) { FactoryBot.create :user, global_permission: :manage_user }+ let(:current_user) { global_manage_user }context 'with internal authentication' dobefore dodiff --git a/spec/features/users/delete_spec.rb b/spec/features/users/delete_spec.rbindex 6d5cd57b735..0201f45aa91 100644--- a/spec/features/users/delete_spec.rb+++ b/spec/features/users/delete_spec.rb@@ -68,7 +68,7 @@ describe 'user deletion: ', type: :feature, js: true docontext 'user with global add role' dolet!(:user) { FactoryBot.create :user }- let(:current_user) { FactoryBot.create :user, global_permission: :add_user }+ let(:current_user) { FactoryBot.create :user, global_permission: :manage_user }it 'can not delete even if settings allow it', js: true doSetting.users_deletable_by_admins = 1diff --git a/spec/features/users/edit_users_spec.rb b/spec/features/users/edit_users_spec.rbindex 706aa7dd59b..2796dd963f4 100644--- a/spec/features/users/edit_users_spec.rb+++ b/spec/features/users/edit_users_spec.rb@@ -85,8 +85,8 @@ describe 'edit users', type: :feature, js: true doendcontext 'as global user' do- shared_let(:global_add_user) { FactoryBot.create :user, global_permission: :add_user }- let(:current_user) { global_add_user }+ shared_let(:global_manage_user) { FactoryBot.create :user, global_permission: :manage_user }+ let(:current_user) { global_manage_user }it 'can too edit the user' dovisit edit_user_path(user)diff --git a/spec/features/users/index_spec.rb b/spec/features/users/index_spec.rbindex 921218a4d39..7ae7991fd2c 100644--- a/spec/features/users/index_spec.rb+++ b/spec/features/users/index_spec.rb@@ -147,8 +147,8 @@ describe 'index users', type: :feature doendcontext 'as global user' do- shared_let(:global_add_user) { FactoryBot.create :user, global_permission: :add_user }- let(:current_user) { global_add_user }+ shared_let(:global_manage_user) { FactoryBot.create :user, global_permission: :manage_user }+ let(:current_user) { global_manage_user }it 'can too visit the page' doindex_page.visit!diff --git a/spec/features/users/invitation_spec.rb b/spec/features/users/invitation_spec.rbindex feeb9b31f6a..600ce789a1d 100644--- a/spec/features/users/invitation_spec.rb+++ b/spec/features/users/invitation_spec.rb@@ -59,7 +59,7 @@ feature 'invitation spec', type: :feature, js: true doendcontext 'as global user' do- shared_let(:global_add_user) { FactoryBot.create :user, global_permission: :add_user }- let(:current_user) { global_add_user }+ shared_let(:global_manage_user) { FactoryBot.create :user, global_permission: :manage_user }+ let(:current_user) { global_manage_user }endenddiff --git a/spec/features/users/user_memberships_spec.rb b/spec/features/users/user_memberships_spec.rbindex a0ce7bcd0d8..0c61eb74758 100644--- a/spec/features/users/user_memberships_spec.rb+++ b/spec/features/users/user_memberships_spec.rb@@ -41,5 +41,5 @@ feature 'user memberships through user page', type: :feature, js: true doit_behaves_like 'principal membership management flows'end- it_behaves_like 'global user principal membership management flows', :add_user+ it_behaves_like 'global user principal membership management flows', :manage_userend\ No newline at end of filediff --git a/spec/requests/api/v3/user/create_user_resource_spec.rb b/spec/requests/api/v3/user/create_user_resource_spec.rbindex 6d5338edaa0..535e24fad6a 100644--- a/spec/requests/api/v3/user/create_user_resource_spec.rb+++ b/spec/requests/api/v3/user/create_user_resource_spec.rb@@ -195,7 +195,7 @@ describe ::API::V3::Users::UsersAPI, type: :request doenddescribe 'user with global user CRU permission' do- shared_let(:current_user) { FactoryBot.create :user, global_permission: :add_user }+ shared_let(:current_user) { FactoryBot.create :user, global_permission: :manage_user }it_behaves_like 'create user request flow'diff --git a/spec/requests/api/v3/user/update_user_resource_spec.rb b/spec/requests/api/v3/user/update_user_resource_spec.rbindex 7ef94ac5a09..6573243b020 100644--- a/spec/requests/api/v3/user/update_user_resource_spec.rb+++ b/spec/requests/api/v3/user/update_user_resource_spec.rb@@ -127,9 +127,9 @@ describe ::API::V3::Users::UsersAPI, type: :request doendend- describe 'user with global add_user permission' do- shared_let(:global_add_user) { FactoryBot.create :user, global_permission: :add_user }- let(:current_user) { global_add_user }+ describe 'user with global manage_user permission' do+ shared_let(:global_manage_user) { FactoryBot.create :user, global_permission: :manage_user }+ let(:current_user) { global_manage_user }it_behaves_like 'update flow'diff --git a/spec/requests/api/v3/user/user_resource_spec.rb b/spec/requests/api/v3/user/user_resource_spec.rbindex 5b35d006712..a577b3c4b7d 100644--- a/spec/requests/api/v3/user/user_resource_spec.rb+++ b/spec/requests/api/v3/user/user_resource_spec.rb@@ -39,8 +39,8 @@ describe 'API v3 User resource',let(:user) { FactoryBot.create(:user) }let(:admin) { FactoryBot.create(:admin) }let(:locked_admin) { FactoryBot.create :admin, status: Principal.statuses[:locked] }- let(:user_with_global_add_user) do- FactoryBot.create :user, firstname: 'Global', lastname: 'User', global_permission: :add_user+ let(:user_with_global_manage_user) do+ FactoryBot.create :user, firstname: 'Global', lastname: 'User', global_permission: :manage_userendsubject(:response) { last_response }@@ -161,8 +161,8 @@ describe 'API v3 User resource',it_behaves_like 'flow with permitted user'end- context 'user with global add_user permission' do- let(:current_user) { user_with_global_add_user }+ context 'user with global manage_user permission' do+ let(:current_user) { user_with_global_manage_user }it_behaves_like 'flow with permitted user'end@@ -304,8 +304,8 @@ describe 'API v3 User resource',it_behaves_like 'deletion is not allowed'end- context 'as user with add_user permission' do- let(:current_user) { user_with_global_add_user }+ context 'as user with manage_user permission' do+ let(:current_user) { user_with_global_manage_user }it_behaves_like 'deletion is not allowed'enddiff --git a/spec/services/placeholder_users/delete_service_spec.rb b/spec/services/placeholder_users/delete_service_spec.rbindex e2d8077d6a2..22521208af0 100644--- a/spec/services/placeholder_users/delete_service_spec.rb+++ b/spec/services/placeholder_users/delete_service_spec.rb@@ -29,71 +29,57 @@require 'spec_helper'describe ::PlaceholderUsers::DeleteService, type: :model do- skip 'Skipped as we will tackle the DeleteService in a separate PR' do- let(:input_user) { FactoryBot.build_stubbed(:user) }- let(:project) { FactoryBot.build_stubbed(:project) }+ let(:placeholder_user) { FactoryBot.build_stubbed(:placeholder_user) }+ let(:project) { FactoryBot.build_stubbed(:project) }- let(:instance) { described_class.new(model: input_user, user: actor) }+ let(:instance) { described_class.new(model: placeholder_user, user: actor) }- subject { instance.call }+ subject { instance.call }- shared_examples 'deletes the user' do- it do- expect(input_user).to receive(:lock!)- expect(Principals::DeleteJob).to receive(:perform_later).with(input_user)- expect(subject).to eq true- end+ shared_examples 'deletes the user' do+ it do+ expect(placeholder_user).to receive(:locked!)+ expect(Principals::DeleteJob).to receive(:perform_later).with(placeholder_user)+ expect(subject).to be_successend+ end- shared_examples 'does not delete the user' do- it do- expect(input_user).not_to receive(:lock!)- expect(Principals::DeleteJob).not_to receive(:perform_later)- expect(subject).to eq false- end+ shared_examples 'does not delete the user' do+ it do+ expect(placeholder_user).not_to receive(:locked!)+ expect(Principals::DeleteJob).not_to receive(:perform_later)+ expect(subject).not_to be_successend+ end- context 'if deletion by admins allowed', with_settings: { users_deletable_by_admins: true } do- context 'with admin user' do- let(:actor) { FactoryBot.build_stubbed(:admin) }-- it_behaves_like 'deletes the user'- end+ context 'with admin user' do+ let(:actor) { FactoryBot.build_stubbed(:admin) }- context 'with unprivileged system user' do- let(:actor) { User.system }+ it_behaves_like 'deletes the user'+ end- before do- allow(actor).to receive(:admin?).and_return false- end+ context 'with gloal user' do+ let(:actor) { FactoryBot.create(:user, global_permission: %i[manage_placeholder_user]) }- it_behaves_like 'does not delete the user'- end+ it_behaves_like 'deletes the user'+ end- context 'with privileged system user' do- let(:actor) { User.system }+ context 'with unprivileged system user' do+ let(:actor) { User.system }- it 'performs deletion' do- actor.run_given do- expect(input_user).to receive(:lock!)- expect(Principals::DeleteJob).to receive(:perform_later).with(input_user)- expect(subject).to eq true- end- end- end+ before do+ allow(actor).to receive(:admin?).and_return falseend- context 'if deletion by admins NOT allowed', with_settings: { users_deletable_by_admins: false } do- context 'with admin user' do- let(:actor) { FactoryBot.build_stubbed(:admin) }-- it_behaves_like 'does not delete the user'- end+ it_behaves_like 'does not delete the user'+ end- context 'with system user' do- let(:actor) { User.system }+ context 'with privileged system user' do+ let(:actor) { User.system }- it_behaves_like 'does not delete the user'+ it_behaves_like 'deletes the user' do+ around do |example|+ actor.run_given { example.run }endendend