summaryrefslogtreecommitdiff
path: root/app/presenters/member_presenter.rb
blob: 0c67fc98ced6b4f62033cab7489cb5d47fca12da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true

class MemberPresenter < Gitlab::View::Presenter::Delegated
  presents :member

  def access_level_roles
    member.class.access_level_roles
  end

  def valid_level_roles
    return access_level_roles unless member.highest_group_member

    access_level_roles.reject do |_name, level|
      member.highest_group_member.access_level > level
    end
  end

  def can_resend_invite?
    invite? &&
      can?(current_user, admin_member_permission, source)
  end

  def can_update?
    can?(current_user, update_member_permission, member)
  end

  def can_remove?
    can?(current_user, destroy_member_permission, member)
  end

  def can_approve?
    request? && can_update?
  end

  # This functionality is only available in EE.
  def can_override?
    false
  end

  private

  def admin_member_permission
    raise NotImplementedError
  end

  def update_member_permission
    raise NotImplementedError
  end

  def destroy_member_permission
    raise NotImplementedError
  end
end

MemberPresenter.prepend_if_ee('EE::MemberPresenter')