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
apply admin-users.controller to new user form
ulferts7d4c77b72e2d
diff --git a/app/views/users/_general.html.erb b/app/views/users/_general.html.erbindex fa8dd6452c9..82521fd5ea5 100644--- a/app/views/users/_general.html.erb+++ b/app/views/users/_general.html.erb@@ -49,6 +49,7 @@ See COPYRIGHT and LICENSE files for more details.data: {controller: 'admin-users','application-target': 'dynamic',+ 'admin-users-password-auth-selected-value': @user.auth_source_id.blank?,},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 45fb5819a10..936b357fe27 100644--- a/app/views/users/form/authentication/_auth_source.html.erb+++ b/app/views/users/form/authentication/_auth_source.html.erb@@ -10,12 +10,14 @@include_blank: t(:label_internal)},data: {- action: 'admin-users#togglePasswordFields'+ action: 'admin-users#toggleAuthenticationFields'}%></div>- <div class="form--field" id="new_user_login" style="display: none;">- <%= f.text_field :login, required: true, size: 25, disabled: true %>+ <div class="form--field"+ hidden+ data-admin-users-target="authSourceFields">+ <%= f.text_field :login, required: true, size: 25 %></div><% end %>diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erbindex 41743697259..121ca07b37f 100644--- a/app/views/users/new.html.erb+++ b/app/views/users/new.html.erb@@ -27,10 +27,6 @@ See COPYRIGHT and LICENSE files for more details.++#%>-<% content_for :header_tags do %>- <meta name="required_script" content="new_user" />-<% end %>-<% html_title t(:label_administration), t("label_user_new") %><% local_assigns[:additional_breadcrumb] = t(:label_user_new) %>@@ -41,6 +37,11 @@ See COPYRIGHT and LICENSE files for more details.<%= labelled_tabular_form_for @user,url: { action: "create" },html: { class: nil, autocomplete: 'off' },+ data: {+ controller: 'admin-users',+ 'application-target': 'dynamic',+ 'admin-users-password-auth-selected-value': @user.auth_source_id.blank?,+ },as: :user do |f| %><%= render partial: 'simple_form', locals: { f: f, auth_sources: @auth_sources, user: @user } %>diff --git a/frontend/src/app/core/augmenting/dynamic-scripts/new_user.js b/frontend/src/app/core/augmenting/dynamic-scripts/new_user.jsdeleted file mode 100644index 2c122dcc96a..00000000000--- a/frontend/src/app/core/augmenting/dynamic-scripts/new_user.js+++ /dev/null@@ -1,55 +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 the user chooses the default internal authentication mode- * no login field is shown as the email is taken by default.- * If another mode is chosen (e.g. LDAP) the field is shown as it- * may be required by the auth source.- */- var toggleLogin = function() {- var newUserLogin = jQuery('#new_user_login');-- if (this.value === '') {- newUserLogin.hide();- newUserLogin.find('input').prop('disabled', true);- } else {- newUserLogin.show();- newUserLogin.find('input').prop('disabled', false);- }- };-- jQuery(function init(){- var select = jQuery('#user_auth_source_id');-- select.on('change.toggleNewUserLogin', toggleLogin);- toggleLogin();- });-})();diff --git a/frontend/src/stimulus/controllers/dynamic/admin-users.controller.ts b/frontend/src/stimulus/controllers/dynamic/admin-users.controller.tsindex 675e20e2692..4515db8cb94 100644--- a/frontend/src/stimulus/controllers/dynamic/admin-users.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/admin-users.controller.ts@@ -1,18 +1,39 @@import { Controller } from '@hotwired/stimulus';export default class AdminUsersController extends Controller {- static targets = ['passwordFields'];+ static targets = [+ 'passwordFields',+ 'authSourceFields',+ ];++ static values = {+ passwordAuthSelected: Boolean,+ };++ declare passwordAuthSelectedValue:boolean;declare readonly passwordFieldsTarget:HTMLElement;- togglePasswordFields(evt:{ target:HTMLSelectElement }):void {- const selected = evt.target.value;+ declare readonly hasPasswordFieldsTarget:boolean;++ declare readonly authSourceFieldsTarget:HTMLElement;++ toggleAuthenticationFields(evt:{ target:HTMLSelectElement }):void {+ this.passwordAuthSelectedValue = evt.target.value === '';+ }++ private passwordAuthSelectedValueChanged() {+ if (this.hasPasswordFieldsTarget) {+ this.toggleHiddenAndDisabled(this.passwordFieldsTarget, !this.passwordAuthSelectedValue);+ }+ this.toggleHiddenAndDisabled(this.authSourceFieldsTarget, this.passwordAuthSelectedValue);+ }- this.passwordFieldsTarget.hidden = selected !== '';- this.passwordFieldsTarget- .querySelectorAll('input[type="password"]')+ private toggleHiddenAndDisabled(target:HTMLElement, hiddenAndDisabled:boolean) {+ target.hidden = hiddenAndDisabled;+ target.querySelectorAll('input').forEach((el:HTMLInputElement) => {- el.disabled = selected !== '';+ el.disabled = hiddenAndDisabled;});}}