mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-04 03:36:44 +08:00
Fixed handling of activity subject parents when matching activity filters [SCI-5973]
This commit is contained in:
parent
04e58740d8
commit
8f3f39f7c7
3 changed files with 31 additions and 3 deletions
|
@ -2,6 +2,11 @@
|
||||||
|
|
||||||
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.singularize.camelize, 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
|
||||||
|
@ -46,10 +51,29 @@ module Activities
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_subjects!
|
def filter_subjects!
|
||||||
|
parents = activity_subject_parents
|
||||||
|
|
||||||
@activity_filters = @activity_filters.where(
|
@activity_filters = @activity_filters.where(
|
||||||
"NOT(filter ? 'subjects') OR "\
|
"NOT(filter ? 'subjects') OR "\
|
||||||
"filter -> 'subjects' -> '#{@activity.subject_type}' @> '\"#{@activity.subject_id}\"'"
|
"filter -> 'subjects' -> 'Project' @> '\"#{@activity.project_id}\"' OR "\
|
||||||
|
"filter -> 'subjects' -> '#{@activity.subject_type}' @> '\"#{@activity.subject_id}\"'" +
|
||||||
|
(parents.any? ? ' OR ' : '') +
|
||||||
|
parents.map do |subject|
|
||||||
|
"filter -> 'subjects' -> '#{subject.class}' @> '\"#{subject.id}\"'"
|
||||||
|
end.join(' OR ')
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def activity_subject_parents
|
||||||
|
subject_parents(@activity.subject, [])
|
||||||
|
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
|
||||||
|
|
|
@ -14,7 +14,11 @@ module Activities
|
||||||
def activity_payload
|
def activity_payload
|
||||||
@activity.values.merge(
|
@activity.values.merge(
|
||||||
type: @activity.type_of,
|
type: @activity.type_of,
|
||||||
created_at: @activity.created_at
|
created_at: @activity.created_at,
|
||||||
|
subject: {
|
||||||
|
type: @activity.subject_type,
|
||||||
|
id: @activity.subject_id
|
||||||
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,7 +23,7 @@ class WebhookService
|
||||||
@webhook.url,
|
@webhook.url,
|
||||||
{
|
{
|
||||||
headers: { 'Content-Type' => 'application/json' },
|
headers: { 'Content-Type' => 'application/json' },
|
||||||
body: @payload
|
body: @payload.to_json
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue