2025-07-18 17:36:37 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2021-02-12 17:18:55 +01:00
|
|
|
#-- copyright
|
|
|
|
|
# OpenProject is an open source project management software.
|
2024-07-30 13:42:36 +02:00
|
|
|
# Copyright (C) the OpenProject GmbH
|
2021-02-12 17:18:55 +01:00
|
|
|
#
|
|
|
|
|
# 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:
|
2024-08-16 19:06:57 +02:00
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
2021-02-12 17:18:55 +01:00
|
|
|
# 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.
|
|
|
|
|
#
|
2021-09-02 21:49:06 +02:00
|
|
|
# See COPYRIGHT and LICENSE files for more details.
|
2021-02-12 17:18:55 +01:00
|
|
|
#++
|
|
|
|
|
|
|
|
|
|
class PlaceholderUsersController < ApplicationController
|
|
|
|
|
layout "admin"
|
2021-02-16 14:16:35 +01:00
|
|
|
before_action :authorize_global, except: %i[show]
|
2024-06-11 10:20:38 +02:00
|
|
|
no_authorization_required! :show
|
2021-02-16 14:16:35 +01:00
|
|
|
|
2021-02-12 17:18:55 +01:00
|
|
|
before_action :find_placeholder_user, only: %i[show
|
|
|
|
|
edit
|
|
|
|
|
update
|
2021-02-17 10:22:14 +01:00
|
|
|
deletion_info
|
2021-02-12 17:18:55 +01:00
|
|
|
destroy]
|
|
|
|
|
|
2021-05-31 16:31:41 +02:00
|
|
|
before_action :authorize_deletion, only: %i[deletion_info destroy]
|
|
|
|
|
|
2021-02-12 17:18:55 +01:00
|
|
|
def index
|
2023-05-18 13:05:27 +03:00
|
|
|
@placeholder_users = PlaceholderUsers::PlaceholderUserFilterComponent.query params
|
2021-02-12 17:18:55 +01:00
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html do
|
|
|
|
|
render layout: !request.xhr?
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def show
|
2023-09-13 08:46:06 +02:00
|
|
|
# show projects based on current user visibility.
|
|
|
|
|
# But don't simply concatenate the .visible scope to the memberships
|
|
|
|
|
# as .memberships has an include and an order which for whatever reason
|
|
|
|
|
# also gets applied to the Project.allowed_to parts concatenated by a UNION
|
|
|
|
|
# and an order inside a UNION is not allowed in postgres.
|
|
|
|
|
@memberships = @placeholder_user
|
|
|
|
|
.memberships
|
|
|
|
|
.where(id: Member.visible(current_user))
|
2021-02-12 17:18:55 +01:00
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html { render layout: "no_menu" }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def new
|
|
|
|
|
@placeholder_user = PlaceholderUsers::SetAttributesService
|
2021-02-16 14:16:35 +01:00
|
|
|
.new(user: User.current,
|
|
|
|
|
model: PlaceholderUser.new,
|
|
|
|
|
contract_class: EmptyContract)
|
|
|
|
|
.call({})
|
|
|
|
|
.result
|
2021-02-12 17:18:55 +01:00
|
|
|
end
|
|
|
|
|
|
2023-03-09 10:25:57 +01:00
|
|
|
def edit
|
|
|
|
|
@membership ||= Member.new
|
|
|
|
|
@individual_principal = @placeholder_user
|
|
|
|
|
end
|
|
|
|
|
|
2024-11-05 06:46:17 +01:00
|
|
|
def create # rubocop:disable Metrics/AbcSize
|
2021-02-12 17:18:55 +01:00
|
|
|
service = PlaceholderUsers::CreateService.new(user: User.current)
|
|
|
|
|
service_result = service.call(permitted_params.placeholder_user)
|
|
|
|
|
@placeholder_user = service_result.result
|
|
|
|
|
|
|
|
|
|
if service_result.success?
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html do
|
|
|
|
|
flash[:notice] = I18n.t(:notice_successful_create)
|
|
|
|
|
redirect_to(params[:continue] ? new_placeholder_user_path : edit_placeholder_user_path(@placeholder_user))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html do
|
2024-08-28 12:43:09 +02:00
|
|
|
render action: :new, status: :unprocessable_entity
|
2021-02-12 17:18:55 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-11-05 06:46:17 +01:00
|
|
|
def update # rubocop:disable Metrics/AbcSize
|
2021-02-12 17:18:55 +01:00
|
|
|
service_result = PlaceholderUsers::UpdateService
|
2021-02-16 14:16:35 +01:00
|
|
|
.new(user: User.current,
|
|
|
|
|
model: @placeholder_user)
|
|
|
|
|
.call(permitted_params.placeholder_user)
|
2021-02-12 17:18:55 +01:00
|
|
|
|
|
|
|
|
if service_result.success?
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html do
|
|
|
|
|
flash[:notice] = I18n.t(:notice_successful_update)
|
2026-02-02 11:06:25 +01:00
|
|
|
redirect_back_or_to(edit_placeholder_user_path(@placeholder_user))
|
2021-02-12 17:18:55 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
@membership ||= Member.new
|
|
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html do
|
2024-08-28 12:43:09 +02:00
|
|
|
render action: :edit, status: :unprocessable_entity
|
2021-02-12 17:18:55 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-02-17 10:22:14 +01:00
|
|
|
def deletion_info
|
|
|
|
|
respond_to :html
|
|
|
|
|
end
|
|
|
|
|
|
2021-02-12 17:18:55 +01:00
|
|
|
def destroy
|
2021-02-16 08:46:53 +01:00
|
|
|
PlaceholderUsers::DeleteService
|
|
|
|
|
.new(user: User.current, model: @placeholder_user)
|
|
|
|
|
.call
|
2021-02-12 17:18:55 +01:00
|
|
|
|
2021-02-16 08:46:53 +01:00
|
|
|
flash[:info] = I18n.t(:notice_deletion_scheduled)
|
2021-02-12 17:18:55 +01:00
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html do
|
|
|
|
|
redirect_to placeholder_users_path
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def find_placeholder_user
|
2026-02-02 11:06:25 +01:00
|
|
|
@placeholder_user = PlaceholderUser.visible.find(params[:id])
|
2021-02-12 17:18:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
2021-05-31 16:31:41 +02:00
|
|
|
def authorize_deletion
|
|
|
|
|
unless helpers.can_delete_placeholder_user?(@placeholder_user, current_user)
|
|
|
|
|
render_403 message: I18n.t("placeholder_users.right_to_manage_members_missing")
|
|
|
|
|
end
|
|
|
|
|
end
|
2021-02-12 17:18:55 +01:00
|
|
|
end
|