diff --git a/app/controllers/access_permissions/protocols_controller.rb b/app/controllers/access_permissions/protocols_controller.rb index d9372d0f3..2c2684115 100644 --- a/app/controllers/access_permissions/protocols_controller.rb +++ b/app/controllers/access_permissions/protocols_controller.rb @@ -35,7 +35,9 @@ module AccessPermissions user_id: permitted_update_params[:user_id], team: current_team ) - @user_assignment.update(permitted_update_params) + @user_assignment.update!(permitted_update_params) + log_activity(:protocol_template_access_changed, @user_assignment) + respond_to do |format| format.json do render :protocol_member @@ -53,8 +55,9 @@ module AccessPermissions user_assignment.team = current_team user_assignment.assigned_by = current_user user_assignment.save! - end + log_activity(:protocol_template_access_granted, user_assignment) + end respond_to do |format| @message = t('access_permissions.create.success', count: @protocol.user_assignments.count) format.json { render :edit } @@ -72,6 +75,8 @@ module AccessPermissions user_assignment = @protocol.user_assignments.find_by(user: user, team: current_team) respond_to do |format| if user_assignment.destroy + + log_activity(:protocol_template_access_revoked, user_assignment) format.json do render json: { flash: t('access_permissions.destroy.success', member_name: user.full_name) }, status: :ok @@ -110,5 +115,17 @@ module AccessPermissions def check_read_permissions render_403 unless can_read_protocol_in_repository?(@protocol) end + + def log_activity(type_of, user_assignment) + Activities::CreateActivityService + .call(activity_type: type_of, + owner: current_user, + subject: @protocol, + team: @protocol.team, + project: nil, + message_items: { protocol: @protocol.id, + user_target: user_assignment.user.id, + role: user_assignment.user_role.name }) + end end end diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 3a190f7c7..7c5a1d931 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -164,12 +164,21 @@ class ProtocolsController < ApplicationController end def publish - @protocol.update( - published_by: current_user, - published_on: DateTime.now, - version_comment: params[:version_comment] || @protocol.version_comment, - protocol_type: (@protocol.parent_id.nil? ? :in_repository_published_original : :in_repository_published_version) - ) + Protocol.transaction do + @protocol.update!( + published_by: current_user, + published_on: DateTime.now, + version_comment: params[:version_comment] || @protocol.version_comment, + protocol_type: (@protocol.parent_id.nil? ? :in_repository_published_original : :in_repository_published_version) + ) + log_activity(:protocol_template_published, + nil, + protocol: @protocol.id, + version_number: @protocol.version_number) + rescue ActiveRecord::RecordInvalid + raise ActiveRecord::Rollback + end + if params[:view] == 'show' redirect_to protocol_path(@protocol) else @@ -178,8 +187,14 @@ class ProtocolsController < ApplicationController end def destroy_draft - @protocol.destroy - + Protocol.transaction do + parent = @protocol.parent + @protocol.destroy! + @protocol = parent + log_activity(:protocol_template_draft_deleted, + nil, + protocol: @protocol.id) + end redirect_to protocols_path end @@ -329,6 +344,7 @@ class ProtocolsController < ApplicationController transaction_error = false Protocol.transaction do @new = @protocol.copy_to_repository(Protocol.new(create_params), current_user) + log_activity(:task_protocol_save_to_template, @my_module.experiment.project, protocol: @protocol.id) rescue StandardError => e transaction_error = true Rails.logger.error(e.message) @@ -1027,6 +1043,9 @@ class ProtocolsController < ApplicationController respond_to do |format| format.json do if @protocol.update(version_comment: params.require(:protocol)[:version_comment]) + log_activity(:protocol_template_revision_notes_updated, + nil, + protocol: @protocol.id) render json: { version_comment: @protocol.version_comment } else render json: @protocol.errors, status: :unprocessable_entity diff --git a/app/helpers/global_activities_helper.rb b/app/helpers/global_activities_helper.rb index 76bfb9f7e..db2679db6 100644 --- a/app/helpers/global_activities_helper.rb +++ b/app/helpers/global_activities_helper.rb @@ -82,12 +82,8 @@ module GlobalActivitiesHelper protocols_my_module_path(obj) end when Protocol - if obj.in_repository_public? - path = protocols_path(type: :public, team: obj.team.id) - elsif obj.in_repository_private? - path = protocols_path(type: :private, team: obj.team.id) - elsif obj.in_repository_archived? - path = protocols_path(type: :archive, team: obj.team.id) + if obj.my_module.nil? + path = protocols_path(team: obj.team.id) elsif obj.my_module.navigable? path = protocols_my_module_path(obj.my_module) else diff --git a/app/views/global_activities/references/_protocol.html.erb b/app/views/global_activities/references/_protocol.html.erb index b8743a474..9486083f1 100644 --- a/app/views/global_activities/references/_protocol.html.erb +++ b/app/views/global_activities/references/_protocol.html.erb @@ -7,12 +7,9 @@ <% end %> <% if subject %> <% if subject.in_repository? %> - <% type = :public if subject.in_repository_public? %> - <% type = :private if subject.in_repository_private? %> - <% type = :archive if subject.in_repository_archived? %>
- <%= route_to_other_team protocols_path(team: subject.team, type: type), + <%= route_to_other_team protocols_path(team: subject.team), team, subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH), title: subject.name %> diff --git a/config/initializers/extends.rb b/config/initializers/extends.rb index 5813b3c5e..f1c7c8866 100644 --- a/config/initializers/extends.rb +++ b/config/initializers/extends.rb @@ -429,7 +429,14 @@ class Extends task_step_checklist_duplicated: 226, protocol_step_text_duplicated: 227, protocol_step_table_duplicated: 228, - protocol_step_checklist_duplicated: 229 + protocol_step_checklist_duplicated: 229, + protocol_template_published: 230, + protocol_template_revision_notes_updated: 231, + protocol_template_draft_deleted: 232, + protocol_template_access_granted: 233, + protocol_template_access_changed: 234, + protocol_template_access_revoked: 235, + task_protocol_save_to_template: 236 } ACTIVITY_GROUPS = { @@ -438,7 +445,7 @@ class Extends task: [8, 58, 9, 59, *10..14, 35, 36, 37, 53, 54, *60..63, 138, 139, 140, 64, 66, 106, 126, 120, 132, *146..148, 166], task_protocol: [15, 22, 16, 18, 19, 20, 21, 17, 38, 39, 100, 111, 45, 46, 47, 121, 124, 115, 118, 127, 130, 137, - 217, 168, 171, 177, 184, 185, 188, 189, *192..203, 222, 224, 225, 226], + 217, 168, 171, 177, 184, 185, 188, 189, *192..203, 222, 224, 225, 226, 236], task_inventory: [55, 56, 146, 147, 183], experiment: [*27..31, 57, 141, 165], reports: [48, 50, 49, 163, 164], @@ -446,7 +453,7 @@ class Extends 78, 96, 107, 113, 114, *133..136, 180, 181, 182], protocol_repository: [80, 103, 89, 87, 79, 90, 91, 88, 85, 86, 84, 81, 82, 83, 101, 112, 123, 125, 117, 119, 129, 131, 170, 173, 179, 187, 186, - 190, 191, *204..215, 220, 221, 223, 227, 228, 229], + 190, 191, *204..215, 220, 221, 223, 227, 228, 229, *230..235], team: [92, 94, 93, 97, 104], label_repository: [*216..219] } diff --git a/config/locales/global_activities/en.yml b/config/locales/global_activities/en.yml index b7d75e804..a87d291fc 100644 --- a/config/locales/global_activities/en.yml +++ b/config/locales/global_activities/en.yml @@ -254,6 +254,13 @@ en: label_template_edited_html: "%{user} edited %{type} label template %{label_template} in Label templates." label_template_deleted_html: "%{user} deleted %{type} label template %{label_template} in Label templates." label_template_copied_html: "%{user} copied %{type} label template %{label_template_new} from %{label_template_original} in Label templates." + protocol_template_published_html: "%{user} published protocol template %{protocol} version %{version_number}" + protocol_template_revision_notes_updated_html: "%{user} edited revision notes of %{protocol}" + protocol_template_draft_deleted_html: "%{user} deleted draft of %{protocol}" + protocol_template_access_granted_html: "%{user} granted access to %{user_target} with user role %{role} to protocol template %{protocol}" + protocol_template_access_changed_html: "%{user} changed %{user_target}’s role on protocol template %{protocol} to %{role}" + protocol_template_access_revoked_html: "%{user} removed %{user_target} with user role %{role} from protocol template %{protocol}" + task_protocol_save_to_template_html: "%{user} created a new protocol template %{protocol} from a task" activity_name: create_project: "Project created" rename_project: "Project renamed" @@ -462,9 +469,13 @@ en: label_template_edited: "Label template edited" label_template_deleted: "Label template deleted" label_template_copied: "Label template copied" - - - + protocol_template_published: "Protocol template published" + protocol_template_revision_notes_updated: "Revision notes edited" + protocol_template_draft_deleted: "Deleting draft" + protocol_template_access_granted: "User granted access to protocol template" + protocol_template_access_changed: "User role changed on a protocol" + protocol_template_access_revoked: "User removed from a protocol" + task_protocol_save_to_template: "Save as new protocol template" activity_group: projects: "Projects" task_results: "Task results"