Commit a8e3d26b authored by jplang's avatar jplang

Display details about inheritance when editing a member roles (#31032).

git-svn-id: https://svn.redmine.org/redmine/trunk@17968 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent bb6d379b
......@@ -21,6 +21,8 @@ class PrincipalMembershipsController < ApplicationController
layout 'admin'
self.main_menu = false
helper :members
before_action :require_admin
before_action :find_principal, :only => [:new, :create]
before_action :find_membership, :only => [:edit, :update, :destroy]
......
......@@ -37,4 +37,19 @@ module MembersHelper
s + content_tag('span', links, :class => 'pagination')
end
# Returns inheritance information for an inherited member role
def render_role_inheritance(member, role)
content = member.role_inheritance(role).map do |h|
if h.is_a?(Project)
l(:label_inherited_from_parent_project)
elsif h.is_a?(Group)
l(:label_inherited_from_group, :name => h.name.to_s)
end
end.compact.uniq
if content.present?
content_tag('span', content.join(", "), :class => "info")
end
end
end
......@@ -110,6 +110,16 @@ class Member < ActiveRecord::Base
member_roles.any? {|mr| mr.role_id == role.id && mr.inherited_from.present?}
end
# Returns an Array of Project and/or Group from which the given role
# was inherited, or an empty Array if the role was not inherited
def role_inheritance(role)
member_roles.
select {|mr| mr.role_id == role.id && mr.inherited_from.present?}.
map {|mr| mr.inherited_from_member_role.try(:member)}.
compact.
map {|m| m.project == project ? m.principal : m.project}
end
# Returns true if the member's role is editable by user
def role_editable?(role, user=User.current)
if has_inherited_role?(role)
......
......@@ -37,6 +37,11 @@ class MemberRole < ActiveRecord::Base
!inherited_from.nil?
end
# Returns the MemberRole from which self was inherited, or nil
def inherited_from_member_role
MemberRole.find_by_id(inherited_from) if inherited_from
end
# Destroys the MemberRole without destroying its Member if it doesn't have
# any other roles
def destroy_without_member_removal
......
......@@ -9,12 +9,13 @@
role.id, @member.roles.to_a.include?(role),
:id => nil,
:disabled => !@member.role_editable?(role)) %> <%= role %>
<%= render_role_inheritance(@member, role) %>
</label><br />
<% end %>
</p>
<%= hidden_field_tag 'membership[role_ids][]', '', :id => nil %>
<p>
<%= submit_tag l(:button_save), :class => "small" %>
<%= submit_tag l(:button_save) %>
<%= link_to_function l(:button_cancel),
"$('#member-#{@member.id}-roles').show(); $('#member-#{@member.id}-form').empty(); return false;" if request.xhr? %>
</p>
......
<%= form_for(:membership, :url => principal_membership_path(@principal, @membership),
<%= form_for(@membership, :url => principal_membership_path(@principal, @membership),
:as => :membership,
:remote => request.xhr?,
:method => :put) do %>
<p>
<% @roles.each do |role| %>
<label>
<%= check_box_tag 'membership[role_ids][]', role.id, @membership.roles.to_a.include?(role),
:disabled => !@membership.role_editable?(role),
:id => nil %> <%= role.name %>
<%= check_box_tag 'membership[role_ids][]',
role.id, @membership.roles.to_a.include?(role),
:id => nil,
:disabled => !@membership.role_editable?(role) %> <%= role.name %>
<%= render_role_inheritance(@membership, role) %>
</label><br />
<% end %>
</p>
......
......@@ -1041,6 +1041,8 @@ en:
label_font_proportional: Proportional font
label_last_notes: Last notes
label_nothing_to_preview: Nothing to preview
label_inherited_from_parent_project: "Inherited from parent project"
label_inherited_from_group: "Inherited from group %{name}"
button_login: Login
button_submit: Submit
......
......@@ -1252,7 +1252,8 @@ fr:
label_delete_link_to_subtask: "Supprimer la relation avec la sous-tâche"
error_not_allowed_to_log_time_for_other_users: "Vous n'êtes pas autorisé à saisir le temps passé pour d'autres utilisateurs"
permission_log_time_for_other_users: "Saisir le temps passé pour d'autres utilisateurs"
label_tomorrow: tomorrow
label_inherited_from_parent_project: "Hérité du projet parent"
label_inherited_from_group: "Hérité du groupe %{name}" label_tomorrow: tomorrow
label_next_week: next week
label_next_month: next month
text_role_no_workflow: No workflow defined for this role
......
......@@ -841,9 +841,12 @@ p.other-formats { text-align: right; font-size:0.9em; color: #666; }
a.atom { background: url(../images/feed.png) no-repeat 1px 50%; padding: 2px 0px 3px 16px; }
em.info {font-style:normal;font-size:90%;color:#888;display:block;}
.info {font-size:90%;color:#888;}
em.info {font-style:normal;display:block;}
em.info.error {padding-left:20px; background:url(../images/exclamation.png) no-repeat 0 50%;}
form.edit_membership p {margin:0.9em 0;}
textarea.text_cf {width:95%; resize:vertical;}
input.string_cf, input.link_cf {width:95%;}
select.bool_cf {width:auto !important;}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment