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
Add 'Global role' tab for groups
Christophe Bliard15f00ffe847b
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rbindex 49f1df03d2b..dc055766f02 100644--- a/app/controllers/groups_controller.rb+++ b/app/controllers/groups_controller.rb@@ -176,12 +176,13 @@ class GroupsController < ApplicationControllerenddef destroy_membership+ member = Member.find(params[:membership_id])Members::DeleteService- .new(model: Member.find(params[:membership_id]), user: current_user)+ .new(model: member, user: current_user).callflash[:notice] = I18n.t :notice_successful_delete- redirect_to controller: '/groups', action: 'edit', id: @group, tab: 'memberships'+ redirect_to controller: '/groups', action: 'edit', id: @group, tab: redirected_to_tab(member)endprotected@@ -222,7 +223,15 @@ class GroupsController < ApplicationControllerflash[:error] = service_call.errors.full_messages.join("\n")end- redirect_to controller: '/groups', action: 'edit', id: @group, tab: 'memberships'+ redirect_to controller: '/groups', action: 'edit', id: @group, tab: redirected_to_tab(service_call.result)+ end++ def redirected_to_tab(membership)+ if membership.project+ 'memberships'+ else+ 'global_roles'+ endenddef respond_users_altered(service_call)diff --git a/app/helpers/groups_helper.rb b/app/helpers/groups_helper.rbindex db8b08611a3..f0e31543071 100644--- a/app/helpers/groups_helper.rb+++ b/app/helpers/groups_helper.rb@@ -48,6 +48,12 @@ module GroupsHelperpartial: 'groups/memberships',path: edit_group_path(@group, tab: :memberships),label: :label_project_plural+ },+ {+ name: 'global_roles',+ partial: 'groups/global_roles',+ path: edit_group_path(@group, tab: :global_roles),+ label: :label_global_roles}]enddiff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rbindex fa48abc2620..7fec059897d 100644--- a/app/helpers/members_helper.rb+++ b/app/helpers/members_helper.rb@@ -36,12 +36,26 @@ module MembersHelper# If it is the later, the ids of the non delete roles are appended to the url so that they are kept.def global_member_role_deletion_link(member, role)if member.roles.length == 1+ path =+ if member.principal.is_a?(Group)+ membership_of_group_path(member.principal, member)+ else+ user_membership_path(user_id: member.user_id, id: member.id)+ end+link_to('',- user_membership_path(user_id: member.user_id, id: member.id),+ path,{ method: :delete, class: 'icon icon-delete', title: t(:button_delete) })else+ path =+ if member.principal.is_a?(Group)+ membership_of_group_path(member.principal, member, 'membership[role_ids]' => member.roles - [role])+ else+ user_membership_path(user_id: member.user_id, id: member.id, 'membership[role_ids]' => member.roles - [role])+ end+link_to('',- user_membership_path(user_id: member.user_id, id: member.id, 'membership[role_ids]' => member.roles - [role]),+ path,{ method: :patch, class: 'icon icon-delete', title: t(:button_delete) })endenddiff --git a/app/models/member.rb b/app/models/member.rbindex 7c0984ae083..bf7c3a53267 100644--- a/app/models/member.rb+++ b/app/models/member.rb@@ -34,7 +34,7 @@ class Member < ApplicationRecordextend DeprecatedAliasbelongs_to :principal, foreign_key: 'user_id'has_many :member_roles, dependent: :destroy, autosave: true, validate: false- has_many :roles, through: :member_roles+ has_many :roles, -> { distinct }, through: :member_rolesbelongs_to :projectvalidates_presence_of :principaldiff --git a/app/views/groups/_assigned_global_role.html.erb b/app/views/groups/_assigned_global_role.html.erbnew file mode 100644index 00000000000..a8db1612c7a--- /dev/null+++ b/app/views/groups/_assigned_global_role.html.erb@@ -0,0 +1,37 @@+<%#-- 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 COPYRIGHT and LICENSE files for more details.++++#%>++<tr id="assigned_global_role_<%= role.id%>">+ <td class="role">+ <%=h role %>+ </td>+ <td class="buttons">+ <%= global_member_role_deletion_link(member, role) %>+ </td>+</tr>diff --git a/app/views/groups/_available_global_role.html.erb b/app/views/groups/_available_global_role.html.erbnew file mode 100644index 00000000000..d4a3aaf2332--- /dev/null+++ b/app/views/groups/_available_global_role.html.erb@@ -0,0 +1,42 @@+<%#-- 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 COPYRIGHT and LICENSE files for more details.++++#%>++<%+ name = global_member ? 'membership[role_ids][]' : 'new_membership[role_ids][]'+%>++<div class="principal_role_option form--field" id= "principal_role_option_<%= h(role.id) %>">+ <label class="form--label-with-check-box" for="principal_role_role_ids_<%= role.id %>">+ <%= check_box_tag name,+ role.id,+ false,+ id: "principal_role_role_ids_#{role.id}" %>+ <%= h(role)%>+ </label>+</div>diff --git a/app/views/groups/_available_global_roles.html.erb b/app/views/groups/_available_global_roles.html.erbnew file mode 100644index 00000000000..66dd037712b--- /dev/null+++ b/app/views/groups/_available_global_roles.html.erb@@ -0,0 +1,65 @@+<%#-- 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 COPYRIGHT and LICENSE files for more details.++++#%>++<% available_roles = GlobalRole.all - (global_member&.roles || []) %>++<div class="grid-content" id="available_principal_roles">+ <fieldset class="form--fieldset">+ <legend class="form--fieldset-legend"><%= Role.model_name.human(:count => 2) %></legend>+ <% if available_roles.empty? %>+ <span id="no_additional_principal_roles">+ <%= no_results_box %>+ </span>+ <% else %>+ <span id="additional_principal_roles">+ <% args =+ if global_member+ { url: membership_of_group_path(group, global_member), method: :put }+ else+ { url: memberships_of_group_path(group), method: :post }+ end+ %>+ <%= form_for(:principal_roles, **args) do %>+ <% if global_member %>+ <%= hidden_field_tag('membership[id]', global_member.id ) %>++ <% global_member.roles.each do |role| %>+ <%= hidden_field_tag('membership[role_ids][]', role.id ) %>+ <% end %>+ <% end %>++ <% available_roles.each do |role| %>+ <%= render :partial => 'groups/available_global_role', :locals => {role: role, global_member: global_member} %>+ <% end %>+ <p><br/><%= styled_button_tag t(:button_add), class: '-with-icon icon-checkmark' %></p>+ <% end %>+ </span>+ <% end %>+ </fieldset>+</div>diff --git a/app/views/groups/_global_roles.html.erb b/app/views/groups/_global_roles.html.erbnew file mode 100644index 00000000000..8cb25c89548--- /dev/null+++ b/app/views/groups/_global_roles.html.erb@@ -0,0 +1,73 @@+<%#-- 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 COPYRIGHT and LICENSE files for more details.++++#%>++<%= render partial: 'global_roles_header' %>++<% global_member = Member.global.where(principal: @group).includes(:roles).first %>++<div class="grid-block" id="principal_global_roles_content">+ <div id="assigned_principal_roles" class="grid-content">+ <% unless global_member&.roles&.any? %>+ <%= no_results_box %>+ <% else %>+ <div class="generic-table--container">+ <div class="generic-table--results-container">+ <table class="generic-table principal_roles" id="table_principal_roles">+ <colgroup>+ <col opHighlightCol>+ <col>+ </colgroup>+ <thead>+ <tr>+ <th>+ <div class="generic-table--sort-header-outer">+ <div class="generic-table--sort-header">+ <span>+ <%= Role.model_name.human %>+ </span>+ </div>+ </div>+ </th>+ <th><div class="generic-table--empty-header"></div></th>+ </tr>+ </thead>+ <tbody id="table_principal_roles_body">+ <% global_member.roles.each do |role| %>+ <%= render :partial => 'assigned_global_role', :locals => { :role => role, member: global_member } %>+ <%end%>+ </tbody>+ </table>++ </div>+ </div>+ <% end %>+ </div>++ <%= render partial: 'groups/available_global_roles', locals: { group: @group, global_member: global_member }%>+</div>diff --git a/app/views/groups/_global_roles_header.html.erb b/app/views/groups/_global_roles_header.html.erbnew file mode 100644index 00000000000..2ead7011daa--- /dev/null+++ b/app/views/groups/_global_roles_header.html.erb@@ -0,0 +1,32 @@+<%#-- 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 COPYRIGHT and LICENSE files for more details.++++#%>++<% content_for :header_tags do %>+ <meta name="required_script" content="global_roles" />+<% end %>diff --git a/config/routes.rb b/config/routes.rbindex 3b17d48e57d..3a6bee49549 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -366,7 +366,8 @@ OpenProject::Application.routes.draw domatch '/members' => 'groups#add_users', via: :post, as: 'members_of'match '/members/:user_id' => 'groups#remove_user', via: :delete, as: 'member_of'# this should be put into it's own resource- match '/memberships/:membership_id' => 'groups#edit_membership', via: :put, as: 'membership_of'+ match '/memberships/:membership_id' => 'groups#edit_membership', via: :patch, as: 'membership_of'+ match '/memberships/:membership_id' => 'groups#edit_membership', via: :putmatch '/memberships/:membership_id' => 'groups#destroy_membership', via: :deletematch '/memberships' => 'groups#create_memberships', via: :post, as: 'memberships_of'end