2018-01-20 01:25:58 +08:00
|
|
|
Canaid::Permissions.register_for(Project) do
|
2018-03-04 21:19:17 +08:00
|
|
|
# Project must be active for all the specified permissions
|
|
|
|
%i(read_project
|
|
|
|
manage_project
|
|
|
|
archive_project
|
|
|
|
create_experiments
|
|
|
|
create_comments_in_project
|
2018-04-18 22:47:52 +08:00
|
|
|
manage_tags)
|
2018-03-04 21:19:17 +08:00
|
|
|
.each do |perm|
|
|
|
|
can perm do |_, project|
|
|
|
|
project.active?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-12 20:21:36 +08:00
|
|
|
# project: read, read activities, read comments, read users, read archive,
|
|
|
|
# read notifications
|
|
|
|
# reports: read
|
2018-01-20 01:25:58 +08:00
|
|
|
can :read_project do |user, project|
|
2018-02-03 01:19:03 +08:00
|
|
|
user.is_member_of_project?(project) ||
|
2018-01-20 01:25:58 +08:00
|
|
|
user.is_admin_of_team?(project.team) ||
|
|
|
|
(project.visible? && user.is_member_of_team?(project.team))
|
|
|
|
end
|
|
|
|
|
2018-02-19 21:47:36 +08:00
|
|
|
# project: update/delete, assign/reassign/unassign users
|
2018-02-03 01:48:55 +08:00
|
|
|
can :manage_project do |user, project|
|
2018-01-20 01:25:58 +08:00
|
|
|
user.is_owner_of_project?(project)
|
|
|
|
end
|
|
|
|
|
2018-02-03 04:07:24 +08:00
|
|
|
# project: archive
|
|
|
|
can :archive_project do |user, project|
|
|
|
|
can_manage_project?(user, project)
|
|
|
|
end
|
|
|
|
|
2018-02-19 21:47:36 +08:00
|
|
|
# NOTE: Must not be dependent on canaid parmision for which we check if it's
|
|
|
|
# active
|
2018-02-03 03:04:19 +08:00
|
|
|
# project: restore
|
2018-01-20 01:25:58 +08:00
|
|
|
can :restore_project do |user, project|
|
2018-02-19 21:47:36 +08:00
|
|
|
user.is_owner_of_project?(project) && project.archived?
|
2018-01-20 01:25:58 +08:00
|
|
|
end
|
|
|
|
|
2018-02-03 03:04:19 +08:00
|
|
|
# experiment: create
|
2018-02-16 01:46:29 +08:00
|
|
|
can :create_experiments do |user, project|
|
2018-01-20 01:25:58 +08:00
|
|
|
user.is_user_or_higher_of_project?(project)
|
|
|
|
end
|
|
|
|
|
2018-02-03 03:04:19 +08:00
|
|
|
# project: create comment
|
2018-02-16 01:46:29 +08:00
|
|
|
can :create_comments_in_project do |user, project|
|
2018-01-20 01:25:58 +08:00
|
|
|
user.is_technician_or_higher_of_project?(project)
|
|
|
|
end
|
|
|
|
|
2018-02-12 20:21:36 +08:00
|
|
|
# project: create/update/delete tag
|
|
|
|
# module: assign/reassign/unassign tag
|
2018-02-16 01:46:29 +08:00
|
|
|
can :manage_tags do |user, project|
|
2018-01-20 01:25:58 +08:00
|
|
|
user.is_user_or_higher_of_project?(project)
|
|
|
|
end
|
2018-03-04 21:19:17 +08:00
|
|
|
end
|
2018-02-03 01:19:03 +08:00
|
|
|
|
2018-03-04 21:19:17 +08:00
|
|
|
Canaid::Permissions.register_for(ProjectComment) do
|
2018-02-14 00:10:59 +08:00
|
|
|
# Project must be active for all the specified permissions
|
2018-03-04 21:19:17 +08:00
|
|
|
%i(manage_comment_in_project)
|
2018-02-03 01:19:03 +08:00
|
|
|
.each do |perm|
|
2018-03-04 21:19:17 +08:00
|
|
|
can perm do |_, project_comment|
|
|
|
|
project_comment.project.active?
|
2018-02-03 01:19:03 +08:00
|
|
|
end
|
|
|
|
end
|
2018-01-20 01:25:58 +08:00
|
|
|
|
2018-02-12 20:21:36 +08:00
|
|
|
# project: update/delete comment
|
2018-02-19 21:47:36 +08:00
|
|
|
can :manage_comment_in_project do |user, project_comment|
|
|
|
|
project_comment.project.present? && (project_comment.user == user ||
|
2018-03-04 21:49:28 +08:00
|
|
|
user.is_owner_of_project?(project_comment.project))
|
2018-01-20 01:25:58 +08:00
|
|
|
end
|
|
|
|
end
|