2015-03-17 23:06:03 +00:00
|
|
|
class RepositoryPolicy < ApplicationPolicy
|
|
|
|
|
2015-03-18 22:02:38 +00:00
|
|
|
def show?
|
2015-04-13 22:06:29 +01:00
|
|
|
is_admin? || 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?
|
2015-04-01 22:34:14 +01:00
|
|
|
is_admin? || local_reader?(record.platform)
|
2015-03-17 23:06:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def write?
|
2015-04-01 22:34:14 +01:00
|
|
|
is_admin? || local_writer?(record.platform)
|
2015-03-17 23:06:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update?
|
2015-04-01 22:34:14 +01:00
|
|
|
is_admin? || local_admin?(record.platform)
|
2015-03-17 23:06:03 +00:00
|
|
|
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?
|
2015-04-01 22:34:14 +01:00
|
|
|
return false if record.platform.personal? && record.name == 'main'
|
|
|
|
is_admin? || owner?(record.platform) || local_admin?(record.platform)
|
2015-03-18 22:02:38 +00:00
|
|
|
end
|
|
|
|
alias_method :destroy?, :create?
|
|
|
|
|
|
|
|
def packages?
|
2015-04-01 22:34:14 +01:00
|
|
|
record.platform.main? && ( is_admin? || local_admin?(record.platform) )
|
2015-03-18 22:02:38 +00:00
|
|
|
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
|
|
|
|
2016-05-22 13:25:00 +01:00
|
|
|
def manage_projects?
|
2015-04-01 22:34:14 +01:00
|
|
|
is_admin? || local_admin?(record.platform) || repository_user_ids.include?(user.id)
|
2015-03-17 23:06:03 +00:00
|
|
|
end
|
2016-05-22 13:25:00 +01:00
|
|
|
alias_method :add_project?, :manage_projects?
|
|
|
|
alias_method :remove_project?, :manage_projects?
|
2015-03-17 23:06:03 +00:00
|
|
|
|
2015-04-01 22:34:14 +01:00
|
|
|
def settings?
|
|
|
|
is_admin? || owner?(record.platform) || local_admin?(record.platform)
|
2015-03-18 22:02:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def key_pair?
|
|
|
|
user.system?
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_repo_lock_file?
|
2015-04-01 22:34:14 +01:00
|
|
|
is_admin? || user.system? || ( record.platform.main? && local_admin?(record.platform) )
|
2015-03-18 22:02:38 +00:00
|
|
|
end
|
|
|
|
alias_method :remove_repo_lock_file?, :add_repo_lock_file?
|
|
|
|
|
2015-05-20 20:54:38 +01:00
|
|
|
# Public: Get list of parameters that the user is allowed to alter.
|
|
|
|
#
|
|
|
|
# Returns Array
|
|
|
|
def permitted_attributes
|
|
|
|
%i(
|
|
|
|
name
|
|
|
|
description
|
|
|
|
publish_without_qa
|
|
|
|
synchronizing_publications
|
|
|
|
publish_builds_only_from_branch
|
|
|
|
build_for_platform_id
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
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
|