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

38 lines
1 KiB
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
class GroupDeployKey < Key
self.table_name = 'group_deploy_keys'
2020-10-24 23:57:45 +05:30
has_many :group_deploy_keys_groups, inverse_of: :group_deploy_key, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :groups, through: :group_deploy_keys_groups
2020-06-23 00:09:42 +05:30
validates :user, presence: true
2020-11-24 15:15:51 +05:30
scope :for_groups, ->(group_ids) do
joins(:group_deploy_keys_groups).where(group_deploy_keys_groups: { group_id: group_ids }).uniq
end
2020-06-23 00:09:42 +05:30
def type
'DeployKey'
end
2020-10-24 23:57:45 +05:30
def group_deploy_keys_group_for(group)
group_deploy_keys_groups.find_by(group: group)
end
def can_be_edited_for?(user, group)
Ability.allowed?(user, :update_group_deploy_key, self) ||
Ability.allowed?(
user,
:update_group_deploy_key_for_group,
group_deploy_keys_group_for(group)
)
end
def group_deploy_keys_groups_for_user(user)
group_deploy_keys_groups.select do |group_deploy_keys_group|
Ability.allowed?(user, :read_group, group_deploy_keys_group.group)
end
end
2020-06-23 00:09:42 +05:30
end