Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit f1cf272

Browse files
committed
FEATURE: allow access to assigns from forum researcher
1 parent 1fb358a commit f1cf272

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lib/utils/research/filter.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,34 @@ def self.word_to_date(str)
162162
end
163163
end
164164

165+
def self.assign_allowed?(guardian)
166+
SiteSetting.respond_to?(:assign_enabled) && SiteSetting.assign_enabled &&
167+
(guardian.can_assign? || SiteSetting.assigns_public)
168+
end
169+
170+
register_filter(/\Aassigned_to:(.+)\z/i) do |relation, name, filter|
171+
if assign_allowed?(filter.guardian)
172+
raise Discourse::InvalidAccess.new(
173+
"Assigns are not enabled or you do not have permission to see assigns.",
174+
)
175+
end
176+
177+
if (name == "nobody")
178+
relation.joins("LEFT JOIN assignments a ON a.topic_id = topics.id AND a.active").where(
179+
"a.assigned_to_id IS NULL",
180+
)
181+
elsif name == "*"
182+
relation.joins("JOIN assignments a ON a.topic_id = topics.id AND a.active").where(
183+
"a.assigned_to_id IS NOT NULL",
184+
)
185+
else
186+
usernames = name.split(",").map(&:strip).map(&:downcase)
187+
relation.joins("JOIN assignments a ON a.topic_id = topics.id AND a.active").where(
188+
assigned_to_id: User.where(username_lower: usernames).select(:id),
189+
)
190+
end
191+
end
192+
165193
register_filter(/\Agroups?:([a-zA-Z0-9_\-,]+)\z/i) do |relation, groups_param, filter|
166194
if groups_param.include?(",")
167195
group_names = groups_param.split(",").map(&:strip)

0 commit comments

Comments
 (0)