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
admin users controller
Oliver Günthere0e34af4dc99
diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erbindex 4438763602c..2119571c5b6 100644--- a/app/views/users/_form.html.erb+++ b/app/views/users/_form.html.erb@@ -29,10 +29,6 @@ See COPYRIGHT and LICENSE files for more details.<%= error_messages_for_contract @user, @errors %>-<% content_for :header_tags do %>- <meta name="required_script" content="admin_users" />-<% end %>-<section class="form--section"><%= render partial: 'users/form/basic_attributes', locals: { f: f } %>diff --git a/app/views/users/_general.html.erb b/app/views/users/_general.html.erbindex d172b0f01ce..8da07090c16 100644--- a/app/views/users/_general.html.erb+++ b/app/views/users/_general.html.erb@@ -40,10 +40,20 @@ See COPYRIGHT and LICENSE files for more details.<%= labelled_tabular_form_for @user,url: { controller: '/users',- action: "update",- tab: nil },- html: { method: :put,- autocomplete: 'off' },+ action: "update",+ tab: nil },+ html: {+ method: :put,+ autocomplete: 'off',+ data: {+ controller: 'admin-users',+ 'application-target': 'dynamic'+ }+ },+ data: {+ controller: 'admin-users',+ 'application-target': 'dynamic',+ },as: :user do |f| %><%= render partial: 'form', locals: { f: f } %>diff --git a/app/views/users/form/authentication/_auth_source.html.erb b/app/views/users/form/authentication/_auth_source.html.erbindex 53f54184ff7..45fb5819a10 100644--- a/app/views/users/form/authentication/_auth_source.html.erb+++ b/app/views/users/form/authentication/_auth_source.html.erb@@ -4,12 +4,18 @@AuthSource.all,:id,:name,- label: :'activerecord.attributes.user.auth_source',- container_class: '-middle',- include_blank: t(:label_internal) %>+ {+ label: :'activerecord.attributes.user.auth_source',+ container_class: '-middle',+ include_blank: t(:label_internal)+ },+ data: {+ action: 'admin-users#togglePasswordFields'+ }+ %></div><div class="form--field" id="new_user_login" style="display: none;"><%= f.text_field :login, required: true, size: 25, disabled: true %></div>-<% end %>\ No newline at end of file+<% end %>diff --git a/app/views/users/form/authentication/_internal_password.html.erb b/app/views/users/form/authentication/_internal_password.html.erbindex e1eba37ab39..402a73b9026 100644--- a/app/views/users/form/authentication/_internal_password.html.erb+++ b/app/views/users/form/authentication/_internal_password.html.erb@@ -1,21 +1,23 @@-<%- pw_style =- if @user.change_password_allowed?- ''- else- ' style="display: none;"'- end-%>-<div id="password_fields"<%= pw_style.html_safe %>>++<%= content_tag :div,+ data: {+ controller: 'disable-when-checked',+ 'admin-users-target': 'passwordFields'+ },+ hidden: [email protected]_password_allowed? do %><% assign_random_password_enabled = params[:user] &¶ms[:user][:assign_random_password] %><div class="form--field"><%= styled_label_tag 'user_assign_random_password',I18n.t(:assign_random_password, scope: :user) %><div class="form--field-container">- <%= styled_check_box_tag("user[assign_random_password]",+ <%= styled_check_box_tag "user[assign_random_password]","1",- assign_random_password_enabled) %>+ assign_random_password_enabled,+ data: {+ 'disable-when-checked-target': 'cause'+ }+ %></div></div>@@ -24,6 +26,9 @@<%= f.password_field :password,required: @user.new_record?,disabled: assign_random_password_enabled,+ data: {+ 'disable-when-checked-target': 'effect'+ },container_class: '-middle' %><div class="form--field-instructions"><%= password_complexity_requirements %>@@ -33,12 +38,15 @@<%= f.password_field :password_confirmation,required: @user.new_record?,disabled: assign_random_password_enabled,+ data: {+ 'disable-when-checked-target': 'effect'+ },container_class: '-middle' %></div><% end %><% if @user.active? -%>- <div class="form--field send-information -hidden">+ <div class="form--field send-information"><%= styled_label_tag 'send_information', t(:label_send_information) %><div class="form--field-container"><%= styled_check_box_tag("send_information",@@ -52,4 +60,4 @@<%= f.check_box :force_password_change,disabled: assign_random_password_enabled %></div>-</div>\ No newline at end of file+<% end %>diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 162ef8bf790..56733a1362e 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1985,7 +1985,7 @@ en:label_role_search: "Assign role to new members"label_scm: "SCM"label_search: "Search"- label_send_information: "Send account information to the user"+ label_send_information: "Send new credentials to the user"label_send_test_email: "Send a test email"label_setting_plural: "Settings"label_system_settings: "System settings"diff --git a/frontend/src/app/core/augmenting/dynamic-scripts/admin_users.js b/frontend/src/app/core/augmenting/dynamic-scripts/admin_users.jsdeleted file mode 100644index f1ae18f8235..00000000000--- a/frontend/src/app/core/augmenting/dynamic-scripts/admin_users.js+++ /dev/null@@ -1,72 +0,0 @@-//-- copyright-// OpenProject is an open source project management software.-// Copyright (C) 2012-2023 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 COPYRIGHT and LICENSE files for more details.-//++---(function() {- // When 'assign random password' field is enabled,- // disable and clear password fields and disable and check the- // 'force password reset' field- function on_assign_random_password_change(){- var checked = jQuery('#user_assign_random_password').is(':checked');- jQuery('#user_password').prop('disabled', checked);- jQuery('#user_password_confirmation').prop('disabled', checked);- jQuery('#user_password').val('');- jQuery('#user_password_confirmation').val('');- jQuery('#user_force_password_change').prop('checked', checked)- .prop('disabled', checked);- }-- /**- * Hide password fields when non-internal authentication source is selected.- * Also disables the fields so they are not submitted and not required to- * enter.- */- function on_auth_source_change() {- var passwordFields = jQuery('#password_fields'),- passwordInputs = passwordFields.find('#user_password, #user_password_confirmation');-- if (this.value === '') {- passwordFields.show();- passwordInputs.prop('disabled', false);- } else {- passwordFields.hide();- passwordInputs.prop('disabled', 'disabled');- }- }-- function on_password_change() {- var sendInformationField = jQuery('.send-information');- sendInformationField.toggleClass('-hidden', jQuery(this).val() === '');- }-- jQuery(function init(){- jQuery('#user_assign_random_password').change(on_assign_random_password_change);- jQuery('#user_auth_source_id').on('change.togglePasswordFields', on_auth_source_change);- jQuery('#user_password').change(on_password_change);- });-})();diff --git a/frontend/src/stimulus/controllers/dynamic/admin-users.controller.ts b/frontend/src/stimulus/controllers/dynamic/admin-users.controller.tsnew file mode 100644index 00000000000..675e20e2692--- /dev/null+++ b/frontend/src/stimulus/controllers/dynamic/admin-users.controller.ts@@ -0,0 +1,18 @@+import { Controller } from '@hotwired/stimulus';++export default class AdminUsersController extends Controller {+ static targets = ['passwordFields'];++ declare readonly passwordFieldsTarget:HTMLElement;++ togglePasswordFields(evt:{ target:HTMLSelectElement }):void {+ const selected = evt.target.value;++ this.passwordFieldsTarget.hidden = selected !== '';+ this.passwordFieldsTarget+ .querySelectorAll('input[type="password"]')+ .forEach((el:HTMLInputElement) => {+ el.disabled = selected !== '';+ });+ }+}