diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index 4eff3d8c6..1ab3f1eab 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -17,6 +17,7 @@ class TagsController < ApplicationController
end
if @tag.save
+ log_activity(:create_tag, @tag.project, tag: @tag.id, project: @tag.project.id)
if params.include? "my_module_id"
# Assign the tag to the specified module
new_mmt = MyModuleTag.new(
@@ -25,17 +26,8 @@ class TagsController < ApplicationController
new_mmt.save
my_module = new_mmt.my_module
- Activities::CreateActivityService
- .call(activity_type: :add_task_tag,
- owner: current_user,
- subject: my_module,
- project:
- my_module.experiment.project,
- team: current_team,
- message_items: {
- my_module: my_module.id,
- tag: @tag.id
- })
+
+ log_activity(:add_task_tag, my_module, tag: @tag.id, my_module: my_module.id)
end
flash_success = t(
@@ -82,6 +74,7 @@ class TagsController < ApplicationController
def update
@tag.last_modified_by = current_user
if @tag.update_attributes(tag_params)
+ log_activity(:edit_tag, @tag.project, tag: @tag.id, project: @tag.project.id)
respond_to do |format|
format.html
format.json do
@@ -103,6 +96,7 @@ class TagsController < ApplicationController
end
def destroy
+ log_activity(:delete_tag, @tag.project, tag: @tag.id, project: @tag.project.id)
if @tag.destroy
flash_success = t(
"tags.destroy.success_flash",
@@ -166,4 +160,14 @@ class TagsController < ApplicationController
def tag_params
params.require(:tag).permit(:name, :color, :project_id)
end
+
+ def log_activity(type_of, subject = nil, message_items = {})
+ Activities::CreateActivityService
+ .call(activity_type: type_of,
+ owner: current_user,
+ subject: subject,
+ team: current_team,
+ project: @tag.project,
+ message_items: message_items)
+ end
end
diff --git a/config/initializers/extends.rb b/config/initializers/extends.rb
index 5e853a6ea..92ea5213b 100644
--- a/config/initializers/extends.rb
+++ b/config/initializers/extends.rb
@@ -178,7 +178,7 @@ class Extends
change_task_due_date: 62,
remove_task_due_date: 63,
add_task_tag: 64,
- edit_task_tag: 65,
+ edit_tag: 65,
remove_task_tag: 66, # 67, 68, 69 are in addons
create_inventory: 70,
rename_inventory: 71,
@@ -214,13 +214,15 @@ class Extends
copy_protocol_in_repository: 103,
user_leave_team: 104,
copy_inventory: 105,
- export_protocol_from_task: 106
+ export_protocol_from_task: 106,
+ create_tag: 108,
+ delete_tag: 109
}
ACTIVITY_GROUPS = {
- projects: [*0..7, 32, 33, 34, 95],
+ projects: [*0..7, 32, 33, 34, 95, 108, 65, 109],
task_results: [23, 26, 25, 42, 24, 40, 41, 99],
- task: [8, 58, 9, 59, 10, 11, 12, 13, 14, 35, 36, 37, 53, 54, *60..69, 106],
+ task: [8, 58, 9, 59, 10, 11, 12, 13, 14, 35, 36, 37, 53, 54, *60..64, *66..69, 106],
task_protocol: [15, 22, 16, 18, 19, 20, 21, 17, 38, 39, 100, 45, 46, 47],
task_inventory: [55, 56],
experiment: [*27..31, 57],
diff --git a/config/locales/global_activities/en.yml b/config/locales/global_activities/en.yml
index b61850158..02765cc33 100644
--- a/config/locales/global_activities/en.yml
+++ b/config/locales/global_activities/en.yml
@@ -127,6 +127,10 @@ en:
change_users_role_on_team_html: "%{user} changed user %{user_changed}'s role in team %{team} to %{role}."
export_projects_html: "%{user} exported project(s) %{projects} to .zip."
export_inventory_items_html: "%{user} exported inventory item(s) from %{repository}."
+ create_tag_html: "%{user} created tag %{tag} in project %{project}."
+ edit_tag_html: "%{user} edited tag %{tag} in project %{project}."
+ delete_tag_html: "%{user} deleted tag %{tag} in project %{project}."
+
activity_name:
create_project: "Project created"
rename_project: "Project renamed"
@@ -192,7 +196,6 @@ en:
change_task_due_date: "Task due date changed"
remove_task_due_date: "Task due date removed"
add_task_tag: "Task tag added"
- edit_task_tag: "Task tag edited"
remove_task_tag: "Task tag removed"
create_inventory: "Inventory created"
rename_inventory: "Inventory renamed"
@@ -225,6 +228,10 @@ en:
user_leave_team: "User left team"
export_projects: "Projects exported"
export_inventory_items: "Inventory items exported"
+ create_tag: "Tag created"
+ edit_tag: "Tag edited"
+ delete_tag: "Tag deleted"
+
activity_group:
projects: "Projects"
task_results: "Task results"
diff --git a/spec/controllers/tags_controller_spec.rb b/spec/controllers/tags_controller_spec.rb
index 3b0794fe4..d4833cb6c 100644
--- a/spec/controllers/tags_controller_spec.rb
+++ b/spec/controllers/tags_controller_spec.rb
@@ -14,10 +14,10 @@ describe TagsController, type: :controller do
end
let(:experiment) { create :experiment, project: project }
let(:my_module) { create :my_module, experiment: experiment }
+ let(:tag) { create :tag, project: project }
describe 'POST create' do
let(:action) { post :create, params: params, format: :json }
- let(:tag) { create :tag, project: project }
let(:params) do
{
my_module_id: my_module.id,
@@ -28,7 +28,10 @@ describe TagsController, type: :controller do
}
end
- it 'calls create activity for adding task tag' do
+ it 'calls create activity for create tag' do
+ expect(Activities::CreateActivityService)
+ .to(receive(:call)
+ .with(hash_including(activity_type: :create_tag)))
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :add_task_tag)))
@@ -40,4 +43,50 @@ describe TagsController, type: :controller do
.to(change { Activity.count })
end
end
+
+ describe 'PUT update' do
+ let(:action) do
+ put :update, params: {
+ project_id: tag.project.id,
+ id: tag.id,
+ my_module_id: my_module.id,
+ tag: { name: 'Name2' }
+ }, format: :json
+ end
+
+ it 'calls create activity for edit tag' do
+ expect(Activities::CreateActivityService)
+ .to(receive(:call)
+ .with(hash_including(activity_type: :edit_tag)))
+ action
+ end
+
+ it 'adds activity in DB' do
+ expect { action }
+ .to(change { Activity.count })
+ end
+ end
+
+ describe 'DELETE destroy' do
+ let(:action) do
+ delete :destroy, params: {
+ project_id: tag.project.id,
+ id: tag.id,
+ my_module_id: my_module.id,
+ format: :json
+ }
+ end
+
+ it 'calls create activity for delete tag' do
+ expect(Activities::CreateActivityService)
+ .to(receive(:call)
+ .with(hash_including(activity_type: :delete_tag)))
+ action
+ end
+
+ it 'adds activity in DB' do
+ expect { action }
+ .to(change { Activity.count })
+ end
+ end
end