debian-mirror-gitlab/app/models/project_group_link.rb

52 lines
1.2 KiB
Ruby
Raw Normal View History

2016-06-02 11:05:42 +05:30
class ProjectGroupLink < ActiveRecord::Base
2016-09-13 17:45:13 +05:30
include Expirable
2016-06-02 11:05:42 +05:30
GUEST = 10
REPORTER = 20
DEVELOPER = 30
MASTER = 40
belongs_to :project
belongs_to :group
validates :project_id, presence: true
2016-11-03 12:29:30 +05:30
validates :group, presence: true
2016-06-02 11:05:42 +05:30
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
2017-08-17 22:00:37 +05:30
after_commit :refresh_group_members_authorized_projects
2016-06-02 11:05:42 +05:30
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-09-13 17:45:13 +05:30
private
2016-06-02 11:05:42 +05:30
def different_group
2017-08-17 22:00:37 +05:30
return unless self.group && self.project
project_group = self.project.group
return unless project_group
group_ids = project_group.ancestors.map(&:id).push(project_group.id)
if group_ids.include?(self.group.id)
errors.add(:base, "Project cannot be shared with the group it is in or one of its ancestors.")
2016-06-02 11:05:42 +05:30
end
end
2017-08-17 22:00:37 +05:30
def refresh_group_members_authorized_projects
group.refresh_members_authorized_projects
end
2016-06-02 11:05:42 +05:30
end