mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-14 09:04:56 +08:00
Add activities for item relationships [SCI-9718] (#6788)
This commit is contained in:
parent
184944dd5f
commit
5ca33bb96a
4 changed files with 56 additions and 6 deletions
|
@ -36,7 +36,7 @@ class RepositoryRowConnectionsController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
# Filtter exixting relations from params
|
||||
# Filter existing relations from params
|
||||
relation_ids = connection_params[:relation_ids].map(&:to_i) -
|
||||
@repository_row.public_send("#{@relation}_connections").pluck("#{@relation}_id") -
|
||||
[@repository_row.id]
|
||||
|
@ -48,6 +48,12 @@ class RepositoryRowConnectionsController < ApplicationController
|
|||
"#{@relation}": row
|
||||
}
|
||||
@repository_row.public_send("#{@relation}_connections").build attributes
|
||||
|
||||
log_activity(:inventory_item_relationships_linked,
|
||||
@repository_row.repository,
|
||||
{ inventory_item: @repository_row.name,
|
||||
linked_inventory_item: row.name,
|
||||
relationship_type: @relation })
|
||||
end
|
||||
@repository_row.save!
|
||||
end
|
||||
|
@ -73,9 +79,20 @@ class RepositoryRowConnectionsController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
connection = @repository_row.parent_connections.or(@repository_row.child_connections).find(params[:id])
|
||||
connection.destroy
|
||||
head :no_content
|
||||
RepositoryRowConnection.transaction do
|
||||
connection = @repository_row.parent_connections.or(@repository_row.child_connections).find(params[:id])
|
||||
unlinked_item = connection.parent?(@repository_row) ? connection.child : connection.parent
|
||||
|
||||
log_activity(:inventory_item_relationships_unlinked,
|
||||
@repository_row.repository,
|
||||
{ inventory_item: @repository_row.name,
|
||||
unlinked_inventory_item: unlinked_item.name })
|
||||
|
||||
connection.destroy!
|
||||
head :no_content
|
||||
rescue StandardError
|
||||
head :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def repositories
|
||||
|
@ -136,4 +153,15 @@ class RepositoryRowConnectionsController < ApplicationController
|
|||
def connection_params
|
||||
params.require(:repository_row_connection).permit(:connection_repository_id, :relation, relation_ids: [])
|
||||
end
|
||||
|
||||
def log_activity(type_of, repository, message_items = {})
|
||||
message_items = { repository: repository.id }.merge(message_items)
|
||||
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: type_of,
|
||||
owner: current_user,
|
||||
subject: repository,
|
||||
team: repository.team,
|
||||
message_items: message_items)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,4 +26,20 @@ class RepositoryRowConnection < ApplicationRecord
|
|||
errors.add(:base, 'Reciprocal connections are not allowed')
|
||||
end
|
||||
end
|
||||
|
||||
def parent?(repository_row)
|
||||
parent_id == repository_row.id
|
||||
end
|
||||
|
||||
def child?(repository_row)
|
||||
child_id == repository_row.id
|
||||
end
|
||||
|
||||
def relationship_type(repository_row)
|
||||
return :parent if parent?(repository_row)
|
||||
|
||||
return :child if child?(repository_row)
|
||||
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -492,7 +492,9 @@ class Extends
|
|||
export_inventories: 293,
|
||||
edit_image_on_inventory_item: 294,
|
||||
edit_wopi_file_on_inventory_item: 295,
|
||||
export_inventory_stock_consumption: 296
|
||||
export_inventory_stock_consumption: 296,
|
||||
inventory_item_relationships_linked: 297,
|
||||
inventory_item_relationships_unlinked: 298
|
||||
}
|
||||
|
||||
ACTIVITY_GROUPS = {
|
||||
|
@ -506,7 +508,7 @@ class Extends
|
|||
experiment: [*27..31, 57, 141, 165],
|
||||
reports: [48, 50, 49, 163, 164],
|
||||
inventories: [70, 71, 105, 144, 145, 72, 73, 74, 102, 142, 143, 75, 76, 77,
|
||||
78, 96, 107, 113, 114, *133..136, 180, 181, 182, *292..296],
|
||||
78, 96, 107, 113, 114, *133..136, 180, 181, 182, *292..298],
|
||||
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,
|
||||
190, 191, *204..215, 220, 223, 227, 228, 229, *230..235,
|
||||
|
|
|
@ -155,6 +155,8 @@ en:
|
|||
edit_item_inventory_html: "%{user} edited inventory item %{repository_row}."
|
||||
delete_item_inventory_html: "%{user} deleted inventory item %{repository_row}."
|
||||
edit_item_field_inventory_html: "%{user} edited %{repository_column} on inventory item %{repository_row}."
|
||||
inventory_item_relationships_linked_html: "%{user} link %{repository_row1} as a %{relationship_type} to %{repository_row2}."
|
||||
inventory_item_relationships_unlinked_html: "%{user} unlinked %{repository_row1} and %{repository_row2}."
|
||||
archive_inventory_item_html: "%{user} archived inventory item %{repository_row}."
|
||||
restore_inventory_item_html: "%{user} restored inventory item %{repository_row}."
|
||||
create_column_inventory_html: "%{user} created column %{repository_column} in inventory %{repository}."
|
||||
|
@ -426,6 +428,8 @@ en:
|
|||
create_item_inventory: "Inventory item created"
|
||||
edit_item_inventory: "Inventory item edited"
|
||||
edit_item_field_inventory: "Inventory item field edited"
|
||||
inventory_item_relationships_linked: "Inventory item relationships linked"
|
||||
inventory_item_relationships_unlinked: "Inventory item relationships unlinked"
|
||||
delete_item_inventory: "Inventory item deleted"
|
||||
archive_inventory_item: "Inventory item archived"
|
||||
restore_inventory_item: "Inventory item restored"
|
||||
|
|
Loading…
Add table
Reference in a new issue