2016-03-11 11:47:05 -05:00
|
|
|
class ProjectGroupLink < ActiveRecord::Base
|
2016-08-18 17:45:41 -04:00
|
|
|
include Expirable
|
|
|
|
|
2016-03-11 11:47:05 -05:00
|
|
|
GUEST = 10
|
|
|
|
REPORTER = 20
|
|
|
|
DEVELOPER = 30
|
|
|
|
MASTER = 40
|
|
|
|
|
|
|
|
belongs_to :project
|
|
|
|
belongs_to :group
|
|
|
|
|
|
|
|
validates :project_id, presence: true
|
2016-10-11 06:20:35 -04:00
|
|
|
validates :group, presence: true
|
2016-03-11 11:47:05 -05:00
|
|
|
validates :group_id, uniqueness: { scope: [:project_id], message: "already shared with this group" }
|
|
|
|
validates :group_access, presence: true
|
|
|
|
validates :group_access, inclusion: { in: Gitlab::Access.values }, presence: true
|
|
|
|
validate :different_group
|
|
|
|
|
2016-10-11 08:25:17 -04:00
|
|
|
after_create :refresh_group_members_authorized_projects
|
|
|
|
after_destroy :refresh_group_members_authorized_projects
|
|
|
|
|
2016-03-11 11:47:05 -05:00
|
|
|
def self.access_options
|
|
|
|
Gitlab::Access.options
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.default_access
|
|
|
|
DEVELOPER
|
|
|
|
end
|
|
|
|
|
|
|
|
def human_access
|
|
|
|
self.class.access_options.key(self.group_access)
|
|
|
|
end
|
|
|
|
|
2016-08-18 17:45:41 -04:00
|
|
|
private
|
2016-03-11 11:47:05 -05:00
|
|
|
|
|
|
|
def different_group
|
|
|
|
if self.group && self.project && self.project.group == self.group
|
|
|
|
errors.add(:base, "Project cannot be shared with the project it is in.")
|
|
|
|
end
|
|
|
|
end
|
2016-10-11 08:25:17 -04:00
|
|
|
|
|
|
|
def refresh_group_members_authorized_projects
|
|
|
|
group.refresh_members_authorized_projects
|
|
|
|
end
|
2016-03-11 11:47:05 -05:00
|
|
|
end
|