Add activities for status change

This commit is contained in:
Urban Rotnik 2020-08-04 16:40:06 +02:00
parent d8378f4bc4
commit 581cd69963
4 changed files with 21 additions and 8 deletions

View file

@ -266,13 +266,15 @@ class MyModulesController < ApplicationController
new_status = @my_module.my_module_status_flow.my_module_statuses.find_by(id: update_status_params[:status_id])
return render_404 unless new_status
old_status_id = @my_module.my_module_status_id
@my_module.update(my_module_status: new_status)
render json: { content: render_to_string(
partial: 'my_modules/status_flow/task_flow_button.html.erb',
locals: { my_module: @my_module })
}, status: :ok
log_activity(:change_status_on_task_flow, @my_module, my_module_status_old: old_status_id,
my_module_status_new: @my_module.my_module_status.id)
render json: { content: render_to_string(
partial: 'my_modules/status_flow/task_flow_button.html.erb', locals: { my_module: @my_module }
) }, status: :ok
end
private

View file

@ -143,8 +143,11 @@ class Extends
step: nil
}
ACTIVITY_MESSAGE_ITEMS_TYPES = ACTIVITY_SUBJECT_TYPES + %w(User Tag RepositoryColumn RepositoryRow Step
Asset TinyMceAsset Repository RepositorySnapshot).freeze
ACTIVITY_MESSAGE_ITEMS_TYPES =
ACTIVITY_SUBJECT_TYPES + %w(
User Tag RepositoryColumn RepositoryRow Step Asset TinyMceAsset Repository MyModuleStatus RepositorySnapshot
).freeze
ACTIVITY_TYPES = {
create_project: 0,
@ -288,13 +291,15 @@ class Extends
archive_inventory: 144,
restore_inventory: 145,
export_inventory_items_assigned_to_task: 146,
export_inventory_snapshot_items_assigned_to_task: 147
export_inventory_snapshot_items_assigned_to_task: 147,
change_status_on_task_flow: 148 # 149, 150, 151 in AdddOn!
}
ACTIVITY_GROUPS = {
projects: [*0..7, 32, 33, 34, 95, 108, 65, 109],
task_results: [23, 26, 25, 42, 24, 40, 41, 99, 110, 122, 116, 128],
task: [8, 58, 9, 59, *10..14, 35, 36, 37, 53, 54, *60..63, 138, 139, 140, 64, *66..69, 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],
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_inventory: [55, 56],
experiment: [*27..31, 57],

View file

@ -175,6 +175,7 @@ en:
protocol_description_in_task_edited_html: "%{user} edited protocol description on task %{my_module}."
export_inventory_items_assigned_to_task_html: "%{user} exported inventory item(s) assigned to task %{my_module} from inventory %{repository}: Live version."
export_inventory_snapshot_items_assigned_to_task_html: "%{user} exported inventory item(s) assigned to task %{my_module} from inventory %{repository_snapshot}: Snapshot of %{created_at}."
change_status_on_task_flow_html: "%{user} changed status from <strong>%{my_module_status_old}</strong> to <strong>%{my_module_status_new}</strong> for task %{my_module}."
activity_name:
create_project: "Project created"
@ -315,6 +316,7 @@ en:
protocol_description_in_task_edited: "Protocol description in task edited"
export_inventory_items_assigned_to_task: "Task-assigned inventory items exported (live version)"
export_inventory_snapshot_items_assigned_to_task: "Task-assigned inventory items exported (snapshot)"
change_status_on_task_flow: "Task status changed"
activity_group:
projects: "Projects"

View file

@ -147,6 +147,10 @@ describe MyModulesController, type: :controller do
expect(my_module.reload.my_module_status.id).to be_eql(status_id)
expect(response).to have_http_status 200
end
it 'creates activity' do
expect { action }.to(change { Activity.all.count }.by(1))
end
end
context 'when status not found' do