summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Kozono <mkozono@gmail.com>2017-09-05 23:49:57 -0700
committerMichael Kozono <mkozono@gmail.com>2017-09-06 12:07:21 -0700
commitf03b90c6a370e15ed21f82df1501d5fc58b0f4ec (patch)
tree0a2f8f2967dad9fc89b216ab3a4b877b3fd96af6
parent5404dbb49d4064f7ff3b74ea229edb43f01fd699 (diff)
downloadgitlab-ce-f03b90c6a370e15ed21f82df1501d5fc58b0f4ec.tar.gz
Link or not link depending on permissions
-rw-r--r--app/helpers/groups_helper.rb24
-rw-r--r--spec/helpers/groups_helper_spec.rb16
2 files changed, 29 insertions, 11 deletions
diff --git a/app/helpers/groups_helper.rb b/app/helpers/groups_helper.rb
index f7e6eb350cd..970cff835ec 100644
--- a/app/helpers/groups_helper.rb
+++ b/app/helpers/groups_helper.rb
@@ -99,15 +99,23 @@ module GroupsHelper
end
end
- def ancestor_group_link(group)
+ def ancestor_group(group)
ancestor = oldest_consecutively_locked_ancestor(group)
- link_to ancestor.name, group_path(ancestor)
+ if can?(current_user, :read_group, ancestor)
+ link_to ancestor.name, group_path(ancestor)
+ else
+ ancestor.name
+ end
end
- def remove_the_share_lock_from_ancestor_link(group)
+ def remove_the_share_lock_from_ancestor(group)
ancestor = oldest_consecutively_locked_ancestor(group)
- link_text = s_("GroupSettings|remove the share lock from %{ancestor_group_name}") % { ancestor_group_name: ancestor.name }
- link_to link_text, edit_group_path(ancestor)
+ text = s_("GroupSettings|remove the share lock from %{ancestor_group_name}") % { ancestor_group_name: ancestor.name }
+ if can?(current_user, :admin_group, ancestor)
+ link_to text, edit_group_path(ancestor)
+ else
+ text
+ end
end
def oldest_consecutively_locked_ancestor(group)
@@ -121,14 +129,14 @@ module GroupsHelper
end
def ancestor_locked_but_you_can_override(group)
- s_("GroupSettings|This setting is applied on %{ancestor_group}. You can override the setting or %{remove_ancestor_share_lock}.") % { ancestor_group: ancestor_group_link(group), remove_ancestor_share_lock: remove_the_share_lock_from_ancestor_link(group) }
+ s_("GroupSettings|This setting is applied on %{ancestor_group}. You can override the setting or %{remove_ancestor_share_lock}.") % { ancestor_group: ancestor_group(group), remove_ancestor_share_lock: remove_the_share_lock_from_ancestor(group) }
end
def ancestor_locked_so_ask_the_owner(group)
- s_("GroupSettings|This setting is applied on %{ancestor_group}. To share projects in this group with another group, ask the owner to override the setting or remove the share lock from %{ancestor_group}.") % { ancestor_group: ancestor_group_link(group) }
+ s_("GroupSettings|This setting is applied on %{ancestor_group}. To share projects in this group with another group, ask the owner to override the setting or %{remove_ancestor_share_lock}.") % { ancestor_group: ancestor_group(group), remove_ancestor_share_lock: remove_the_share_lock_from_ancestor(group) }
end
def ancestor_locked_and_has_been_overridden(group)
- s_("GroupSettings|This setting is applied on %{ancestor_group} and has been overridden on this subgroup.") % { ancestor_group: ancestor_group_link(group) }
+ s_("GroupSettings|This setting is applied on %{ancestor_group} and has been overridden on this subgroup.") % { ancestor_group: ancestor_group(group) }
end
end
diff --git a/spec/helpers/groups_helper_spec.rb b/spec/helpers/groups_helper_spec.rb
index edfa3d9ae5a..7c5d954763c 100644
--- a/spec/helpers/groups_helper_spec.rb
+++ b/spec/helpers/groups_helper_spec.rb
@@ -107,9 +107,9 @@ describe GroupsHelper do
let(:possible_help_texts) do
{
default_help: "This setting will be applied to all subgroups unless overridden by a group owner",
- ancestor_locked_but_you_can_override: /This setting is applied on <a .+>.+<\/a>\. You can override the setting or <a .+>remove the share lock from .+<\/a>/,
- ancestor_locked_so_ask_the_owner: /This setting is applied on <a .+>.+<\/a>\. To share projects in this group with another group, ask the owner to override the setting or remove the share lock from <a .+>.+<\/a>/,
- ancestor_locked_and_has_been_overridden: /This setting is applied on <a .+>.+<\/a> and has been overridden on this subgroup/
+ ancestor_locked_but_you_can_override: /This setting is applied on <a .+>.+<\/a>\. You can override the setting or .+/,
+ ancestor_locked_so_ask_the_owner: /This setting is applied on .+\. To share projects in this group with another group, ask the owner to override the setting or remove the share lock from .+/,
+ ancestor_locked_and_has_been_overridden: /This setting is applied on .+ and has been overridden on this subgroup/
}
end
let(:possible_linked_ancestors) do
@@ -170,6 +170,16 @@ describe GroupsHelper do
allow(helper).to receive(:can?)
.with(users[current_user], :change_share_with_group_lock, subgroup)
.and_return(Ability.allowed?(users[current_user], :change_share_with_group_lock, subgroup))
+
+ ancestor = possible_linked_ancestors[linked_ancestor]
+ if ancestor
+ allow(helper).to receive(:can?)
+ .with(users[current_user], :read_group, ancestor)
+ .and_return(Ability.allowed?(users[current_user], :read_group, ancestor))
+ allow(helper).to receive(:can?)
+ .with(users[current_user], :admin_group, ancestor)
+ .and_return(Ability.allowed?(users[current_user], :admin_group, ancestor))
+ end
end
it 'has the correct help text with correct ancestor links' do