2019-07-12 22:43:54 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-05-06 21:17:54 +08:00
|
|
|
Canaid::Permissions.register_for(RepositoryBase) do
|
2019-07-17 22:00:49 +08:00
|
|
|
# repository: read/export
|
|
|
|
can :read_repository do |user, repository|
|
2020-05-06 21:17:54 +08:00
|
|
|
if repository.is_a?(RepositorySnapshot)
|
2022-12-13 23:12:08 +08:00
|
|
|
can_read_my_module?(user, repository.my_module)
|
2020-05-06 21:17:54 +08:00
|
|
|
else
|
2022-12-20 20:26:38 +08:00
|
|
|
user.teams.include?(repository.team) || repository.shared_with?(user.current_team)
|
2020-05-06 21:17:54 +08:00
|
|
|
end
|
2019-07-17 22:00:49 +08:00
|
|
|
end
|
2020-05-06 21:17:54 +08:00
|
|
|
end
|
2019-07-17 22:00:49 +08:00
|
|
|
|
2020-05-06 21:17:54 +08:00
|
|
|
Canaid::Permissions.register_for(Repository) do
|
2020-05-15 23:46:59 +08:00
|
|
|
# Should be no provisioning snapshots for repository for all the specified permissions
|
|
|
|
%i(manage_repository
|
|
|
|
create_repository_rows
|
|
|
|
manage_repository_rows
|
|
|
|
delete_repository_rows
|
|
|
|
create_repository_columns)
|
|
|
|
.each do |perm|
|
|
|
|
can perm do |_, repository|
|
2022-06-07 00:21:57 +08:00
|
|
|
repository.active? && repository.repository_snapshots.provisioning.none?
|
2020-05-15 23:46:59 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-21 17:00:52 +08:00
|
|
|
%i(create_repository_rows
|
|
|
|
manage_repository_rows
|
|
|
|
manage_repository_assets
|
|
|
|
delete_repository_rows)
|
|
|
|
.each do |perm|
|
|
|
|
can perm do |user, repository|
|
2022-10-21 20:51:16 +08:00
|
|
|
repository.shared_with?(user.current_team) ? repository.shared_with_write?(user.current_team) : true
|
2022-10-21 17:00:52 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-12 22:43:54 +08:00
|
|
|
# repository: update, delete
|
|
|
|
can :manage_repository do |user, repository|
|
2022-05-19 19:46:03 +08:00
|
|
|
!repository.shared_with?(user.current_team) && repository.permission_granted?(user, RepositoryPermissions::MANAGE)
|
2019-07-12 22:43:54 +08:00
|
|
|
end
|
|
|
|
|
2020-06-24 17:32:20 +08:00
|
|
|
# repository: archive, restore
|
|
|
|
can :archive_repository do |user, repository|
|
2021-08-24 21:55:13 +08:00
|
|
|
next false if repository.is_a?(BmtRepository)
|
|
|
|
|
2022-05-19 19:46:03 +08:00
|
|
|
!repository.shared_with?(user.current_team) && repository.permission_granted?(user, RepositoryPermissions::MANAGE)
|
2020-06-24 17:32:20 +08:00
|
|
|
end
|
|
|
|
|
2022-02-28 17:33:43 +08:00
|
|
|
# repository: destroy
|
|
|
|
can :delete_repository do |user, repository|
|
2022-06-07 00:21:57 +08:00
|
|
|
repository.archived? && repository.permission_granted?(user, RepositoryPermissions::MANAGE)
|
2022-02-28 17:33:43 +08:00
|
|
|
end
|
|
|
|
|
2019-08-20 21:08:53 +08:00
|
|
|
# repository: share
|
|
|
|
can :share_repository do |user, repository|
|
2022-05-19 19:46:03 +08:00
|
|
|
can_manage_repository?(user, repository)
|
2019-08-20 21:08:53 +08:00
|
|
|
end
|
|
|
|
|
2020-04-21 20:49:36 +08:00
|
|
|
# repository: make a snapshot with assigned rows
|
|
|
|
can :create_repository_snapshot do |user, repository|
|
2022-05-19 19:46:03 +08:00
|
|
|
can_read_repository?(user, repository)
|
2020-04-21 20:49:36 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# repository: delete a snapshot with assigned rows
|
|
|
|
can :delete_repository_snapshot do |user, repository|
|
2022-05-19 19:46:03 +08:00
|
|
|
can_manage_repository?(user, repository)
|
2020-04-21 20:49:36 +08:00
|
|
|
end
|
|
|
|
|
2019-07-12 22:43:54 +08:00
|
|
|
# repository: create/import record
|
|
|
|
can :create_repository_rows do |user, repository|
|
2021-08-24 21:55:13 +08:00
|
|
|
next false if repository.is_a?(BmtRepository)
|
2022-03-30 20:33:26 +08:00
|
|
|
next false if repository.archived?
|
2021-08-24 21:55:13 +08:00
|
|
|
|
2022-10-21 17:00:52 +08:00
|
|
|
repository.permission_granted?(user, RepositoryPermissions::ROWS_CREATE)
|
2019-07-12 22:43:54 +08:00
|
|
|
end
|
|
|
|
|
2022-04-25 18:18:01 +08:00
|
|
|
can :manage_repository_assets do |user, repository|
|
2022-05-19 19:46:03 +08:00
|
|
|
repository.permission_granted?(user, RepositoryPermissions::ROWS_UPDATE)
|
2022-04-25 18:18:01 +08:00
|
|
|
end
|
|
|
|
|
2019-07-12 22:43:54 +08:00
|
|
|
# repository: update/delete records
|
|
|
|
can :manage_repository_rows do |user, repository|
|
2022-05-19 19:46:03 +08:00
|
|
|
repository.permission_granted?(user, RepositoryPermissions::ROWS_UPDATE)
|
2019-11-21 00:12:47 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
can :delete_repository_rows do |user, repository|
|
2022-05-19 19:46:03 +08:00
|
|
|
repository.permission_granted?(user, RepositoryPermissions::ROWS_DELETE)
|
2019-11-21 00:12:47 +08:00
|
|
|
end
|
|
|
|
|
2019-07-12 22:43:54 +08:00
|
|
|
# repository: create field
|
|
|
|
can :create_repository_columns do |user, repository|
|
2022-05-19 19:46:03 +08:00
|
|
|
!repository.shared_with?(user.current_team) &&
|
|
|
|
repository.permission_granted?(user, RepositoryPermissions::COLUMNS_CREATE)
|
2019-07-12 22:43:54 +08:00
|
|
|
end
|
2022-02-01 16:59:31 +08:00
|
|
|
|
|
|
|
# repository: create/update/delete filters
|
|
|
|
can :manage_repository_filters do |user, repository|
|
2022-05-19 19:46:03 +08:00
|
|
|
((repository.team == user.current_team) && can_manage_team?(user, repository.team)) ||
|
|
|
|
(repository.shared_with_write?(user.current_team) && can_manage_team?(user, user.current_team))
|
2022-02-01 16:59:31 +08:00
|
|
|
end
|
2022-03-29 18:33:28 +08:00
|
|
|
|
|
|
|
can :manage_repository_stock do |user, repository|
|
2022-04-01 19:54:08 +08:00
|
|
|
RepositoryBase.stock_management_enabled? && can_manage_repository_rows?(user, repository)
|
2022-03-29 18:33:28 +08:00
|
|
|
end
|
2019-07-12 22:43:54 +08:00
|
|
|
end
|