Class: ProjectMember

Inherits:
Member show all
Defined in:
app/models/members/project_member.rb

Constant Summary collapse

SOURCE_TYPE =
'Project'

Constants included from UpdateHighestRole

UpdateHighestRole::HIGHEST_ROLE_JOB_DELAY, UpdateHighestRole::HIGHEST_ROLE_LEASE_TIMEOUT

Constants included from Gitlab::Access

Gitlab::Access::AccessDeniedError, Gitlab::Access::DEVELOPER, Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS, Gitlab::Access::GUEST, Gitlab::Access::MAINTAINER, Gitlab::Access::MAINTAINER_PROJECT_ACCESS, Gitlab::Access::MAINTAINER_SUBGROUP_ACCESS, Gitlab::Access::MINIMAL_ACCESS, Gitlab::Access::NO_ACCESS, Gitlab::Access::NO_ONE_PROJECT_ACCESS, Gitlab::Access::OWNER, Gitlab::Access::OWNER_SUBGROUP_ACCESS, Gitlab::Access::PROTECTION_DEV_CAN_MERGE, Gitlab::Access::PROTECTION_DEV_CAN_PUSH, Gitlab::Access::PROTECTION_FULL, Gitlab::Access::PROTECTION_NONE, Gitlab::Access::REPORTER

Constants included from Expirable

Expirable::DAYS_TO_EXPIRE

Instance Attribute Summary

Attributes inherited from Member

#raw_invite_token

Attributes included from Importable

#imported, #importing

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Member

#accept_invite!, #accept_request, #access_field, access_for_user_ids, access_levels, add_user, add_users, #create_notification_setting, #decline_invite!, #destroy_notification_setting, filter_by_2fa, find_by_invite_token, #generate_invite_token, #generate_invite_token!, #highest_group_member, #invite?, #invite_to_unknown_user?, left_join_users, #notifiable?, #notification_setting, #pending?, #real_source_type, #request?, #resend_invite, search, search_invite_email, set_member_attributes, sort_by_attribute

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods included from Presentable

#present

Methods included from Gitlab::Access

all_values, #human_access, human_access, human_access_with_none, #human_access_with_none, options, options_with_none, options_with_owner, project_creation_level_name, project_creation_options, project_creation_string_options, project_creation_string_values, project_creation_values, protection_options, protection_values, subgroup_creation_options, subgroup_creation_string_options, subgroup_creation_string_values, subgroup_creation_values, sym_options, sym_options_with_owner

Methods included from Expirable

#expired?, #expires?, #expires_soon?

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Class Method Details

.access_level_rolesObject


78
79
80
# File 'app/models/members/project_member.rb', line 78

def access_level_roles
  Gitlab::Access.options
end

.add_users_to_projects(project_ids, users, access_level, current_user: nil, expires_at: nil) ⇒ Object

Add users to projects with passed access option

access can be an integer representing a access code or symbol like :maintainer representing role

Ex.

add_users_to_projects(
  project_ids,
  user_ids,
  ProjectMember::MAINTAINER
)

add_users_to_projects(
  project_ids,
  user_ids,
  :maintainer
)

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/members/project_member.rb', line 44

def add_users_to_projects(project_ids, users, access_level, current_user: nil, expires_at: nil)
  self.transaction do
    project_ids.each do |project_id|
      project = Project.find(project_id)

      add_users(
        project,
        users,
        access_level,
        current_user: current_user,
        expires_at: expires_at
      )
    end
  end
end

.truncate_team(project) ⇒ Object


74
75
76
# File 'app/models/members/project_member.rb', line 74

def truncate_team(project)
  truncate_teams [project.id]
end

.truncate_teams(project_ids) ⇒ Object


60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/members/project_member.rb', line 60

def truncate_teams(project_ids)
  ProjectMember.transaction do
    members = ProjectMember.where(source_id: project_ids)

    members.each do |member|
      member.destroy
    end
  end

  true
rescue
  false
end

Instance Method Details

#notifiable_optionsObject


97
98
99
# File 'app/models/members/project_member.rb', line 97

def notifiable_options
  { project: project }
end

#owner?Boolean

Returns:

  • (Boolean)

93
94
95
# File 'app/models/members/project_member.rb', line 93

def owner?
  project.owner == user
end

#projectObject


89
90
91
# File 'app/models/members/project_member.rb', line 89

def project
  source
end