mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-12-17 14:19:05 +08:00
Add entity breadcrumbs to activity webhooks [SCI-9056] (#6056)
This commit is contained in:
parent
3c0389adc8
commit
9f23fe557a
4 changed files with 24 additions and 20 deletions
|
|
@ -14,6 +14,11 @@ class Activity < ApplicationRecord
|
||||||
change_user_role_on_my_module
|
change_user_role_on_my_module
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
|
# invert the children hash to get a hash defining parents
|
||||||
|
ACTIVITY_SUBJECT_PARENTS = Extends::ACTIVITY_SUBJECT_CHILDREN.invert.map do |k, v|
|
||||||
|
k&.map { |s| [s.to_s.classify, v.to_s.classify.constantize.reflect_on_association(s)&.inverse_of&.name || v] }
|
||||||
|
end.compact.sum.to_h.freeze
|
||||||
|
|
||||||
include ActivityValuesModel
|
include ActivityValuesModel
|
||||||
include GenerateNotificationModel
|
include GenerateNotificationModel
|
||||||
|
|
||||||
|
|
@ -127,6 +132,18 @@ class Activity < ApplicationRecord
|
||||||
result.join('&')
|
result.join('&')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def subject_parents
|
||||||
|
recursive_subject_parents(subject, []).compact
|
||||||
|
end
|
||||||
|
|
||||||
|
def recursive_subject_parents(activity_subject, parents)
|
||||||
|
parent_model_name = ACTIVITY_SUBJECT_PARENTS[activity_subject.class.name]
|
||||||
|
return parents if parent_model_name.nil?
|
||||||
|
|
||||||
|
parent = activity_subject.public_send(parent_model_name)
|
||||||
|
recursive_subject_parents(parent, parents << parent)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def generate_breadcrumb(subject)
|
def generate_breadcrumb(subject)
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,6 @@
|
||||||
|
|
||||||
module Activities
|
module Activities
|
||||||
class ActivityFilterMatchingService
|
class ActivityFilterMatchingService
|
||||||
# invert the children hash to get a hash defining parents
|
|
||||||
ACTIVITY_SUBJECT_PARENTS = Extends::ACTIVITY_SUBJECT_CHILDREN.invert.map do |k, v|
|
|
||||||
k&.map { |s| [s.to_s.classify, v.to_s.classify.constantize.reflect_on_association(s)&.inverse_of&.name || v] }
|
|
||||||
end.compact.sum.to_h.freeze
|
|
||||||
|
|
||||||
def initialize(activity)
|
def initialize(activity)
|
||||||
@activity = activity
|
@activity = activity
|
||||||
@activity_filters = ActivityFilter.all
|
@activity_filters = ActivityFilter.all
|
||||||
|
|
@ -60,7 +55,7 @@ module Activities
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_subjects!
|
def filter_subjects!
|
||||||
parents = activity_subject_parents
|
parents = @activity.subject_parents
|
||||||
|
|
||||||
@activity_filters = @activity_filters.where(
|
@activity_filters = @activity_filters.where(
|
||||||
"NOT(filter ? 'subjects') OR "\
|
"NOT(filter ? 'subjects') OR "\
|
||||||
|
|
@ -72,17 +67,5 @@ module Activities
|
||||||
end.join(' OR ')
|
end.join(' OR ')
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def activity_subject_parents
|
|
||||||
subject_parents(@activity.subject, []).compact
|
|
||||||
end
|
|
||||||
|
|
||||||
def subject_parents(subject, parents)
|
|
||||||
parent_model_name = ACTIVITY_SUBJECT_PARENTS[subject.class.name]
|
|
||||||
return parents if parent_model_name.nil?
|
|
||||||
|
|
||||||
parent = subject.public_send(parent_model_name)
|
|
||||||
subject_parents(parent, parents << parent)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,10 @@ module Activities
|
||||||
subject: {
|
subject: {
|
||||||
type: @activity.subject_type,
|
type: @activity.subject_type,
|
||||||
id: @activity.subject_id
|
id: @activity.subject_id
|
||||||
}
|
},
|
||||||
|
subject_breadcrumbs: @activity.subject_parents.map do |subject|
|
||||||
|
{ type: subject.model_name.human.downcase, id: subject.id }
|
||||||
|
end
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,8 @@ class Extends
|
||||||
repository_base: [:repository_rows],
|
repository_base: [:repository_rows],
|
||||||
repository_row: nil,
|
repository_row: nil,
|
||||||
report: nil,
|
report: nil,
|
||||||
project: nil,
|
team: [:projects],
|
||||||
|
project: [:experiments],
|
||||||
experiment: [:my_modules],
|
experiment: [:my_modules],
|
||||||
my_module: %i(results protocols),
|
my_module: %i(results protocols),
|
||||||
result: [:asset],
|
result: [:asset],
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue