This repository was archived by the owner on Jul 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff 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 ( /\A assigned_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 ( /\A groups?:([a-zA-Z0-9_\- ,]+)\z /i ) do |relation , groups_param , filter |
166194 if groups_param . include? ( "," )
167195 group_names = groups_param . split ( "," ) . map ( &:strip )
You can’t perform that action at this time.
0 commit comments