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? %>