2022-06-14 11:07:02 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class DataExplorerQueryGroupBookmarkable < BaseBookmarkable
|
|
|
|
def self.model
|
|
|
|
DataExplorer::QueryGroup
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.serializer
|
|
|
|
UserDataExplorerQueryGroupBookmarkSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.preload_associations
|
2022-12-29 07:31:29 -05:00
|
|
|
%i[data_explorer_queries groups]
|
2022-06-14 11:07:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.list_query(user, guardian)
|
|
|
|
group_ids = []
|
|
|
|
if !user.admin?
|
|
|
|
group_ids = user.visible_groups.pluck(:id)
|
|
|
|
return if group_ids.empty?
|
|
|
|
end
|
|
|
|
|
2022-12-29 07:31:29 -05:00
|
|
|
query =
|
|
|
|
user
|
|
|
|
.bookmarks_of_type("DataExplorer::QueryGroup")
|
|
|
|
.joins(
|
|
|
|
"INNER JOIN data_explorer_query_groups ON data_explorer_query_groups.id = bookmarks.bookmarkable_id",
|
|
|
|
)
|
|
|
|
.joins(
|
|
|
|
"LEFT JOIN data_explorer_queries ON data_explorer_queries.id = data_explorer_query_groups.query_id",
|
|
|
|
)
|
2022-06-14 11:07:02 -04:00
|
|
|
query = query.where("data_explorer_query_groups.group_id IN (?)", group_ids) if !user.admin?
|
|
|
|
query
|
|
|
|
end
|
|
|
|
|
|
|
|
# Searchable only by data_explorer_queries name
|
|
|
|
def self.search_query(bookmarks, query, ts_query, &bookmarkable_search)
|
2022-12-29 07:31:29 -05:00
|
|
|
bookmarkable_search.call(bookmarks, "data_explorer_queries.name ILIKE :q")
|
2022-06-14 11:07:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.reminder_handler(bookmark)
|
2022-07-17 23:40:24 -04:00
|
|
|
send_reminder_notification(
|
|
|
|
bookmark,
|
2022-06-14 11:07:02 -04:00
|
|
|
data: {
|
|
|
|
title: bookmark.bookmarkable.query.name,
|
2022-12-29 07:31:29 -05:00
|
|
|
bookmarkable_url:
|
|
|
|
"/g/#{bookmark.bookmarkable.group.name}/reports/#{bookmark.bookmarkable.query.id}",
|
|
|
|
},
|
2022-06-14 11:07:02 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.reminder_conditions(bookmark)
|
|
|
|
bookmark.bookmarkable.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.can_see?(guardian, bookmark)
|
|
|
|
return false if !bookmark.bookmarkable.group
|
|
|
|
guardian.user_is_a_member_of_group?(bookmark.bookmarkable.group)
|
|
|
|
end
|
|
|
|
end
|