diff options
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/gitlab_routing_helper.rb | 77 | ||||
-rw-r--r-- | app/helpers/members_helper.rb | 126 | ||||
-rw-r--r-- | app/helpers/projects_helper.rb | 4 |
3 files changed, 92 insertions, 115 deletions
diff --git a/app/helpers/gitlab_routing_helper.rb b/app/helpers/gitlab_routing_helper.rb index 2ce2d4e694f..3a43e936aee 100644 --- a/app/helpers/gitlab_routing_helper.rb +++ b/app/helpers/gitlab_routing_helper.rb @@ -13,10 +13,23 @@ # merge_request_path(merge_request) # module GitlabRoutingHelper + # Project def project_path(project, *args) namespace_project_path(project.namespace, project, *args) end + def project_url(project, *args) + namespace_project_url(project.namespace, project, *args) + end + + def edit_project_path(project, *args) + edit_namespace_project_path(project.namespace, project, *args) + end + + def edit_project_url(project, *args) + edit_namespace_project_url(project.namespace, project, *args) + end + def project_files_path(project, *args) namespace_project_tree_path(project.namespace, project, @ref || project.repository.root_ref) end @@ -41,10 +54,6 @@ module GitlabRoutingHelper activity_namespace_project_path(project.namespace, project, *args) end - def edit_project_path(project, *args) - edit_namespace_project_path(project.namespace, project, *args) - end - def runners_path(project, *args) namespace_project_runners_path(project.namespace, project, *args) end @@ -65,14 +74,6 @@ module GitlabRoutingHelper namespace_project_milestone_path(entity.project.namespace, entity.project, entity, *args) end - def project_url(project, *args) - namespace_project_url(project.namespace, project, *args) - end - - def edit_project_url(project, *args) - edit_namespace_project_url(project.namespace, project, *args) - end - def issue_url(entity, *args) namespace_project_issue_url(entity.project.namespace, entity.project, entity, *args) end @@ -92,4 +93,56 @@ module GitlabRoutingHelper toggle_subscription_namespace_project_merge_request_path(entity.project.namespace, entity.project, entity) end end + + ## Members + def project_members_url(project, *args) + namespace_project_project_members_url(project.namespace, project) + end + + def project_member_path(project_member, *args) + namespace_project_project_member_path(project_member.source.namespace, project_member.source, project_member) + end + + def request_access_project_members_path(project, *args) + request_access_namespace_project_project_members_path(project.namespace, project) + end + + def leave_project_members_path(project, *args) + leave_namespace_project_project_members_path(project.namespace, project) + end + + def approve_access_request_project_member_path(project_member, *args) + approve_access_request_namespace_project_project_member_path(project_member.source.namespace, project_member.source, project_member) + end + + def resend_invite_project_member_path(project_member, *args) + resend_invite_namespace_project_project_member_path(project_member.source.namespace, project_member.source, project_member) + end + + # Groups + + ## Members + def group_members_url(group, *args) + group_group_members_url(group, *args) + end + + def group_member_path(group_member, *args) + group_group_member_path(group_member.source, group_member) + end + + def request_access_group_members_path(group, *args) + request_access_group_group_members_path(group) + end + + def leave_group_members_path(group, *args) + leave_group_group_members_path(group) + end + + def approve_access_request_group_member_path(group_member, *args) + approve_access_request_group_group_member_path(group_member.source, group_member) + end + + def resend_invite_group_member_path(group_member, *args) + resend_invite_group_group_member_path(group_member.source, group_member) + end end diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb index bd84b8b239f..a53828ef4e7 100644 --- a/app/helpers/members_helper.rb +++ b/app/helpers/members_helper.rb @@ -1,117 +1,45 @@ module MembersHelper - def member_class(member) - "#{member.source.class.to_s}Member".constantize - end - - def members_association(entity) - "#{entity.class.to_s.underscore}_members".to_sym - end - + # Returns a `<action>_<source>_member` association, e.g.: + # - admin_project_member, update_project_member, destroy_project_member + # - admin_group_member, update_group_member, destroy_group_member def action_member_permission(action, member) - "#{action}_#{member.source.class.to_s.underscore}_member".to_sym + "#{action}_#{member.type.underscore}".to_sym end - def can_see_entity_roles?(user, entity) + def can_see_member_roles?(source:, user: nil) return false unless user - user.is_admin? || entity.send(members_association(entity)).exists?(user_id: user.id) - end - - def member_path(member) - case member.source - when Project - namespace_project_project_member_path(member.source.namespace, member.source, member) - when Group - group_group_member_path(member.source, member) - else - raise ArgumentError.new('Unknown object class') - end + user.is_admin? || source.members.exists?(user_id: user.id) end - def resend_invite_member_path(member) - case member.source - when Project - resend_invite_namespace_project_project_member_path(member.source.namespace, member.source, member) - when Group - resend_invite_group_group_member_path(member.source, member) - else - raise ArgumentError.new('Unknown object class') - end - end + def remove_member_message(member, user: nil) + user = current_user if defined?(current_user) - def request_access_path(entity) - case entity - when Project - request_access_namespace_project_project_members_path(entity.namespace, entity) - when Group - request_access_group_group_members_path(entity) - else - raise ArgumentError.new('Unknown object class') - end - end - - def approve_request_member_path(member) - case member.source - when Project - approve_access_request_namespace_project_project_member_path(member.source.namespace, member.source, member) - when Group - approve_access_request_group_group_member_path(member.source, member) - else - raise ArgumentError.new('Unknown object class') - end - end + text = 'Are you sure you want to ' + action = + if member.request? + if member.user == user + 'withdraw your access request for' + else + "deny #{member.user.name}'s request to join" + end + elsif member.invite? + "revoke the invitation for #{member.invite_email} to join" + else + "remove #{member.user.name} from" + end - def leave_path(entity) - case entity - when Project - leave_namespace_project_project_members_path(entity.namespace, entity) - when Group - leave_group_group_members_path(entity) - else - raise ArgumentError.new('Unknown object class') - end - end - - def withdraw_request_message(entity) - "Are you sure you want to withdraw your access request for the \"#{entity_name(entity)}\" #{entity_type(entity)}?" - end - - def remove_member_message(member) - entity = member.source - entity_type = entity_type(entity) - entity_name = entity_name(entity) - - if member.request? - "You are going to deny #{member.created_by.name}'s request to join the #{entity_name} #{entity_type}. Are you sure?" - elsif member.invite? - "You are going to revoke the invitation for #{member.invite_email} to join the #{entity_name} #{entity_type}. Are you sure?" - else - "You are going to remove #{member.user.name} from the #{entity_name} #{entity_type}. Are you sure?" - end + text << action << " the #{member.source.human_name} #{member.real_source_type.humanize(capitalize: false)}?" end def remove_member_title(member) - member.request? ? 'Deny access request' : 'Remove user' - end - - def leave_confirmation_message(entity) - "Are you sure you want to leave \"#{entity_name(entity)}\" #{entity_type(entity)}?" - end - - private + text = " from #{member.real_source_type.humanize(capitalize: false)}" - def entity_type(entity) - entity.class.to_s.underscore + text.prepend(member.request? ? 'Deny access request' : 'Remove user') end - def entity_name(entity) - case entity - when Project - entity.name_with_namespace - when Group - entity.name - else - raise ArgumentError.new('Unknown object class') - end + def leave_confirmation_message(member_source) + "Are you sure you want to leave the " \ + "\"#{member_source.human_name}\" #{member_source.class.to_s.humanize(capitalize: false)}?" end end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 03941f87b13..d30dd66202b 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -1,8 +1,4 @@ module ProjectsHelper - def max_access_level(project, user) - Gitlab::Access.options_with_owner.key(project.team.max_member_access(user.id)) - end - def link_to_project(project) link_to [project.namespace.becomes(Namespace), project], title: h(project.name) do title = content_tag(:span, project.name, class: 'project-name') |