2019-07-12 22:43:54 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
Canaid::Permissions.register_for(Repository) do
|
2019-07-17 22:00:49 +08:00
|
|
|
# repository: read/export
|
|
|
|
can :read_repository do |user, repository|
|
2019-08-23 16:57:02 +08:00
|
|
|
user.teams.include?(repository.team) || repository.shared_with?(user.current_team)
|
2019-07-17 22:00:49 +08:00
|
|
|
end
|
|
|
|
|
2019-07-12 22:43:54 +08:00
|
|
|
# repository: update, delete
|
|
|
|
can :manage_repository do |user, repository|
|
2019-08-23 16:57:02 +08:00
|
|
|
user.is_admin_of_team?(repository.team) unless repository.shared_with?(user.current_team)
|
2019-07-12 22:43:54 +08:00
|
|
|
end
|
|
|
|
|
2019-08-20 21:08:53 +08:00
|
|
|
# repository: share
|
|
|
|
can :share_repository do |user, repository|
|
2019-08-23 16:57:02 +08:00
|
|
|
user.is_admin_of_team?(repository.team) unless repository.shared_with?(user.current_team)
|
2019-08-20 21:08:53 +08:00
|
|
|
end
|
|
|
|
|
2019-07-12 22:43:54 +08:00
|
|
|
# repository: create/import record
|
|
|
|
can :create_repository_rows do |user, repository|
|
2019-08-23 16:57:02 +08:00
|
|
|
if repository.shared_with?(user.current_team)
|
|
|
|
repository.shared_with_write?(user.current_team) && user.is_normal_user_or_admin_of_team?(user.current_team)
|
|
|
|
elsif user.teams.include?(repository.team)
|
2019-07-12 22:43:54 +08:00
|
|
|
user.is_normal_user_or_admin_of_team?(repository.team)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# repository: update/delete records
|
|
|
|
can :manage_repository_rows do |user, repository|
|
|
|
|
can_create_repository_rows?(user, repository)
|
|
|
|
end
|
|
|
|
|
2019-11-21 00:12:47 +08:00
|
|
|
can :update_repository_rows do |user, repository|
|
|
|
|
can_manage_repository_rows?(user, repository)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :delete_repository_rows do |user, repository|
|
|
|
|
can_manage_repository_rows?(user, repository)
|
|
|
|
end
|
|
|
|
|
2019-07-12 22:43:54 +08:00
|
|
|
# repository: create field
|
|
|
|
can :create_repository_columns do |user, repository|
|
2019-08-23 16:57:02 +08:00
|
|
|
can_create_repository_rows?(user, repository) unless repository.shared_with?(user.current_team)
|
2019-07-12 22:43:54 +08:00
|
|
|
end
|
|
|
|
end
|