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
employ stimulus controller on role admin page
ulfertsf9703eeba602
diff --git a/app/views/principals/_global_roles.html.erb b/app/views/principals/_global_roles.html.erbindex 19087af177d..53304b5c22c 100644--- a/app/views/principals/_global_roles.html.erb+++ b/app/views/principals/_global_roles.html.erb@@ -27,8 +27,6 @@ See COPYRIGHT and LICENSE files for more details.++#%>-<%= render partial: 'principals/global_roles_header' %>-<%principal = @group || @userglobal_member = Member.global.where(principal: principal).includes(:roles).firstdiff --git a/app/views/principals/_global_roles_header.html.erb b/app/views/principals/_global_roles_header.html.erbdeleted file mode 100644index 7894c8da1c0..00000000000--- a/app/views/principals/_global_roles_header.html.erb+++ /dev/null@@ -1,32 +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.--++#%>--<% content_for :header_tags do %>- <meta name="required_script" content="global_roles" />-<% end %>diff --git a/app/views/roles/_form.html.erb b/app/views/roles/_form.html.erbindex f0bb67f6b55..392fa0344a2 100644--- a/app/views/roles/_form.html.erb+++ b/app/views/roles/_form.html.erb@@ -27,44 +27,45 @@ See COPYRIGHT and LICENSE files for more details.++#%>-<%= render partial: 'principals/global_roles_header' %>-<% roles ||= nil %><%= error_messages_for_contract(role, @call.errors) if @call %>-<div class="form--field -required">- <%= f.text_field :name, required: true, container_class: '-slim' %>-</div>-<div class="form--field">- <% if role.new_record? %>- <%= styled_label_tag :global_role, t(:label_global_role) %>- <div class="form--field-container">- <%= styled_check_box_tag("global_role", "1", role.is_a?(GlobalRole))%>- </div>- <% else %>- <%= styled_label_tag :unchangeable, "#{t(:label_role_type)} #{t(:label_not_changeable)}" %>- <div class="form--field-container">- <%= (role.is_a?(GlobalRole) ? t(:label_global_role) : t(:label_member_role))%>- </div>- <% end %>-</div>+<div data-controller="admin-roles"+ data-application-target="dynamic"+ data-loader-global-role-value="<%= role.is_a?(GlobalRole) %>">+ <div class="form--field -required">+ <%= f.text_field :name, required: true, container_class: '-slim' %>+ </div>+ <div class="form--field">+ <% if role.new_record? %>+ <%= styled_label_tag :global_role, t(:label_global_role) %>+ <div class="form--field-container">+ <%= styled_check_box_tag("global_role",+ "1",+ role.is_a?(GlobalRole),+ data: {+ action: 'admin-roles#toggle'+ }) %>+ </div>+ <% else %>+ <%= styled_label_tag :unchangeable, "#{t(:label_role_type)} #{t(:label_not_changeable)}" %>+ <div class="form--field-container">+ <%= (role.is_a?(GlobalRole) ? t(:label_global_role) : t(:label_member_role))%>+ </div>+ <% end %>+ </div>-<% if role.new_record? || !role.is_a?(GlobalRole) %>- <div id="member_attributes">+ <div data-admin-roles-target="memberAttributes"><%= render partial: "member_attributes", locals: { f: f, role: role, roles: roles&.select {|r| !r.is_a?(GlobalRole)} }%></div>-<% end %>-<% if role.new_record? || role.is_a?(GlobalRole) %>- <div id="global_permissions" style=<%= role.new_record? && !role.is_a?(GlobalRole) ? "display:none" : ""%> >+ <div data-admin-roles-target="globalPermissions"><%= render partial: "permissions",locals: { permissions: grouped_setable_permissions(GlobalRole.new), role: role, show_global_role: true }%></div>-<% end %>-<% if role.new_record? || !role.is_a?(GlobalRole) %>- <div id="member_permissions" style=<%= role.new_record? && role.is_a?(GlobalRole) ? "display:none" : ""%>>+ <div data-admin-roles-target="memberPermissions"><%= render partial: "permissions",locals: { permissions: grouped_setable_permissions(role), role: role, show_global_role: false }%></div>-<% end %>+</div>diff --git a/frontend/src/app/core/augmenting/dynamic-scripts/global_roles.ts b/frontend/src/app/core/augmenting/dynamic-scripts/global_roles.tsdeleted file mode 100644index a607428c7b2..00000000000--- a/frontend/src/app/core/augmenting/dynamic-scripts/global_roles.ts+++ /dev/null@@ -1,116 +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.-//++--// Loaded dynamically when path matches-(function ($) {- const globalRoles = {- init() {- if (globalRoles.script_applicable()) {- globalRoles.toggle_forms_on_click();- globalRoles.activation_and_visibility_based_on_checked($('#global_role'));- }- },-- toggle_forms_on_click() {- $('#global_role').on('click', this.toggle_forms);- },-- toggle_forms() {- globalRoles.activation_and_visibility_based_on_checked(this);- },-- activation_and_visibility_based_on_checked(element:any) {- if ($(element).prop('checked')) {- globalRoles.show_global_forms();- globalRoles.hide_member_forms();- globalRoles.enable_global_forms();- globalRoles.disable_member_forms();- } else {- globalRoles.show_member_forms();- globalRoles.hide_global_forms();- globalRoles.disable_global_forms();- globalRoles.enable_member_forms();- }- },-- show_global_forms() {- $('#global_permissions').show();- },-- show_member_forms() {- $('#member_attributes').show();- $('#member_permissions').show();- },-- hide_global_forms() {- $('#global_permissions').hide();- },-- hide_member_forms() {- $('#member_attributes').hide();- $('#member_permissions').hide();- },-- enable_global_forms() {- $('#global_attributes input, #global_attributes input, #global_permissions input').each((ix, el) => {- globalRoles.enable_element(el);- });- },-- enable_member_forms() {- $('#member_attributes input, #member_attributes input, #member_permissions input').each((ix, el) => {- globalRoles.enable_element(el);- });- },-- enable_element(element:any) {- $(element).prop('disabled', false);- },-- disable_global_forms() {- $('#global_attributes input, #global_attributes input, #global_permissions input').each((ix, el) => {- globalRoles.disable_element(el);- });- },-- disable_member_forms() {- $('#member_attributes input, #member_attributes input, #member_permissions input').each((ix, el) => {- globalRoles.disable_element(el);- });- },-- disable_element(element:any) {- $(element).prop('disabled', true);- },-- script_applicable() {- return $('body.controller-roles.action-new, body.controller-roles.action-create').length === 1;- },- };- $(document).ready(globalRoles.init);-}(jQuery));diff --git a/frontend/src/stimulus/controllers/dynamic/admin-roles.controller.ts b/frontend/src/stimulus/controllers/dynamic/admin-roles.controller.tsnew file mode 100644index 00000000000..e946d0bee1c--- /dev/null+++ b/frontend/src/stimulus/controllers/dynamic/admin-roles.controller.ts@@ -0,0 +1,61 @@+/*+ * -- copyright+ * OpenProject is an open source project management software.+ * Copyright (C) 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.+ * +++ */++import { Controller } from '@hotwired/stimulus';++export default class AdminRolesController extends Controller {+ static targets = [+ 'memberAttributes',+ 'globalPermissions',+ 'memberPermissions',+ ];++ static values = {+ globalRole: Boolean,+ };++ declare globalRoleValue:boolean;++ declare readonly memberAttributesTarget:HTMLElement;++ declare readonly memberPermissionsTarget:HTMLElement;++ declare readonly globalPermissionsTarget:HTMLElement;++ toggle() {+ this.globalRoleValue = !this.globalRoleValue;+ }++ globalRoleValueChanged() {+ this.memberAttributesTarget.hidden = this.globalRoleValue;+ this.memberPermissionsTarget.hidden = this.globalRoleValue;+ this.globalPermissionsTarget.hidden = !this.globalRoleValue;+ }+}diff --git a/spec/features/global_roles/global_role_crud_spec.rb b/spec/features/global_roles/global_role_crud_spec.rbindex edd222910f4..8868d287143 100644--- a/spec/features/global_roles/global_role_crud_spec.rb+++ b/spec/features/global_roles/global_role_crud_spec.rb@@ -37,18 +37,17 @@ describe 'Global role: Global role CRUD', js: true dologin_as(current_user)end- # And I am already admin- let(:current_user) { create(:admin) }+ current_user { create(:admin) }it 'can create global role with that perm' do# When I go to the new page of "Role"visit new_role_path# Then I should not see block with "#global_permissions"- expect(page).not_to have_selector('#global_permissions', visible: true)+ expect(page).not_to have_selector('.form--fieldset-legend', text: 'GLOBAL')# When I check "Global Role"check 'Global Role'# Then I should see block with "#global_permissions"- expect(page).to have_selector('#global_permissions', visible: true)+ expect(page).to have_selector('.form--fieldset-legend', text: 'GLOBAL')# And I should see "Global group"expect(page).to have_text 'GLOBAL GROUP'# And I should see "Glob test"