BigW Consortium Gitlab

members_helper.rb 1.47 KB
Newer Older
1
module MembersHelper
2 3 4
  # 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
5
  def action_member_permission(action, member)
6
    "#{action}_#{member.type.underscore}".to_sym
7 8
  end

9 10
  def remove_member_message(member, user: nil)
    user = current_user if defined?(current_user)
11

12 13
    text = 'Are you sure you want to '
    action =
14 15 16
      if member.request?
        if member.user == user
          'withdraw your access request for'
17
        else
18
          "deny #{member.user.name}'s request to join"
19
        end
20 21 22 23 24
      elsif member.invite?
        "revoke the invitation for #{member.invite_email} to join"
      else
        "remove #{member.user.name} from"
      end
25

26
    text << action << " the #{member.source.human_name} #{member.real_source_type.humanize(capitalize: false)}?"
27 28 29
  end

  def remove_member_title(member)
30
    text = " from #{member.real_source_type.humanize(capitalize: false)}"
31

32
    text.prepend(member.request? ? 'Deny access request' : 'Remove user')
33 34
  end

35 36 37
  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)}?"
38
  end
39 40

  def filter_group_project_member_path(options = {})
41
    options = params.slice(:search, :sort).merge(options)
42 43 44 45 46

    path = request.path
    path << "?#{options.to_param}"
    path
  end
47
end