scinote-web/app/permissions/team.rb

121 lines
3.6 KiB
Ruby
Raw Normal View History

2017-11-27 18:24:41 +08:00
Canaid::Permissions.register_for(Team) do
# view projects, view protocols
# leave team, view team users (ATWHO)
2017-12-12 21:56:07 +08:00
# view samples, export samples
# view repositories, view repository, export repository rows
2017-11-27 18:24:41 +08:00
can :read_team do |user, team|
user.is_member_of_team?(team)
end
# edit team name, edit team description
can :update_team do |user, team|
user.is_admin_of_team?(team)
end
# invite user to team, change user's role, remove user from team
2018-01-05 22:15:50 +08:00
can :manage_team_users do |user, team|
user.is_admin_of_team?(team)
end
2017-12-04 20:07:23 +08:00
2017-12-08 00:08:41 +08:00
# create project
2018-01-05 22:15:50 +08:00
can :create_projects do |user, team|
2017-12-08 00:08:41 +08:00
user.is_normal_user_or_admin_of_team?(team)
end
2017-12-04 20:07:23 +08:00
# create protocol in repository, import protocol to repository
2018-01-05 22:15:50 +08:00
can :create_protocols_in_repository do |user, team|
2017-12-04 20:07:23 +08:00
user.is_normal_user_or_admin_of_team?(team)
end
2017-12-04 23:45:23 +08:00
# create, import, edit, delete samples
can :manage_samples do |user, team|
2017-12-04 23:45:23 +08:00
user.is_normal_user_or_admin_of_team?(team)
end
# create custom field
# create, update, delete sample type or sample group
2018-01-05 22:15:50 +08:00
can :manage_sample_columns do |user, team|
user.is_normal_user_or_admin_of_team?(team)
end
# create, copy repository
2018-01-05 22:15:50 +08:00
can :create_repositories do |user, team|
2017-12-13 18:09:25 +08:00
user.is_admin_of_team?(team)
end
# create, import, edit, delete repository records
can :manage_repository_rows do |user, team|
user.is_normal_user_or_admin_of_team?(team)
end
# create repository column
2018-01-05 22:15:50 +08:00
can :create_repository_columns do |user, team|
user.is_normal_user_or_admin_of_team?(team)
end
end
Canaid::Permissions.register_for(Protocol) do
# view protocol in repository, export protocol from repository
# view step in protocol in repository, view or dowload step asset
can :read_protocol_in_repository do |user, protocol|
user.is_member_of_team?(protocol.team) &&
(protocol.in_repository_public? ||
protocol.in_repository_private? && user == protocol.added_by)
end
# edit protocol in repository,
# create, edit, delete or reorder step in repository
can :update_protocol_in_repository do |user, protocol|
protocol.in_repository_active? &&
can_update_protocol_type_in_repository?(user, protocol)
end
# toggle protocol visibility (public, private, archive, restore)
can :update_protocol_type_in_repository do |user, protocol|
user.is_normal_user_or_admin_of_team?(protocol.team) &&
user == protocol.added_by
end
2017-12-07 18:11:27 +08:00
# clone protocol in repository
2018-01-05 22:15:50 +08:00
can :clone_protocol_in_repository do |user, protocol|
can_create_protocols_in_repository?(user, protocol.team) &&
2017-12-07 18:11:27 +08:00
can_read_protocol_in_repository?(user, protocol)
end
end
Canaid::Permissions.register_for(Sample) do
# edit, delete specific sample
can :update_or_delete_sample do |user, sample|
can_manage_samples?(user, sample.team)
end
end
Canaid::Permissions.register_for(CustomField) do
# update, delete custom field
can :update_or_delete_custom_field do |user, custom_field|
2018-01-05 22:15:50 +08:00
can_manage_sample_columns?(user, custom_field.team)
end
end
Canaid::Permissions.register_for(Repository) do
# edit, destroy repository
can :update_or_delete_repository do |user, repository|
2018-01-05 22:15:50 +08:00
can_create_repositories?(user, repository.team)
end
end
Canaid::Permissions.register_for(RepositoryRow) do
# update, delete specific repository record
can :update_or_delete_repository_row do |user, repository_row|
can_manage_repository_rows?(user, repository_row.repository.team)
end
end
Canaid::Permissions.register_for(RepositoryColumn) do
# update, delete repository column
can :update_or_delete_repository_column do |user, repository_column|
2018-01-05 22:15:50 +08:00
can_create_repository_columns?(user, repository_column.repository.team)
end
end