Class: ProjectMember

Inherits:
Member
  • Object
show all
Includes:
Gitlab::ShellAdapter
Defined in:
app/models/members/project_member.rb

Overview

Schema Information

Table name: members

id                 :integer          not null, primary key
access_level       :integer          not null
source_id          :integer          not null
source_type        :string           not null
user_id            :integer
notification_level :integer          not null
type               :string
created_at         :datetime
updated_at         :datetime
created_by_id      :integer
invite_email       :string
invite_token       :string
invite_accepted_at :datetime

Constant Summary collapse

SOURCE_TYPE =
'Project'

Constants included from Gitlab::Access

Gitlab::Access::DEVELOPER, Gitlab::Access::GUEST, Gitlab::Access::MASTER, Gitlab::Access::OWNER, Gitlab::Access::PROTECTION_DEV_CAN_PUSH, Gitlab::Access::PROTECTION_FULL, Gitlab::Access::PROTECTION_NONE, Gitlab::Access::REPORTER

Instance Attribute Summary

Attributes inherited from Member

#raw_invite_token

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::ShellAdapter

#gitlab_shell

Methods inherited from Member

#accept_invite!, add_user, #create_notification_setting, #decline_invite!, find_by_invite_token, #generate_invite_token, #generate_invite_token!, #invite?, #notification_setting, #resend_invite, user_for_id

Methods included from Gitlab::Access

all_values, #human_access, options, options_with_owner, protection_options, protection_values, sym_options, values

Class Method Details

.access_rolesObject


105
106
107
# File 'app/models/members/project_member.rb', line 105

def access_roles
  Gitlab::Access.options
end

.add_users_into_projects(project_ids, user_ids, access, current_user = nil) ⇒ Object

Add users to project teams with passed access option

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

Ex.

add_users_into_projects(
  project_ids,
  user_ids,
  ProjectMember::MASTER
)

add_users_into_projects(
  project_ids,
  user_ids,
  :master
)

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/models/members/project_member.rb', line 57

def add_users_into_projects(project_ids, user_ids, access, current_user = nil)
  access_level = if roles_hash.has_key?(access)
                   roles_hash[access]
                 elsif roles_hash.values.include?(access.to_i)
                   access
                 else
                   raise "Non valid access"
                 end

  users = user_ids.map { |user_id| Member.user_for_id(user_id) }

  ProjectMember.transaction do
    project_ids.each do |project_id|
      project = Project.find(project_id)

      users.each do |user|
        Member.add_user(project.project_members, user, access_level, current_user)
      end
    end
  end

  true
rescue
  false
end

.roles_hashObject


101
102
103
# File 'app/models/members/project_member.rb', line 101

def roles_hash
  Gitlab::Access.sym_options
end

.truncate_team(project) ⇒ Object


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

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

.truncate_teams(project_ids) ⇒ Object


83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/models/members/project_member.rb', line 83

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

#access_fieldObject


110
111
112
# File 'app/models/members/project_member.rb', line 110

def access_field
  access_level
end

#owner?Boolean


118
119
120
# File 'app/models/members/project_member.rb', line 118

def owner?
  project.owner == user
end

#projectObject


114
115
116
# File 'app/models/members/project_member.rb', line 114

def project
  source
end