2015-03-17 23:06:03 +00:00
|
|
|
class RepositoryPolicy < ApplicationPolicy
|
|
|
|
|
2015-03-18 22:02:38 +00:00
|
|
|
def show?
|
2015-03-25 00:17:17 +00:00
|
|
|
PlatformPolicy.new(user, record.platform).show?
|
2015-03-17 23:06:03 +00:00
|
|
|
end
|
2015-03-18 22:02:38 +00:00
|
|
|
alias_method :projects?, :show?
|
|
|
|
alias_method :projects_list?, :show?
|
|
|
|
alias_method :read?, :show?
|
2015-03-17 23:06:03 +00:00
|
|
|
|
|
|
|
def reader?
|
|
|
|
local_reader?(record.platform)
|
|
|
|
end
|
|
|
|
|
|
|
|
def write?
|
|
|
|
local_writer?(record.platform)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update?
|
|
|
|
local_admin?(record.platform)
|
|
|
|
end
|
2015-03-18 22:02:38 +00:00
|
|
|
alias_method :manage_members?, :update?
|
|
|
|
alias_method :regenerate_metadata?, :update?
|
|
|
|
alias_method :signatures?, :update?
|
|
|
|
|
|
|
|
def create?
|
|
|
|
return false if record.platform.personal? && name == 'main'
|
|
|
|
local_admin?(record.platform)
|
|
|
|
end
|
|
|
|
alias_method :destroy?, :create?
|
|
|
|
|
|
|
|
def packages?
|
|
|
|
record.platform.main? && local_admin?(record.platform)
|
|
|
|
end
|
|
|
|
alias_method :remove_member?, :packages?
|
|
|
|
alias_method :remove_members?, :packages?
|
|
|
|
alias_method :add_member?, :packages?
|
|
|
|
alias_method :sync_lock_file?, :packages?
|
2015-03-17 23:06:03 +00:00
|
|
|
|
|
|
|
def add_project?
|
2015-03-18 22:02:38 +00:00
|
|
|
local_admin?(record.platform) || repository_user_ids.include?(user.id)
|
2015-03-17 23:06:03 +00:00
|
|
|
end
|
|
|
|
alias_method :remove_project?, :add_project?
|
|
|
|
|
2015-03-18 22:02:38 +00:00
|
|
|
def destroy?
|
|
|
|
owner?(record.platform)
|
|
|
|
end
|
|
|
|
alias_method :settings?, :destroy?
|
|
|
|
|
|
|
|
def key_pair?
|
|
|
|
user.system?
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_repo_lock_file?
|
|
|
|
user.system? || ( record.platform.main? && local_admin?(record.platform) )
|
|
|
|
end
|
|
|
|
alias_method :remove_repo_lock_file?, :add_repo_lock_file?
|
|
|
|
|
2015-03-17 23:06:03 +00:00
|
|
|
private
|
|
|
|
|
2015-03-18 22:02:38 +00:00
|
|
|
# Public: Get user ids of repository.
|
|
|
|
#
|
|
|
|
# Returns the Set of user ids.
|
|
|
|
def repository_user_ids
|
|
|
|
Rails.cache.fetch(['RepositoryPolicy#repository_user_ids', record]) do
|
|
|
|
Set.new record.member_ids
|
2015-03-17 23:06:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|