diff --git a/app/helpers/permission_helper.rb b/app/helpers/permission_helper.rb index 1fd6cf0ab..3f3cd2a71 100644 --- a/app/helpers/permission_helper.rb +++ b/app/helpers/permission_helper.rb @@ -302,6 +302,19 @@ module PermissionHelper is_technician_or_higher_of_project(project) end + def can_edit_project_comment(comment) + comment.project_comment.present? && + ( + comment.user == current_user || + is_owner_of_project(comment.project_comment.project) + ) + end + + def can_delete_project_comment(comment) + comment.user == current_user || + is_owner_of_project(project) + end + def can_restore_archived_modules(project) is_user_or_higher_of_project(project) end @@ -475,6 +488,26 @@ module PermissionHelper is_technician_or_higher_of_project(my_module.experiment.project) end + def can_edit_module_comment(comment) + comment.my_module_comment.present? && + ( + comment.user == current_user || + is_owner_of_project( + comment.my_module_comment.my_module.experiment.project + ) + ) + end + + def can_delete_module_comment(comment) + comment.my_module_comment.present? && + ( + comment.user == current_user || + is_owner_of_project( + comment.my_module_comment.my_module.experiment.project + ) + ) + end + def can_view_module_samples(my_module) can_view_module(my_module) and can_view_samples(my_module.experiment.project.organization) @@ -502,6 +535,26 @@ module PermissionHelper is_technician_or_higher_of_project(my_module.experiment.project) end + def can_edit_result_comment_in_module(comment) + comment.result_comment.present? && + ( + comment.user == current_user || + is_owner_of_project( + comment.result_comment.result.my_module.experiment.project + ) + ) + end + + def can_delete_result_comment_in_module(comment) + comment.result_comment.present? && + ( + comment.user == current_user || + is_owner_of_project( + comment.result_comment.result.my_module.experiment.project + ) + ) + end + # ---- RESULT TEXT PERMISSIONS ---- def can_create_result_text_in_module(my_module) @@ -874,6 +927,34 @@ module PermissionHelper end end + def can_edit_step_comment_in_protocol(comment) + if protocol.in_module? + comment.step_comment.present? && + ( + comment.user == current_user || + is_owner_of_project( + comment.step_comment.step.protocol.my_module.experiment.project + ) + ) + else + false + end + end + + def can_delete_step_comment_in_protocol(comment) + if protocol.in_module? + comment.step_comment.present? && + ( + comment.user == current_user || + is_owner_of_project( + comment.step_comment.step.protocol.my_module.experiment.project + ) + ) + else + false + end + end + def can_view_or_download_step_assets(protocol) if protocol.in_module? my_module = protocol.my_module