2016-02-12 23:52:43 +08:00
|
|
|
require "aspector"
|
|
|
|
|
|
|
|
module PermissionHelper
|
|
|
|
|
|
|
|
#######################################################
|
|
|
|
# SOME REFLECTION MAGIC
|
|
|
|
#######################################################
|
|
|
|
aspector do
|
2017-01-25 19:30:11 +08:00
|
|
|
# ---- TEAM ROLES DEFINITIONS ----
|
2016-02-12 23:52:43 +08:00
|
|
|
around [
|
2017-01-25 16:48:49 +08:00
|
|
|
:is_member_of_team,
|
|
|
|
:is_admin_of_team,
|
|
|
|
:is_normal_user_of_team,
|
|
|
|
:is_normal_user_or_admin_of_team,
|
|
|
|
:is_guest_of_team
|
2016-02-12 23:52:43 +08:00
|
|
|
] do |proxy, *args, &block|
|
|
|
|
if args[0]
|
2017-01-25 16:48:49 +08:00
|
|
|
@user_team = current_user.user_teams.where(team: args[0]).take
|
|
|
|
@user_team ? proxy.call(*args, &block) : false
|
2016-02-12 23:52:43 +08:00
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# ---- PROJECT ROLES DEFINITIONS ----
|
|
|
|
around [
|
|
|
|
:is_member_of_project,
|
|
|
|
:is_owner_of_project,
|
|
|
|
:is_user_of_project,
|
|
|
|
:is_user_or_higher_of_project,
|
|
|
|
:is_technician_of_project,
|
|
|
|
:is_technician_or_higher_of_project,
|
|
|
|
:is_viewer_of_project
|
|
|
|
] do |proxy, *args, &block|
|
|
|
|
if args[0]
|
|
|
|
@user_project = current_user.user_projects.where(project: args[0]).take
|
|
|
|
@user_project ? proxy.call(*args, &block) : false
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# ---- Almost everything is disabled for archived projects ----
|
|
|
|
around [
|
|
|
|
:can_view_project,
|
|
|
|
:can_view_project_activities,
|
|
|
|
:can_view_project_users,
|
|
|
|
:can_view_project_notifications,
|
|
|
|
:can_view_project_comments,
|
|
|
|
:can_edit_project,
|
|
|
|
:can_archive_project,
|
|
|
|
:can_add_user_to_project,
|
|
|
|
:can_remove_user_from_project,
|
|
|
|
:can_edit_users_on_project,
|
|
|
|
:can_add_comment_to_project,
|
|
|
|
:can_restore_archived_modules,
|
|
|
|
:can_view_project_samples,
|
|
|
|
:can_view_project_archive,
|
|
|
|
:can_create_new_tag,
|
|
|
|
:can_edit_tag,
|
|
|
|
:can_delete_tag,
|
|
|
|
:can_edit_canvas,
|
|
|
|
:can_reposition_modules,
|
|
|
|
:can_edit_connections,
|
|
|
|
:can_create_modules,
|
|
|
|
:can_edit_modules,
|
|
|
|
:can_clone_modules,
|
|
|
|
:can_archive_modules,
|
|
|
|
:can_view_reports,
|
|
|
|
:can_create_new_report,
|
2016-07-29 17:43:15 +08:00
|
|
|
:can_delete_reports,
|
|
|
|
:can_create_experiment
|
2016-02-12 23:52:43 +08:00
|
|
|
] do |proxy, *args, &block|
|
|
|
|
if args[0]
|
|
|
|
project = args[0]
|
|
|
|
project.active? ? proxy.call(*args, &block) : false
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# ---- Almost everything is disabled for archived modules ----
|
|
|
|
around [
|
|
|
|
:can_view_module,
|
|
|
|
# TODO: Because module restoring is made via updating module attributes,
|
|
|
|
# (and that action checks if module is editable) this needs to be
|
|
|
|
# commented out or that functionality will not work any more.
|
|
|
|
#:can_edit_module,
|
|
|
|
:can_archive_module,
|
|
|
|
:can_edit_tags_for_module,
|
|
|
|
:can_add_tag_to_module,
|
|
|
|
:can_remove_tag_from_module,
|
|
|
|
:can_view_module_info,
|
|
|
|
:can_view_module_users,
|
|
|
|
:can_edit_users_on_module,
|
|
|
|
:can_add_user_to_module,
|
|
|
|
:can_remove_user_from_module,
|
2016-07-21 19:11:15 +08:00
|
|
|
:can_view_module_protocols,
|
|
|
|
:can_load_protocol_into_module,
|
|
|
|
:can_export_protocol_from_module,
|
|
|
|
:can_copy_protocol_to_repository,
|
2016-02-12 23:52:43 +08:00
|
|
|
:can_view_module_activities,
|
|
|
|
:can_view_module_comments,
|
|
|
|
:can_add_comment_to_module,
|
|
|
|
:can_view_module_samples,
|
|
|
|
:can_view_module_archive,
|
|
|
|
:can_view_results_in_module,
|
2016-07-21 19:11:15 +08:00
|
|
|
:can_view_or_download_result_assets,
|
2016-02-12 23:52:43 +08:00
|
|
|
:can_view_result_comments,
|
|
|
|
:can_add_result_comment_in_module,
|
|
|
|
:can_create_result_text_in_module,
|
|
|
|
:can_edit_result_text_in_module,
|
|
|
|
:can_archive_result_text_in_module,
|
|
|
|
:can_create_result_table_in_module,
|
|
|
|
:can_edit_result_table_in_module,
|
|
|
|
:can_archive_result_table_in_module,
|
|
|
|
:can_create_result_asset_in_module,
|
|
|
|
:can_edit_result_asset_in_module,
|
|
|
|
:can_archive_result_asset_in_module,
|
|
|
|
:can_add_samples_to_module,
|
2016-07-29 17:43:15 +08:00
|
|
|
:can_delete_samples_from_module
|
|
|
|
] do |proxy, *args, &block|
|
|
|
|
if args[0]
|
|
|
|
my_module = args[0]
|
|
|
|
if my_module.active? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
my_module.experiment.project.active?
|
|
|
|
proxy.call(*args, &block)
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-08 22:35:45 +08:00
|
|
|
# ---- Some things are disabled for archived experiment ----
|
2016-07-29 17:43:15 +08:00
|
|
|
around [
|
2016-08-09 16:00:44 +08:00
|
|
|
:can_edit_experiment,
|
2016-08-26 22:49:32 +08:00
|
|
|
:can_view_experiment,
|
|
|
|
:can_view_experiment_archive,
|
2016-08-09 16:00:44 +08:00
|
|
|
:can_archive_experiment,
|
2016-08-26 22:49:32 +08:00
|
|
|
:can_view_experiment_samples,
|
|
|
|
:can_clone_experiment,
|
|
|
|
:can_move_experiment,
|
2016-08-09 16:00:44 +08:00
|
|
|
:can_edit_canvas,
|
|
|
|
:can_reposition_modules,
|
|
|
|
:can_edit_connections,
|
|
|
|
:can_create_modules,
|
|
|
|
:can_edit_modules,
|
|
|
|
:can_clone_modules,
|
|
|
|
:can_archive_modules
|
2016-02-12 23:52:43 +08:00
|
|
|
] do |proxy, *args, &block|
|
|
|
|
if args[0]
|
2016-07-29 17:43:15 +08:00
|
|
|
experiment = args[0]
|
|
|
|
if experiment.active? &&
|
|
|
|
experiment.project.active?
|
2016-02-12 23:52:43 +08:00
|
|
|
proxy.call(*args, &block)
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
#######################################################
|
|
|
|
# ROLES
|
|
|
|
#######################################################
|
|
|
|
# The following code should stay private, and for each
|
|
|
|
# permission that's needed throughout application, a
|
|
|
|
# public method should be made. That way, we can have
|
|
|
|
# all permissions gathered here in one place.
|
|
|
|
|
2017-01-25 19:30:11 +08:00
|
|
|
# ---- TEAM ROLES ----
|
2017-01-25 16:48:49 +08:00
|
|
|
def is_member_of_team(team)
|
2016-02-12 23:52:43 +08:00
|
|
|
# This is already checked by aspector, so just return true
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2017-01-25 16:48:49 +08:00
|
|
|
def is_admin_of_team(team)
|
|
|
|
@user_team.admin?
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2017-01-25 16:48:49 +08:00
|
|
|
def is_normal_user_of_team(team)
|
|
|
|
@user_team.normal_user?
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2017-01-25 16:48:49 +08:00
|
|
|
def is_normal_user_or_admin_of_team(team)
|
|
|
|
@user_team.normal_user? or @user_team.admin?
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2017-01-25 16:48:49 +08:00
|
|
|
def is_guest_of_team(team)
|
|
|
|
@user_team.guest?
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# ---- PROJECT ROLES ----
|
|
|
|
def is_member_of_project(project)
|
|
|
|
# This is already checked by aspector, so just return true
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_creator_of_project(project)
|
|
|
|
project.created_by == current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_owner_of_project(project)
|
|
|
|
@user_project.owner?
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_user_of_project(project)
|
|
|
|
@user_project.normal_user?
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_user_or_higher_of_project(project)
|
|
|
|
@user_project.normal_user? or @user_project.owner?
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_technician_of_project(project)
|
|
|
|
@user_project.technician?
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_technician_or_higher_of_project(project)
|
|
|
|
@user_project.technician? or
|
2017-01-25 16:48:49 +08:00
|
|
|
@user_project.normal_user? or
|
|
|
|
@user_project.owner?
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def is_viewer_of_project(project)
|
|
|
|
@user_project.viewer?
|
|
|
|
end
|
|
|
|
|
|
|
|
public
|
|
|
|
|
|
|
|
#######################################################
|
|
|
|
# PERMISSIONS
|
|
|
|
#######################################################
|
|
|
|
# The following list can be expanded for new permissions,
|
|
|
|
# and only the following list should be public. Also,
|
|
|
|
# in a lot of cases, the following methods should be added
|
|
|
|
# to "is project archived" or "is module archived" checks
|
|
|
|
# at the beginning of this file (via aspector).
|
|
|
|
|
2017-01-04 17:54:02 +08:00
|
|
|
# ---- ATWHO PERMISSIONS ----
|
2017-01-25 16:48:49 +08:00
|
|
|
def can_view_team_users(team)
|
|
|
|
is_member_of_team(team)
|
2017-01-04 17:54:02 +08:00
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
# ---- PROJECT PERMISSIONS ----
|
|
|
|
|
2017-01-25 16:48:49 +08:00
|
|
|
def can_view_projects(team)
|
|
|
|
is_member_of_team(team)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2017-01-25 16:48:49 +08:00
|
|
|
def can_create_project(team)
|
|
|
|
is_normal_user_or_admin_of_team(team)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# User can view project if he's assigned onto it, or if
|
2017-01-25 16:48:49 +08:00
|
|
|
# a project is public/visible, and user is a member of that team
|
2016-02-12 23:52:43 +08:00
|
|
|
def can_view_project(project)
|
2017-02-13 20:42:53 +08:00
|
|
|
is_admin_of_team(project.team) ||
|
|
|
|
is_member_of_project(project) ||
|
2017-01-25 16:48:49 +08:00
|
|
|
(project.visible? and is_member_of_team(project.team))
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_view_project_activities(project)
|
|
|
|
is_member_of_project(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_view_project_users(project)
|
|
|
|
can_view_project(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_view_project_notifications(project)
|
|
|
|
can_view_project(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_view_project_comments(project)
|
|
|
|
can_view_project(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_edit_project(project)
|
|
|
|
is_owner_of_project(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_archive_project(project)
|
2016-08-08 20:19:35 +08:00
|
|
|
is_owner_of_project(project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_restore_project(project)
|
2016-08-08 20:19:35 +08:00
|
|
|
project.archived? && is_owner_of_project(project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_add_user_to_project(project)
|
|
|
|
is_owner_of_project(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_remove_user_from_project(project)
|
|
|
|
is_owner_of_project(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_edit_users_on_project(project)
|
|
|
|
is_owner_of_project(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_add_comment_to_project(project)
|
|
|
|
is_technician_or_higher_of_project(project)
|
|
|
|
end
|
|
|
|
|
2016-08-24 17:13:51 +08:00
|
|
|
def can_edit_project_comment(comment)
|
2017-03-08 20:18:20 +08:00
|
|
|
comment.project.present? &&
|
2016-08-24 17:13:51 +08:00
|
|
|
(
|
|
|
|
comment.user == current_user ||
|
2017-03-08 20:18:20 +08:00
|
|
|
is_owner_of_project(comment.project)
|
2016-08-24 17:13:51 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_delete_project_comment(comment)
|
2017-03-08 20:18:20 +08:00
|
|
|
comment.project.present? &&
|
2016-08-24 17:36:09 +08:00
|
|
|
(
|
|
|
|
comment.user == current_user ||
|
2017-03-08 20:18:20 +08:00
|
|
|
is_owner_of_project(comment.project)
|
2016-08-24 17:36:09 +08:00
|
|
|
)
|
2016-08-24 17:13:51 +08:00
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
def can_restore_archived_modules(project)
|
|
|
|
is_user_or_higher_of_project(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_view_project_samples(project)
|
2017-01-25 16:48:49 +08:00
|
|
|
can_view_samples(project.team)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_view_project_archive(project)
|
|
|
|
is_user_or_higher_of_project(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_create_new_tag(project)
|
|
|
|
is_user_or_higher_of_project(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_edit_tag(project)
|
|
|
|
is_user_or_higher_of_project(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_delete_tag(project)
|
|
|
|
is_user_or_higher_of_project(project)
|
|
|
|
end
|
|
|
|
|
2016-07-26 17:43:39 +08:00
|
|
|
# ---- EXPERIMENT PERMISSIONS ----
|
|
|
|
|
2016-08-24 16:56:30 +08:00
|
|
|
def can_view_experiment_actions(experiment)
|
2017-03-10 00:45:34 +08:00
|
|
|
can_edit_experiment(experiment) ||
|
2016-08-24 16:56:30 +08:00
|
|
|
can_archive_experiment(experiment)
|
|
|
|
end
|
|
|
|
|
2016-07-26 17:43:39 +08:00
|
|
|
def can_create_experiment(project)
|
|
|
|
is_user_or_higher_of_project(project)
|
|
|
|
end
|
|
|
|
|
2016-07-29 17:43:15 +08:00
|
|
|
def can_edit_experiment(experiment)
|
|
|
|
is_user_or_higher_of_project(experiment.project)
|
2016-07-26 17:43:39 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_view_experiment(experiment)
|
|
|
|
can_view_project(experiment.project)
|
|
|
|
end
|
|
|
|
|
2016-07-28 17:05:28 +08:00
|
|
|
def can_view_experiment_archive(experiment)
|
|
|
|
can_view_project(experiment.project)
|
|
|
|
end
|
|
|
|
|
2016-07-29 17:43:15 +08:00
|
|
|
def can_archive_experiment(experiment)
|
|
|
|
is_user_or_higher_of_project(experiment.project)
|
2016-07-26 17:43:39 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_restore_experiment(experiment)
|
2016-08-03 15:34:10 +08:00
|
|
|
experiment.archived? && is_user_or_higher_of_project(experiment.project)
|
2016-07-26 17:43:39 +08:00
|
|
|
end
|
|
|
|
|
2016-08-02 14:44:07 +08:00
|
|
|
def can_view_experiment_samples(experiment)
|
2017-01-25 16:48:49 +08:00
|
|
|
can_view_samples(experiment.project.team)
|
2016-08-02 14:44:07 +08:00
|
|
|
end
|
2016-08-11 15:46:15 +08:00
|
|
|
|
|
|
|
def can_clone_experiment(experiment)
|
2016-09-08 15:23:29 +08:00
|
|
|
is_user_or_higher_of_project(experiment.project) &&
|
2017-01-25 16:48:49 +08:00
|
|
|
is_normal_user_or_admin_of_team(experiment.project.team)
|
2016-08-11 15:46:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_move_experiment(experiment)
|
2016-09-08 15:23:29 +08:00
|
|
|
is_user_or_higher_of_project(experiment.project) &&
|
2017-01-25 16:48:49 +08:00
|
|
|
is_normal_user_or_admin_of_team(experiment.project.team)
|
2016-08-11 15:46:15 +08:00
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
# ---- WORKFLOW PERMISSIONS ----
|
|
|
|
|
2016-07-28 22:41:10 +08:00
|
|
|
def can_edit_canvas(experiment)
|
|
|
|
is_user_or_higher_of_project(experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2016-07-27 17:35:07 +08:00
|
|
|
def can_reposition_modules(experiment)
|
|
|
|
is_user_or_higher_of_project(experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2016-07-27 17:35:07 +08:00
|
|
|
def can_edit_connections(experiment)
|
|
|
|
is_user_or_higher_of_project(experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# ---- MODULE PERMISSIONS ----
|
|
|
|
|
2016-07-27 17:35:07 +08:00
|
|
|
def can_create_modules(experiment)
|
|
|
|
is_user_or_higher_of_project(experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2016-07-27 17:35:07 +08:00
|
|
|
def can_edit_modules(experiment)
|
|
|
|
is_user_or_higher_of_project(experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2016-07-27 17:35:07 +08:00
|
|
|
def can_clone_modules(experiment)
|
|
|
|
is_user_or_higher_of_project(experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2016-08-17 19:48:02 +08:00
|
|
|
def can_move_modules(experiment)
|
|
|
|
is_user_or_higher_of_project(experiment.project)
|
|
|
|
end
|
|
|
|
|
2016-07-27 17:35:07 +08:00
|
|
|
def can_archive_modules(experiment)
|
|
|
|
is_user_or_higher_of_project(experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_view_module(my_module)
|
2016-07-22 20:31:09 +08:00
|
|
|
can_view_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_edit_module(my_module)
|
2016-07-22 20:31:09 +08:00
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_archive_module(my_module)
|
2016-07-28 16:09:05 +08:00
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_restore_module(my_module)
|
2016-08-08 21:04:02 +08:00
|
|
|
my_module.archived? &&
|
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_edit_tags_for_module(my_module)
|
2016-07-22 20:31:09 +08:00
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_add_tag_to_module(my_module)
|
2016-07-28 22:41:10 +08:00
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_remove_tag_from_module(my_module)
|
2016-07-28 22:41:10 +08:00
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_view_module_info(my_module)
|
2016-07-22 20:31:09 +08:00
|
|
|
can_view_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_view_module_users(my_module)
|
2016-07-22 20:31:09 +08:00
|
|
|
can_view_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_edit_users_on_module(my_module)
|
2016-07-25 15:31:40 +08:00
|
|
|
is_owner_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_add_user_to_module(my_module)
|
2016-07-25 15:31:40 +08:00
|
|
|
is_owner_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_remove_user_from_module(my_module)
|
2016-07-25 15:31:40 +08:00
|
|
|
is_owner_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
def can_view_module_protocols(my_module)
|
|
|
|
can_view_module(my_module)
|
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
def can_view_module_activities(my_module)
|
2016-07-22 20:31:09 +08:00
|
|
|
is_member_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_view_module_comments(my_module)
|
2016-07-22 20:31:09 +08:00
|
|
|
can_view_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_add_comment_to_module(my_module)
|
2016-07-22 20:31:09 +08:00
|
|
|
is_technician_or_higher_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2016-08-24 17:13:51 +08:00
|
|
|
def can_edit_module_comment(comment)
|
2017-03-08 20:18:20 +08:00
|
|
|
comment.my_module.present? &&
|
2016-08-24 17:13:51 +08:00
|
|
|
(
|
|
|
|
comment.user == current_user ||
|
|
|
|
is_owner_of_project(
|
2017-03-08 20:18:20 +08:00
|
|
|
comment.my_module.experiment.project
|
2016-08-24 17:13:51 +08:00
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_delete_module_comment(comment)
|
2017-03-08 20:18:20 +08:00
|
|
|
comment.my_module.present? &&
|
2016-08-24 17:13:51 +08:00
|
|
|
(
|
|
|
|
comment.user == current_user ||
|
|
|
|
is_owner_of_project(
|
2017-03-08 20:18:20 +08:00
|
|
|
comment.my_module.experiment.project
|
2016-08-24 17:13:51 +08:00
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
def can_view_module_samples(my_module)
|
|
|
|
can_view_module(my_module) and
|
2017-01-25 16:48:49 +08:00
|
|
|
can_view_samples(my_module.experiment.project.team)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_view_module_archive(my_module)
|
2016-07-22 20:31:09 +08:00
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2017-02-10 21:27:20 +08:00
|
|
|
def can_complete_module(my_module)
|
|
|
|
is_technician_or_higher_of_project(my_module.experiment.project)
|
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
# ---- RESULTS PERMISSIONS ----
|
|
|
|
|
|
|
|
def can_view_results_in_module(my_module)
|
2016-07-25 15:31:40 +08:00
|
|
|
can_view_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
def can_view_or_download_result_assets(my_module)
|
2017-01-25 16:48:49 +08:00
|
|
|
is_member_of_project(my_module.experiment.project) ||
|
|
|
|
can_view_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_view_result_comments(my_module)
|
2016-07-25 15:31:40 +08:00
|
|
|
can_view_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_add_result_comment_in_module(my_module)
|
2016-07-25 15:31:40 +08:00
|
|
|
is_technician_or_higher_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2016-08-24 17:13:51 +08:00
|
|
|
def can_edit_result_comment_in_module(comment)
|
2017-03-08 20:18:20 +08:00
|
|
|
comment.result.present? &&
|
2016-08-24 17:13:51 +08:00
|
|
|
(
|
|
|
|
comment.user == current_user ||
|
|
|
|
is_owner_of_project(
|
2017-03-08 20:18:20 +08:00
|
|
|
comment.result.my_module.experiment.project
|
2016-08-24 17:13:51 +08:00
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_delete_result_comment_in_module(comment)
|
2017-03-08 20:18:20 +08:00
|
|
|
comment.result.present? &&
|
2016-08-24 17:13:51 +08:00
|
|
|
(
|
|
|
|
comment.user == current_user ||
|
|
|
|
is_owner_of_project(
|
2017-03-08 20:18:20 +08:00
|
|
|
comment.result.my_module.experiment.project
|
2016-08-24 17:13:51 +08:00
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2016-09-06 22:16:39 +08:00
|
|
|
def can_delete_module_result(result)
|
|
|
|
is_owner_of_project(result.my_module.experiment.project)
|
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
# ---- RESULT TEXT PERMISSIONS ----
|
|
|
|
|
|
|
|
def can_create_result_text_in_module(my_module)
|
2016-07-25 15:31:40 +08:00
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_edit_result_text_in_module(my_module)
|
2016-07-25 15:31:40 +08:00
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_archive_result_text_in_module(my_module)
|
2016-07-25 15:31:40 +08:00
|
|
|
is_owner_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# ---- RESULT TABLE PERMISSIONS ----
|
|
|
|
|
|
|
|
def can_create_result_table_in_module(my_module)
|
2016-07-25 15:31:40 +08:00
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_edit_result_table_in_module(my_module)
|
2016-07-25 15:31:40 +08:00
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_archive_result_table_in_module(my_module)
|
2016-07-25 15:31:40 +08:00
|
|
|
is_owner_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# ---- RESULT ASSET PERMISSIONS ----
|
|
|
|
|
|
|
|
def can_create_result_asset_in_module(my_module)
|
2016-07-25 15:31:40 +08:00
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_edit_result_asset_in_module(my_module)
|
2016-07-25 15:31:40 +08:00
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_archive_result_asset_in_module(my_module)
|
2016-07-25 15:31:40 +08:00
|
|
|
is_owner_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# ---- REPORTS PERMISSIONS ----
|
|
|
|
|
|
|
|
def can_view_reports(project)
|
|
|
|
can_view_project(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_create_new_report(project)
|
|
|
|
is_technician_or_higher_of_project(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_delete_reports(project)
|
|
|
|
is_technician_or_higher_of_project(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
# ---- SAMPLE PERMISSIONS ----
|
|
|
|
|
2017-01-25 16:48:49 +08:00
|
|
|
def can_create_samples(team)
|
|
|
|
is_normal_user_or_admin_of_team(team)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2017-01-25 16:48:49 +08:00
|
|
|
def can_view_samples(team)
|
|
|
|
is_member_of_team(team)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# Only person who created the sample
|
2017-01-25 16:48:49 +08:00
|
|
|
# or team admin can edit it
|
2016-02-12 23:52:43 +08:00
|
|
|
def can_edit_sample(sample)
|
2017-01-25 16:48:49 +08:00
|
|
|
is_admin_of_team(sample.team) or
|
|
|
|
sample.user == current_user
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# Only person who created sample can delete it
|
|
|
|
def can_delete_sample(sample)
|
|
|
|
sample.user == current_user
|
|
|
|
end
|
|
|
|
|
2017-01-25 16:48:49 +08:00
|
|
|
def can_delete_samples(team)
|
|
|
|
is_normal_user_or_admin_of_team(team)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_add_samples_to_module(my_module)
|
2016-07-25 15:31:40 +08:00
|
|
|
is_technician_or_higher_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_delete_samples_from_module(my_module)
|
2016-07-25 15:31:40 +08:00
|
|
|
is_technician_or_higher_of_project(my_module.experiment.project)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# ---- SAMPLE TYPES PERMISSIONS ----
|
|
|
|
|
2017-01-25 16:48:49 +08:00
|
|
|
def can_create_sample_type_in_team(team)
|
|
|
|
is_normal_user_or_admin_of_team(team)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# ---- SAMPLE GROUPS PERMISSIONS ----
|
|
|
|
|
2017-01-25 16:48:49 +08:00
|
|
|
def can_create_sample_group_in_team(team)
|
|
|
|
is_normal_user_or_admin_of_team(team)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# ---- CUSTOM FIELDS PERMISSIONS ----
|
|
|
|
|
2017-01-25 16:48:49 +08:00
|
|
|
def can_create_custom_field_in_team(team)
|
|
|
|
is_normal_user_or_admin_of_team(team)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2016-11-29 18:43:18 +08:00
|
|
|
def can_edit_custom_field(custom_field)
|
|
|
|
custom_field.user == current_user ||
|
2017-01-25 16:48:49 +08:00
|
|
|
is_admin_of_team(custom_field.team)
|
2016-11-29 18:43:18 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_delete_custom_field(custom_field)
|
|
|
|
custom_field.user == current_user ||
|
2017-01-25 16:48:49 +08:00
|
|
|
is_admin_of_team(custom_field.team)
|
2016-11-29 18:43:18 +08:00
|
|
|
end
|
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
# ---- PROTOCOL PERMISSIONS ----
|
|
|
|
|
2017-01-25 16:48:49 +08:00
|
|
|
def can_view_team_protocols(team)
|
|
|
|
is_member_of_team(team)
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
2017-01-25 16:48:49 +08:00
|
|
|
def can_create_new_protocol(team)
|
|
|
|
is_normal_user_or_admin_of_team(team)
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
2017-01-25 16:48:49 +08:00
|
|
|
def can_import_protocols(team)
|
|
|
|
is_normal_user_or_admin_of_team(team)
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_view_protocol(protocol)
|
|
|
|
if protocol.in_repository_public?
|
2017-01-25 16:48:49 +08:00
|
|
|
is_member_of_team(protocol.team)
|
|
|
|
elsif protocol.in_repository_private? or protocol.in_repository_archived?
|
|
|
|
is_member_of_team(protocol.team) and
|
|
|
|
protocol.added_by == current_user
|
2016-07-21 19:11:15 +08:00
|
|
|
elsif protocol.in_module?
|
|
|
|
my_module = protocol.my_module
|
2016-07-25 18:07:10 +08:00
|
|
|
my_module.active? &&
|
2017-01-25 16:48:49 +08:00
|
|
|
my_module.experiment.project.active? &&
|
|
|
|
can_view_module(my_module) &&
|
|
|
|
my_module.experiment.active?
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_edit_protocol(protocol)
|
2017-01-25 16:48:49 +08:00
|
|
|
is_normal_user_or_admin_of_team(protocol.team) and
|
2016-07-21 19:11:15 +08:00
|
|
|
current_user == protocol.added_by and (not protocol.in_repository_archived?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_clone_protocol(protocol)
|
2017-01-25 16:48:49 +08:00
|
|
|
is_normal_user_or_admin_of_team(protocol.team) and
|
2016-07-21 19:11:15 +08:00
|
|
|
(
|
|
|
|
protocol.in_repository_public? or
|
|
|
|
(protocol.in_repository_private? and current_user == protocol.added_by)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_make_protocol_private(protocol)
|
|
|
|
protocol.added_by == current_user and
|
|
|
|
protocol.in_repository_public?
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_publish_protocol(protocol)
|
|
|
|
protocol.added_by == current_user and
|
|
|
|
protocol.in_repository_private?
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_export_protocol(protocol)
|
2017-01-25 16:48:49 +08:00
|
|
|
(protocol.in_repository_public? and is_member_of_team(protocol.team)) or
|
|
|
|
(protocol.in_repository_private? and protocol.added_by == current_user) or
|
|
|
|
(protocol.in_module? and
|
|
|
|
can_export_protocol_from_module(protocol.my_module))
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_archive_protocol(protocol)
|
|
|
|
protocol.added_by == current_user and
|
2017-01-25 16:48:49 +08:00
|
|
|
(protocol.in_repository_public? or protocol.in_repository_private?)
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_restore_protocol(protocol)
|
|
|
|
protocol.added_by == current_user and
|
2017-01-25 16:48:49 +08:00
|
|
|
protocol.in_repository_archived?
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_unlink_protocol(protocol)
|
|
|
|
if protocol.linked?
|
|
|
|
my_module = protocol.my_module
|
2016-07-25 18:07:10 +08:00
|
|
|
my_module.active? &&
|
2017-01-25 16:48:49 +08:00
|
|
|
my_module.experiment.project.active? &&
|
|
|
|
is_user_or_higher_of_project(my_module.experiment.project) &&
|
|
|
|
my_module.experiment.active?
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_revert_protocol(protocol)
|
|
|
|
if protocol.linked?
|
|
|
|
my_module = protocol.my_module
|
2016-07-25 18:07:10 +08:00
|
|
|
my_module.active? &&
|
2017-01-25 16:48:49 +08:00
|
|
|
my_module.experiment.project.active? &&
|
|
|
|
is_user_or_higher_of_project(my_module.experiment.project) &&
|
|
|
|
my_module.experiment.active?
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_update_protocol_from_parent(protocol)
|
|
|
|
if protocol.linked?
|
|
|
|
my_module = protocol.my_module
|
2016-07-25 18:07:10 +08:00
|
|
|
my_module.active? &&
|
2017-01-25 16:48:49 +08:00
|
|
|
my_module.experiment.project.active? &&
|
|
|
|
is_user_or_higher_of_project(my_module.experiment.project) &&
|
|
|
|
my_module.experiment.active?
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_load_protocol_from_repository(protocol, source)
|
|
|
|
if can_view_protocol(source)
|
|
|
|
my_module = protocol.my_module
|
2016-07-25 18:07:10 +08:00
|
|
|
my_module.active? &&
|
2017-01-25 16:48:49 +08:00
|
|
|
my_module.experiment.project.active? &&
|
|
|
|
is_user_or_higher_of_project(my_module.experiment.project) &&
|
|
|
|
my_module.experiment.active?
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_update_parent_protocol(protocol)
|
|
|
|
if protocol.linked?
|
|
|
|
my_module = protocol.my_module
|
|
|
|
parent = protocol.parent
|
|
|
|
|
2016-07-25 18:07:10 +08:00
|
|
|
my_module.active? &&
|
2017-01-25 16:48:49 +08:00
|
|
|
my_module.experiment.project.active? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
is_normal_user_or_admin_of_team(parent.team) &&
|
|
|
|
is_user_or_higher_of_project(my_module.experiment.project) &&
|
|
|
|
(parent.in_repository_public? or parent.in_repository_private?) &&
|
|
|
|
parent.added_by == current_user
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# ---- STEPS PERMISSIONS ----
|
|
|
|
|
|
|
|
def can_load_protocol_into_module(my_module)
|
2016-07-25 15:31:40 +08:00
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_export_protocol_from_module(my_module)
|
|
|
|
can_view_module_protocols(my_module)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_copy_protocol_to_repository(my_module)
|
2017-01-25 16:48:49 +08:00
|
|
|
is_normal_user_or_admin_of_team(my_module.experiment.project.team)
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_link_copied_protocol_in_repository(protocol)
|
|
|
|
can_copy_protocol_to_repository(protocol.my_module) and
|
2017-01-25 16:48:49 +08:00
|
|
|
is_user_or_higher_of_project(protocol.my_module.experiment.project)
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_view_steps_in_protocol(protocol)
|
|
|
|
if protocol.in_module?
|
|
|
|
my_module = protocol.my_module
|
2016-07-25 18:07:10 +08:00
|
|
|
my_module.active? &&
|
2017-01-25 16:48:49 +08:00
|
|
|
my_module.experiment.project.active? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
can_view_module(my_module)
|
2016-07-21 19:11:15 +08:00
|
|
|
elsif protocol.in_repository?
|
|
|
|
protocol.in_repository_active? and can_view_protocol(protocol)
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_create_step_in_protocol(protocol)
|
|
|
|
if protocol.in_module?
|
|
|
|
my_module = protocol.my_module
|
2016-07-25 18:07:10 +08:00
|
|
|
my_module.active? &&
|
|
|
|
my_module.experiment.project.active? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-07-21 19:11:15 +08:00
|
|
|
elsif protocol.in_repository?
|
|
|
|
protocol.in_repository_active? and can_edit_protocol(protocol)
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_reorder_step_in_protocol(protocol)
|
|
|
|
if protocol.in_module?
|
|
|
|
my_module = protocol.my_module
|
2016-07-25 18:07:10 +08:00
|
|
|
my_module.active? &&
|
2017-01-25 16:48:49 +08:00
|
|
|
my_module.experiment.project.active? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-07-21 19:11:15 +08:00
|
|
|
elsif protocol.in_repository?
|
|
|
|
protocol.in_repository_active? and can_edit_protocol(protocol)
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Could possibly be divided into:
|
|
|
|
# - edit step name/description
|
|
|
|
# - adding checklists
|
|
|
|
# - adding assets
|
|
|
|
# - adding tables
|
|
|
|
# but right now we have 1 page to rule them all.
|
|
|
|
def can_edit_step_in_protocol(protocol)
|
|
|
|
if protocol.in_module?
|
|
|
|
my_module = protocol.my_module
|
2016-07-25 18:07:10 +08:00
|
|
|
my_module.active? &&
|
|
|
|
my_module.experiment.project.active? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-07-21 19:11:15 +08:00
|
|
|
elsif protocol.in_repository?
|
|
|
|
protocol.in_repository_active? and can_edit_protocol(protocol)
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_delete_step_in_protocol(protocol)
|
|
|
|
if protocol.in_module?
|
|
|
|
my_module = protocol.my_module
|
2016-07-25 18:07:10 +08:00
|
|
|
my_module.active? &&
|
2017-01-25 16:48:49 +08:00
|
|
|
my_module.experiment.project.active? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
is_owner_of_project(my_module.experiment.project)
|
2016-07-21 19:11:15 +08:00
|
|
|
elsif protocol.in_repository?
|
|
|
|
protocol.in_repository_active? and can_edit_protocol(protocol)
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_view_step_comments(protocol)
|
|
|
|
if protocol.in_module?
|
|
|
|
my_module = protocol.my_module
|
2016-07-25 18:07:10 +08:00
|
|
|
my_module.active? &&
|
2017-01-25 16:48:49 +08:00
|
|
|
my_module.experiment.project.active? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
can_view_project(my_module.experiment.project)
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
|
|
|
# In repository, comments are disabled
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_add_step_comment_in_protocol(protocol)
|
|
|
|
if protocol.in_module?
|
|
|
|
my_module = protocol.my_module
|
2016-07-25 18:07:10 +08:00
|
|
|
my_module.active? &&
|
2017-01-25 16:48:49 +08:00
|
|
|
my_module.experiment.project.active? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
is_technician_or_higher_of_project(my_module.experiment.project)
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
|
|
|
# In repository, user cannot complete steps
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-24 17:13:51 +08:00
|
|
|
def can_edit_step_comment_in_protocol(comment)
|
2017-03-08 20:18:20 +08:00
|
|
|
return false if comment.step.blank?
|
2016-08-25 17:45:13 +08:00
|
|
|
|
2017-03-08 20:18:20 +08:00
|
|
|
protocol = comment.step.protocol
|
2016-08-24 17:13:51 +08:00
|
|
|
if protocol.in_module?
|
2016-08-25 17:45:13 +08:00
|
|
|
comment.user == current_user ||
|
|
|
|
is_owner_of_project(
|
|
|
|
protocol.my_module.experiment.project
|
2016-08-24 17:13:51 +08:00
|
|
|
)
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_delete_step_comment_in_protocol(comment)
|
2017-03-08 20:18:20 +08:00
|
|
|
return false if comment.step.blank?
|
2016-08-25 17:45:13 +08:00
|
|
|
|
2017-03-08 20:18:20 +08:00
|
|
|
protocol = comment.step.protocol
|
2016-08-24 17:13:51 +08:00
|
|
|
if protocol.in_module?
|
2016-08-25 17:45:13 +08:00
|
|
|
comment.user == current_user ||
|
|
|
|
is_owner_of_project(
|
|
|
|
protocol.my_module.experiment.project
|
2016-08-24 17:13:51 +08:00
|
|
|
)
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
def can_view_or_download_step_assets(protocol)
|
|
|
|
if protocol.in_module?
|
|
|
|
my_module = protocol.my_module
|
2016-07-25 18:07:10 +08:00
|
|
|
my_module.active? &&
|
2017-01-25 16:48:49 +08:00
|
|
|
my_module.experiment.project.active? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
(is_member_of_project(my_module.experiment.project) ||
|
|
|
|
can_view_project(my_module.experiment.project))
|
2016-07-21 19:11:15 +08:00
|
|
|
elsif protocol.in_repository?
|
|
|
|
protocol.in_repository_active? and can_view_protocol(protocol)
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_complete_step_in_protocol(protocol)
|
|
|
|
if protocol.in_module?
|
|
|
|
my_module = protocol.my_module
|
2016-07-25 18:07:10 +08:00
|
|
|
my_module.active? &&
|
2017-01-25 16:48:49 +08:00
|
|
|
my_module.experiment.project.active? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
is_technician_or_higher_of_project(my_module.experiment.project)
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
|
|
|
# In repository, user cannot complete steps
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_uncomplete_step_in_protocol(protocol)
|
|
|
|
if protocol.in_module?
|
|
|
|
my_module = protocol.my_module
|
2016-07-25 18:07:10 +08:00
|
|
|
my_module.active? &&
|
|
|
|
my_module.experiment.project.active? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
|
|
|
# In repository, user cannot complete steps
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_check_checkbox(protocol)
|
|
|
|
if protocol.in_module?
|
|
|
|
my_module = protocol.my_module
|
2016-07-25 18:07:10 +08:00
|
|
|
my_module.active? &&
|
2017-01-25 16:48:49 +08:00
|
|
|
my_module.experiment.project.active? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
is_technician_or_higher_of_project(my_module.experiment.project)
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
|
|
|
# In repository, user cannot check checkboxes
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_uncheck_checkbox(protocol)
|
|
|
|
if protocol.in_module?
|
|
|
|
my_module = protocol.my_module
|
2016-07-25 18:07:10 +08:00
|
|
|
my_module.active? &&
|
2017-01-25 16:48:49 +08:00
|
|
|
my_module.experiment.project.active? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
is_user_or_higher_of_project(my_module.experiment.project)
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
|
|
|
# In repository, user cannot check checkboxes
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
2017-05-22 23:54:30 +08:00
|
|
|
|
|
|
|
# ---- REPOSITORIES PERMISSIONS ----
|
|
|
|
|
|
|
|
def can_view_team_repositories(team)
|
|
|
|
is_member_of_team(team)
|
2017-05-23 17:32:02 +08:00
|
|
|
end
|
2017-05-23 17:05:25 +08:00
|
|
|
|
2017-06-06 21:50:43 +08:00
|
|
|
def can_create_repository(team)
|
2017-06-06 19:33:57 +08:00
|
|
|
is_admin_of_team(team) &&
|
|
|
|
team.repositories.count < Constants::REPOSITORIES_LIMIT
|
2017-05-24 15:29:44 +08:00
|
|
|
end
|
|
|
|
|
2017-05-18 20:21:00 +08:00
|
|
|
def can_view_repository(repository)
|
2017-06-13 16:33:08 +08:00
|
|
|
is_member_of_team(repository.team)
|
2017-05-22 23:54:30 +08:00
|
|
|
end
|
2017-06-01 02:56:05 +08:00
|
|
|
|
2017-06-05 23:25:05 +08:00
|
|
|
def can_edit_and_destroy_repository(repository)
|
2017-06-01 02:56:05 +08:00
|
|
|
is_admin_of_team(repository.team)
|
|
|
|
end
|
2017-06-06 23:35:29 +08:00
|
|
|
|
2017-06-08 00:43:48 +08:00
|
|
|
def can_copy_repository(repository)
|
|
|
|
can_create_repository(repository.team)
|
|
|
|
end
|
|
|
|
|
2017-06-06 23:35:29 +08:00
|
|
|
def can_create_columns_in_repository(repository)
|
|
|
|
is_normal_user_or_admin_of_team(repository.team)
|
|
|
|
end
|
|
|
|
|
2017-06-07 23:07:28 +08:00
|
|
|
def can_delete_column_in_repository(column)
|
2017-07-28 17:57:04 +08:00
|
|
|
column.created_by == current_user ||
|
|
|
|
is_admin_of_team(column.repository.team)
|
2017-06-06 23:35:29 +08:00
|
|
|
end
|
|
|
|
|
2017-06-07 23:07:28 +08:00
|
|
|
def can_edit_column_in_repository(column)
|
2017-07-28 17:57:04 +08:00
|
|
|
column.created_by == current_user ||
|
|
|
|
is_admin_of_team(column.repository.team)
|
2017-06-06 23:35:29 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_create_repository_records(repository)
|
|
|
|
is_normal_user_or_admin_of_team(repository.team)
|
|
|
|
end
|
|
|
|
|
2017-06-13 14:10:10 +08:00
|
|
|
def can_import_repository_records(repository)
|
|
|
|
is_normal_user_or_admin_of_team(repository.team)
|
|
|
|
end
|
|
|
|
|
2017-06-07 23:07:28 +08:00
|
|
|
def can_edit_repository_record(record)
|
|
|
|
is_normal_user_or_admin_of_team(record.repository.team)
|
2017-06-06 23:35:29 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_delete_repository_records(repository)
|
|
|
|
is_normal_user_or_admin_of_team(repository.team)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_delete_repository_record(record)
|
|
|
|
team = record.repository.team
|
|
|
|
is_admin_of_team(team) || (is_normal_user_of_team(team) &&
|
|
|
|
record.created_by == current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_assign_repository_records(my_module, repository)
|
2017-06-07 23:07:28 +08:00
|
|
|
can_delete_repository_records(repository) &&
|
2017-06-06 23:35:29 +08:00
|
|
|
is_technician_or_higher_of_project(my_module.experiment.project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_unassign_repository_records(my_module, repository)
|
2017-06-07 23:07:28 +08:00
|
|
|
can_delete_repository_records(repository) &&
|
2017-06-06 23:35:29 +08:00
|
|
|
is_technician_or_higher_of_project(my_module.experiment.project)
|
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|