mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-23 04:08:14 +08:00
Add new protocol activities [SCI-7717]
This commit is contained in:
parent
8f25b9c1cb
commit
f7d7113239
6 changed files with 73 additions and 26 deletions
|
@ -35,7 +35,9 @@ module AccessPermissions
|
||||||
user_id: permitted_update_params[:user_id],
|
user_id: permitted_update_params[:user_id],
|
||||||
team: current_team
|
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|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
render :protocol_member
|
render :protocol_member
|
||||||
|
@ -53,8 +55,9 @@ module AccessPermissions
|
||||||
user_assignment.team = current_team
|
user_assignment.team = current_team
|
||||||
user_assignment.assigned_by = current_user
|
user_assignment.assigned_by = current_user
|
||||||
user_assignment.save!
|
user_assignment.save!
|
||||||
end
|
|
||||||
|
|
||||||
|
log_activity(:protocol_template_access_granted, user_assignment)
|
||||||
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
@message = t('access_permissions.create.success', count: @protocol.user_assignments.count)
|
@message = t('access_permissions.create.success', count: @protocol.user_assignments.count)
|
||||||
format.json { render :edit }
|
format.json { render :edit }
|
||||||
|
@ -72,6 +75,8 @@ module AccessPermissions
|
||||||
user_assignment = @protocol.user_assignments.find_by(user: user, team: current_team)
|
user_assignment = @protocol.user_assignments.find_by(user: user, team: current_team)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if user_assignment.destroy
|
if user_assignment.destroy
|
||||||
|
|
||||||
|
log_activity(:protocol_template_access_revoked, user_assignment)
|
||||||
format.json do
|
format.json do
|
||||||
render json: { flash: t('access_permissions.destroy.success', member_name: user.full_name) },
|
render json: { flash: t('access_permissions.destroy.success', member_name: user.full_name) },
|
||||||
status: :ok
|
status: :ok
|
||||||
|
@ -110,5 +115,17 @@ module AccessPermissions
|
||||||
def check_read_permissions
|
def check_read_permissions
|
||||||
render_403 unless can_read_protocol_in_repository?(@protocol)
|
render_403 unless can_read_protocol_in_repository?(@protocol)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -164,12 +164,21 @@ class ProtocolsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def publish
|
def publish
|
||||||
@protocol.update(
|
Protocol.transaction do
|
||||||
|
@protocol.update!(
|
||||||
published_by: current_user,
|
published_by: current_user,
|
||||||
published_on: DateTime.now,
|
published_on: DateTime.now,
|
||||||
version_comment: params[:version_comment] || @protocol.version_comment,
|
version_comment: params[:version_comment] || @protocol.version_comment,
|
||||||
protocol_type: (@protocol.parent_id.nil? ? :in_repository_published_original : :in_repository_published_version)
|
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'
|
if params[:view] == 'show'
|
||||||
redirect_to protocol_path(@protocol)
|
redirect_to protocol_path(@protocol)
|
||||||
else
|
else
|
||||||
|
@ -178,8 +187,14 @@ class ProtocolsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_draft
|
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
|
redirect_to protocols_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -329,6 +344,7 @@ class ProtocolsController < ApplicationController
|
||||||
transaction_error = false
|
transaction_error = false
|
||||||
Protocol.transaction do
|
Protocol.transaction do
|
||||||
@new = @protocol.copy_to_repository(Protocol.new(create_params), current_user)
|
@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
|
rescue StandardError => e
|
||||||
transaction_error = true
|
transaction_error = true
|
||||||
Rails.logger.error(e.message)
|
Rails.logger.error(e.message)
|
||||||
|
@ -1027,6 +1043,9 @@ class ProtocolsController < ApplicationController
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
if @protocol.update(version_comment: params.require(:protocol)[:version_comment])
|
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 }
|
render json: { version_comment: @protocol.version_comment }
|
||||||
else
|
else
|
||||||
render json: @protocol.errors, status: :unprocessable_entity
|
render json: @protocol.errors, status: :unprocessable_entity
|
||||||
|
|
|
@ -82,12 +82,8 @@ module GlobalActivitiesHelper
|
||||||
protocols_my_module_path(obj)
|
protocols_my_module_path(obj)
|
||||||
end
|
end
|
||||||
when Protocol
|
when Protocol
|
||||||
if obj.in_repository_public?
|
if obj.my_module.nil?
|
||||||
path = protocols_path(type: :public, team: obj.team.id)
|
path = protocols_path(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)
|
|
||||||
elsif obj.my_module.navigable?
|
elsif obj.my_module.navigable?
|
||||||
path = protocols_my_module_path(obj.my_module)
|
path = protocols_my_module_path(obj.my_module)
|
||||||
else
|
else
|
||||||
|
|
|
@ -7,12 +7,9 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if subject %>
|
<% if subject %>
|
||||||
<% if subject.in_repository? %>
|
<% 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? %>
|
|
||||||
<div class="ga-breadcrumb">
|
<div class="ga-breadcrumb">
|
||||||
<span class="fas fa-edit"></span>
|
<span class="fas fa-edit"></span>
|
||||||
<%= route_to_other_team protocols_path(team: subject.team, type: type),
|
<%= route_to_other_team protocols_path(team: subject.team),
|
||||||
team,
|
team,
|
||||||
subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH),
|
subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH),
|
||||||
title: subject.name %>
|
title: subject.name %>
|
||||||
|
|
|
@ -429,7 +429,14 @@ class Extends
|
||||||
task_step_checklist_duplicated: 226,
|
task_step_checklist_duplicated: 226,
|
||||||
protocol_step_text_duplicated: 227,
|
protocol_step_text_duplicated: 227,
|
||||||
protocol_step_table_duplicated: 228,
|
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 = {
|
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,
|
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],
|
*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,
|
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],
|
task_inventory: [55, 56, 146, 147, 183],
|
||||||
experiment: [*27..31, 57, 141, 165],
|
experiment: [*27..31, 57, 141, 165],
|
||||||
reports: [48, 50, 49, 163, 164],
|
reports: [48, 50, 49, 163, 164],
|
||||||
|
@ -446,7 +453,7 @@ class Extends
|
||||||
78, 96, 107, 113, 114, *133..136, 180, 181, 182],
|
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,
|
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,
|
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],
|
team: [92, 94, 93, 97, 104],
|
||||||
label_repository: [*216..219]
|
label_repository: [*216..219]
|
||||||
}
|
}
|
||||||
|
|
|
@ -254,6 +254,13 @@ en:
|
||||||
label_template_edited_html: "%{user} edited %{type} label template %{label_template} in Label templates."
|
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_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."
|
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:
|
activity_name:
|
||||||
create_project: "Project created"
|
create_project: "Project created"
|
||||||
rename_project: "Project renamed"
|
rename_project: "Project renamed"
|
||||||
|
@ -462,9 +469,13 @@ en:
|
||||||
label_template_edited: "Label template edited"
|
label_template_edited: "Label template edited"
|
||||||
label_template_deleted: "Label template deleted"
|
label_template_deleted: "Label template deleted"
|
||||||
label_template_copied: "Label template copied"
|
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:
|
activity_group:
|
||||||
projects: "Projects"
|
projects: "Projects"
|
||||||
task_results: "Task results"
|
task_results: "Task results"
|
||||||
|
|
Loading…
Add table
Reference in a new issue