mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-30 19:48:18 +08:00
Task activities refactoring, without tests
This commit is contained in:
parent
7757096693
commit
c476816359
6 changed files with 92 additions and 227 deletions
|
@ -183,14 +183,13 @@ class CanvasController < ApplicationController
|
|||
to_archive.each do |module_id|
|
||||
my_module = MyModule.find_by_id(module_id)
|
||||
next if my_module.blank?
|
||||
Activity.create(type_of: :archive_module,
|
||||
project: my_module.experiment.project,
|
||||
experiment: my_module.experiment,
|
||||
my_module: my_module,
|
||||
user: current_user,
|
||||
message: t('activities.archive_module',
|
||||
user: current_user.full_name,
|
||||
module: my_module.name))
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: :archive_module,
|
||||
owner: current_user,
|
||||
team: my_module.experiment.project.team,
|
||||
project: my_module.experiment.project,
|
||||
subject: my_module,
|
||||
message_items: { my_module: @my_module.id })
|
||||
end
|
||||
|
||||
# Create workflow image
|
||||
|
|
|
@ -51,21 +51,8 @@ class MyModuleCommentsController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
if @comment.save
|
||||
|
||||
my_module_comment_annotation_notification
|
||||
# Generate activity
|
||||
Activity.create(
|
||||
type_of: :add_comment_to_module,
|
||||
user: current_user,
|
||||
project: @my_module.experiment.project,
|
||||
experiment: @my_module.experiment,
|
||||
my_module: @my_module,
|
||||
message: t(
|
||||
'activities.add_comment_to_module',
|
||||
user: current_user.full_name,
|
||||
module: @my_module.name
|
||||
)
|
||||
)
|
||||
log_activity(:add_comment_to_module)
|
||||
|
||||
format.json do
|
||||
render json: {
|
||||
|
@ -112,21 +99,9 @@ class MyModuleCommentsController < ApplicationController
|
|||
respond_to do |format|
|
||||
format.json do
|
||||
if @comment.save
|
||||
|
||||
my_module_comment_annotation_notification(old_text)
|
||||
# Generate activity
|
||||
Activity.create(
|
||||
type_of: :edit_module_comment,
|
||||
user: current_user,
|
||||
project: @my_module.experiment.project,
|
||||
experiment: @my_module.experiment,
|
||||
my_module: @my_module,
|
||||
message: t(
|
||||
'activities.edit_module_comment',
|
||||
user: current_user.full_name,
|
||||
module: @my_module.name
|
||||
)
|
||||
)
|
||||
log_activity(:edit_module_comment)
|
||||
|
||||
message = custom_auto_link(@comment.message, team: current_team)
|
||||
render json: { comment: message }, status: :ok
|
||||
else
|
||||
|
@ -141,19 +116,8 @@ class MyModuleCommentsController < ApplicationController
|
|||
respond_to do |format|
|
||||
format.json do
|
||||
if @comment.destroy
|
||||
# Generate activity
|
||||
Activity.create(
|
||||
type_of: :delete_module_comment,
|
||||
user: current_user,
|
||||
project: @my_module.experiment.project,
|
||||
experiment: @my_module.experiment,
|
||||
my_module: @my_module,
|
||||
message: t(
|
||||
'activities.delete_module_comment',
|
||||
user: current_user.full_name,
|
||||
module: @my_module.name
|
||||
)
|
||||
)
|
||||
log_activity(:delete_module_comment)
|
||||
|
||||
# 'counter' and 'linked_id' are used for counter badge
|
||||
render json: { linked_id: @my_module.id,
|
||||
counter: @my_module.task_comments.count },
|
||||
|
@ -217,4 +181,14 @@ class MyModuleCommentsController < ApplicationController
|
|||
)))
|
||||
)
|
||||
end
|
||||
|
||||
def log_activity(type_of)
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: type_of,
|
||||
owner: current_user,
|
||||
team: @my_module.experiment.project.team,
|
||||
project: @my_module.experiment.project,
|
||||
subject: @my_module,
|
||||
message_items: { my_module: @my_module.id })
|
||||
end
|
||||
end
|
||||
|
|
|
@ -162,54 +162,21 @@ class MyModulesController < ApplicationController
|
|||
saved = @my_module.archive(current_user)
|
||||
if saved
|
||||
# Currently not in use
|
||||
Activity.create(
|
||||
type_of: :archive_module,
|
||||
project: @my_module.experiment.project,
|
||||
experiment: @my_module.experiment,
|
||||
my_module: @my_module,
|
||||
user: current_user,
|
||||
message: t(
|
||||
'activities.archive_module',
|
||||
user: current_user.full_name,
|
||||
module: @my_module.name
|
||||
)
|
||||
)
|
||||
log_activity(:archive_module)
|
||||
end
|
||||
elsif @my_module.archived_changed?(from: true, to: false)
|
||||
|
||||
saved = @my_module.restore(current_user)
|
||||
if saved
|
||||
restored = true
|
||||
Activity.create(
|
||||
type_of: :restore_module,
|
||||
project: @my_module.experiment.project,
|
||||
experiment: @my_module.experiment,
|
||||
my_module: @my_module,
|
||||
user: current_user,
|
||||
message: t(
|
||||
'activities.restore_module',
|
||||
user: current_user.full_name,
|
||||
module: @my_module.name
|
||||
)
|
||||
)
|
||||
log_activity(:restore_module)
|
||||
end
|
||||
else
|
||||
saved = @my_module.save
|
||||
|
||||
if saved
|
||||
if description_changed
|
||||
Activity.create(
|
||||
type_of: :change_module_description,
|
||||
project: @my_module.experiment.project,
|
||||
experiment: @my_module.experiment,
|
||||
my_module: @my_module,
|
||||
user: current_user,
|
||||
message: t(
|
||||
'activities.change_module_description',
|
||||
user: current_user.full_name,
|
||||
module: @my_module.name
|
||||
)
|
||||
)
|
||||
log_activity(:change_module_description)
|
||||
end
|
||||
|
||||
if due_date_changes
|
||||
|
@ -337,21 +304,6 @@ class MyModulesController < ApplicationController
|
|||
my_module.samples.push(*new_samples)
|
||||
task_names << my_module.name
|
||||
end
|
||||
if new_samples.any?
|
||||
Activity.create(
|
||||
type_of: :assign_sample,
|
||||
project: @my_module.experiment.project,
|
||||
experiment: @my_module.experiment,
|
||||
my_module: @my_module,
|
||||
user: current_user,
|
||||
message: I18n.t(
|
||||
'activities.assign_sample',
|
||||
user: current_user.full_name,
|
||||
tasks: task_names.join(', '),
|
||||
samples: new_samples.map(&:name).join(', ')
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
redirect_to samples_my_module_path(@my_module)
|
||||
end
|
||||
|
@ -375,21 +327,6 @@ class MyModulesController < ApplicationController
|
|||
task_names << my_module.name
|
||||
my_module.samples.destroy(samples & my_module.samples)
|
||||
end
|
||||
if samples.any?
|
||||
Activity.create(
|
||||
type_of: :unassign_sample,
|
||||
project: @my_module.experiment.project,
|
||||
experiment: @my_module.experiment,
|
||||
my_module: @my_module,
|
||||
user: current_user,
|
||||
message: I18n.t(
|
||||
'activities.unassign_sample',
|
||||
user: current_user.full_name,
|
||||
tasks: task_names.join(', '),
|
||||
samples: samples.map(&:name).join(', ')
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
redirect_to samples_my_module_path(@my_module)
|
||||
end
|
||||
|
@ -484,19 +421,8 @@ class MyModulesController < ApplicationController
|
|||
|
||||
if records_names.any?
|
||||
records_names.uniq!
|
||||
Activity.create(
|
||||
type_of: :assign_repository_record,
|
||||
project: @project,
|
||||
experiment: @experiment,
|
||||
my_module: @my_module,
|
||||
user: current_user,
|
||||
message: I18n.t('activities.assign_repository_records',
|
||||
user: current_user.full_name,
|
||||
task: @my_module.name,
|
||||
repository: @repository.name,
|
||||
records: records_names.join(', ')
|
||||
)
|
||||
)
|
||||
log_activity_assign_unassign_records(:assign_repository_record,
|
||||
records_names)
|
||||
flash = I18n.t('repositories.assigned_records_flash',
|
||||
records: records_names.join(', '))
|
||||
flash = I18n.t('repositories.assigned_records_downstream_flash',
|
||||
|
@ -542,20 +468,8 @@ class MyModulesController < ApplicationController
|
|||
records.update_all(last_modified_by_id: current_user.id)
|
||||
|
||||
if records.any?
|
||||
Activity.create(
|
||||
type_of: :unassign_repository_record,
|
||||
project: @project,
|
||||
experiment: @experiment,
|
||||
my_module: @my_module,
|
||||
user: current_user,
|
||||
message: I18n.t(
|
||||
'activities.unassign_repository_records',
|
||||
user: current_user.full_name,
|
||||
task: @my_module.name,
|
||||
repository: @repository.name,
|
||||
records: records.map(&:name).join(', ')
|
||||
)
|
||||
)
|
||||
log_activity_assign_unassign_records(:unassign_repository_record,
|
||||
records.map(&:name))
|
||||
flash = I18n.t('repositories.unassigned_records_flash',
|
||||
records: records.map(&:name).join(', '))
|
||||
respond_to do |format|
|
||||
|
@ -663,19 +577,7 @@ class MyModulesController < ApplicationController
|
|||
|
||||
def task_completion_activity
|
||||
completed = @my_module.completed?
|
||||
str = 'activities.uncomplete_module'
|
||||
str = 'activities.complete_module' if completed
|
||||
message = t(str,
|
||||
user: current_user.full_name,
|
||||
module: @my_module.name)
|
||||
Activity.create(
|
||||
user: current_user,
|
||||
project: @project,
|
||||
experiment: @experiment,
|
||||
my_module: @my_module,
|
||||
message: message,
|
||||
type_of: completed ? :complete_task : :uncomplete_task
|
||||
)
|
||||
log_activity(completed ? :complete_task : :uncomplete_task)
|
||||
start_work_on_next_task_notification
|
||||
end
|
||||
|
||||
|
@ -760,4 +662,26 @@ class MyModulesController < ApplicationController
|
|||
params.require(:my_module).permit(:name, :description, :due_date,
|
||||
:archived)
|
||||
end
|
||||
|
||||
def log_activity(type_of)
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: type_of,
|
||||
owner: current_user,
|
||||
team: @my_module.experiment.project.team,
|
||||
project: @my_module.experiment.project,
|
||||
subject: @my_module,
|
||||
message_items: { my_module: @my_module.id })
|
||||
end
|
||||
|
||||
def log_activity_assign_unassign_records(type_of, records_names)
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: type_of,
|
||||
owner: current_user,
|
||||
team: @my_module.experiment.project.team,
|
||||
project: @my_module.experiment.project,
|
||||
subject: @my_module,
|
||||
message_items: { my_module: @my_module.id,
|
||||
repository: @repository.id,
|
||||
record_names: records_names.join(', ') })
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,21 +40,8 @@ class UserMyModulesController < ApplicationController
|
|||
@um = UserMyModule.new(um_params.merge(my_module: @my_module))
|
||||
@um.assigned_by = current_user
|
||||
if @um.save
|
||||
# Create activity
|
||||
message = t(
|
||||
'activities.assign_user_to_module',
|
||||
assigned_user: @um.user.full_name,
|
||||
module: @my_module.name,
|
||||
assigned_by_user: current_user.full_name
|
||||
)
|
||||
Activity.create(
|
||||
user: current_user,
|
||||
project: @um.my_module.experiment.project,
|
||||
experiment: @um.my_module.experiment,
|
||||
my_module: @um.my_module,
|
||||
message: message,
|
||||
type_of: :assign_user_to_module
|
||||
)
|
||||
log_activity(:assign_user_to_module)
|
||||
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
redirect_to my_module_users_edit_path(format: :json),
|
||||
|
@ -75,22 +62,7 @@ class UserMyModulesController < ApplicationController
|
|||
|
||||
def destroy
|
||||
if @um.destroy
|
||||
# Create activity
|
||||
message = t(
|
||||
"activities.unassign_user_from_module",
|
||||
unassigned_user: @um.user.full_name,
|
||||
module: @my_module.name,
|
||||
unassigned_by_user: current_user.full_name
|
||||
)
|
||||
|
||||
Activity.create(
|
||||
user: current_user,
|
||||
project: @um.my_module.experiment.project,
|
||||
experiment: @um.my_module.experiment,
|
||||
my_module: @um.my_module,
|
||||
message: message,
|
||||
type_of: :unassign_user_from_module
|
||||
)
|
||||
log_activity(:unassign_user_from_module)
|
||||
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
|
@ -144,4 +116,15 @@ class UserMyModulesController < ApplicationController
|
|||
def um_params
|
||||
params.require(:user_my_module).permit(:user_id, :my_module_id)
|
||||
end
|
||||
|
||||
def log_activity(type_of)
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: type_of,
|
||||
owner: current_user,
|
||||
team: @um.my_module.experiment.project.team,
|
||||
project: @um.my_module.experiment.project,
|
||||
subject: @um.my_module,
|
||||
message_items: { my_module: @my_module.id,
|
||||
user_target: @um.user.id })
|
||||
end
|
||||
end
|
||||
|
|
|
@ -146,28 +146,20 @@ class Experiment < ApplicationRecord
|
|||
rename_modules(to_rename, current_user)
|
||||
|
||||
# Add activities that modules were created
|
||||
originals.each do |m|
|
||||
Activity.create(type_of: :create_module,
|
||||
user: current_user,
|
||||
project: project,
|
||||
experiment: m.experiment,
|
||||
my_module: m,
|
||||
message: I18n.t('activities.create_module',
|
||||
user: current_user.full_name,
|
||||
module: m.name))
|
||||
originals.each do |my_module|
|
||||
log_activity(:create_module, current_user, my_module)
|
||||
end
|
||||
|
||||
# Add activities that modules were cloned
|
||||
cloned_pairs.each do |mn, mo|
|
||||
Activity.create(type_of: :clone_module,
|
||||
project: mn.experiment.project,
|
||||
experiment: mn.experiment,
|
||||
my_module: mn,
|
||||
user: current_user,
|
||||
message: I18n.t('activities.clone_module',
|
||||
user: current_user.full_name,
|
||||
module_new: mn.name,
|
||||
module_original: mo.name))
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: :clone_module,
|
||||
owner: current_user,
|
||||
team: project.team,
|
||||
project: mn.experiment.project,
|
||||
subject: mn,
|
||||
message_items: { my_module_original: mo.id,
|
||||
my_module_new: mn.id })
|
||||
end
|
||||
|
||||
# Then, archive modules that need to be archived
|
||||
|
@ -263,17 +255,9 @@ class Experiment < ApplicationRecord
|
|||
# Archive all modules. Receives an array of module integer IDs
|
||||
# and current user.
|
||||
def archive_modules(module_ids, current_user)
|
||||
my_modules.where(id: module_ids).each do |m|
|
||||
m.archive!(current_user)
|
||||
|
||||
Activities::CreateActivityService.call(activity_type: :archive_task,
|
||||
owner: current_user,
|
||||
subject: m,
|
||||
project: project,
|
||||
team: project.team,
|
||||
message_items: {
|
||||
my_module: m.id
|
||||
})
|
||||
my_modules.where(id: module_ids).each do |my_module|
|
||||
my_module.archive!(current_user)
|
||||
log_activity(:archive_task, current_user, my_module)
|
||||
end
|
||||
my_modules.reload
|
||||
end
|
||||
|
@ -321,14 +305,7 @@ class Experiment < ApplicationRecord
|
|||
if my_module.present?
|
||||
my_module.name = new_name
|
||||
my_module.save!
|
||||
Activities::CreateActivityService.call(activity_type: :rename_task,
|
||||
owner: current_user,
|
||||
subject: my_module,
|
||||
project: project,
|
||||
team: project.team,
|
||||
message_items: {
|
||||
my_module: my_module.id
|
||||
})
|
||||
log_activity(:rename_task, current_user, my_module)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -618,4 +595,14 @@ class Experiment < ApplicationRecord
|
|||
rescue
|
||||
false
|
||||
end
|
||||
|
||||
def log_activity(type_of, current_user, my_module)
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: type_of,
|
||||
owner: current_user,
|
||||
team: my_module.experiment.project.team,
|
||||
project: my_module.experiment.project,
|
||||
subject: my_module,
|
||||
message_items: { my_module: my_module.id })
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1334,10 +1334,8 @@ en:
|
|||
change_module_description: "<i>%{user}</i> changed task <strong>%{module}</strong>'s description."
|
||||
complete_module: "<i>%{user}</i> completed task <strong>%{module}</strong>."
|
||||
uncomplete_module: "<i>%{user}</i> uncompleted task <strong>%{module}</strong>."
|
||||
assign_sample: "<i>%{user}</i> assigned sample(s) <strong>%{samples}</strong> to task(s) <strong>%{tasks}</strong>"
|
||||
unassign_sample: "<i>%{user}</i> unassigned sample(s) <strong>%{samples}</strong> from task(s) <strong>%{tasks}</strong>"
|
||||
assign_repository_records: "<i>%{user}</i> assigned item(s) <strong>%{records}</strong> from <strong>%{repository}</strong> inventory to task <strong>%{task}</strong>"
|
||||
unassign_repository_records: "<i>%{user}</i> unassigned item(s) <strong>%{records}</strong> from <strong>%{repository}</strong> inventory from task <strong>%{task}</strong>"
|
||||
assign_repository_records: "<i>%{user}</i> assigned item(s) <strong>%{record_names}</strong> from <strong>%{repository}</strong> inventory to task <strong>%{my_module}</strong>"
|
||||
unassign_repository_records: "<i>%{user}</i> unassigned item(s) <strong>%{record_names}</strong> from <strong>%{repository}</strong> inventory from task <strong>%{my_module}</strong>"
|
||||
create_step: "<i>%{user}</i> created Step %{step} <strong>%{step_name}</strong>."
|
||||
destroy_step: "<i>%{user}</i> deleted Step %{step} <strong>%{step_name}</strong>."
|
||||
add_comment_to_step: "<i>%{user}</i> commented on Step %{step} <strong>%{step_name}</strong>."
|
||||
|
|
Loading…
Reference in a new issue