@@ -41,6 +41,19 @@ def _tick_tock(task: px.WorkTask) -> None:
4141 task .advance (step = 1 )
4242
4343
44+ def get_group_users (guids : list [_types .ObjectIdentifier ], users_profiles : list [dict ]):
45+ users = []
46+ for guid in guids :
47+ for user in users_profiles :
48+ if guid in user ["assignedGroups" ]:
49+ users .append (user ["header" ])
50+
51+ if guid in user ["inheritedGroups" ]:
52+ users .append (user ["header" ])
53+
54+ return users
55+
56+
4457app = AsyncTyper (
4558 help = """
4659 Manage stale answers and liveboards within your platform.
@@ -156,7 +169,7 @@ def identify(
156169
157170 SEARCH_TOKENS = (
158171 # SELECT TS: BI ACTIVITY ON ANY ACTIVITY WITH A QUERY
159- "[query text] != '{null}' "
172+ # "[query text] != '{null}' "
160173 # FILTER OUT AD-HOC SEARCH
161174 "[user action] != [user action].answer_unsaved "
162175 # FILTER OUT POTENTIAL DATA QUALITY ISSUES ? (just here for safety~)
@@ -187,22 +200,67 @@ def identify(
187200 if only_groups or ignore_groups :
188201 c = ts .api .groups_search_v1 ()
189202 r = utils .run_sync (c )
190- _ = r .json ()
191-
192- # c = workflows.paginator(ts.api.groups_search, record_size=150_000, timeout=60 * 15)
193- # d = utils.run_sync(c)
203+ d = r .json ()
194204
205+ # Inline with V1 Group API.
195206 all_groups = [
196207 {
197- "guid" : group ["id" ],
198- "name" : group ["name" ],
199- "users" : group ["users" ],
208+ "guid" : group ["header" ]["id" ],
209+ "name" : group ["header" ]["name" ],
200210 }
201211 for group in d
202212 ]
203213
204- only_groups = [group ["guid" ] for group in all_groups if group ["name" ] in (only_groups or [])] # type: ignore[assignment]
205- ignore_groups = [group ["guid" ] for group in all_groups if group ["name" ] in (ignore_groups or [])] # type: ignore[assignment]
214+ # c = workflows.paginator(ts.api.groups_search, record_size=150_000, timeout=60 * 15)
215+ # d = utils.run_sync(c)
216+
217+ # all_groups = [
218+ # {
219+ # "guid": group["id"],
220+ # "name": group["name"],
221+ # "users": group["users"],
222+ # }
223+ # for group in d
224+ # ]
225+
226+ only_groups_lst = [group ["guid" ] for group in all_groups if group ["name" ] in (only_groups or [])] # type: ignore[assignment]
227+ ignore_groups_lst = [group ["guid" ] for group in all_groups if group ["name" ] in (ignore_groups or [])] # type: ignore[assignment]
228+
229+ if only_groups is not None :
230+ users_profiles : list = []
231+ for guid in only_groups_lst :
232+ c = ts .api .group_list_users (group_guid = guid )
233+ r = r = utils .run_sync (c )
234+ users = r .json ()
235+ if not users :
236+ # Exception needs to be redone
237+ info = {
238+ "reason" : "Group names are case sensitive. "
239+ + "You can find a group's 'Group Name' in the Admin panel." ,
240+ "mitigation" : "Verify the name and try again." ,
241+ "type" : "Group" ,
242+ }
243+ raise Exception (str (info )) from None
244+ users_profiles .extend (users )
245+ users_only = [user ["id" ] for user in get_group_users (only_groups_lst , users_profiles )]
246+
247+ if ignore_groups is not None :
248+ users_profiles : list = []
249+ for guid in ignore_groups_lst :
250+ c = ts .api .group_list_users (group_guid = guid )
251+ r = utils .run_sync (c )
252+ users = r .json ()
253+ if not users :
254+ info = {
255+ "reason" : "Group names are case sensitive. "
256+ + "You can find a group's 'Group Name' in the Admin panel." ,
257+ "mitigation" : "Verify the name and try again." ,
258+ "type" : "Group" ,
259+ }
260+ raise Exception (str (info )) from None
261+ users_profiles .extend (users )
262+
263+ users_ignore = [user ["id" ] for user in get_group_users (ignore_groups_lst , users_profiles )]
206264
207265 if ignore_tags :
208266 c = workflows .metadata .fetch_all (metadata_types = ["TAG" ], http = ts .api )
@@ -259,18 +317,18 @@ def identify(
259317 # CHECK: THE AUTHOR IS A MEMBER OF GROUPS WHOSE CONTENT SHOULD NEEDS TO INCLUDED.
260318 if only_groups is not None :
261319 assert isinstance (only_groups , list ), "Only Groups wasn't properly transformed to an array<GUID>."
262- checks .append (metadata_object ["author_guid" ] in only_groups )
320+ checks .append (metadata_object ["author_guid" ] in users_only )
263321
264322 # CHECK: THE AUTHOR IS NOT A MEMBER OF GROUPS WHOSE CONTENT SHOULD BE IGNORED.
265323 if ignore_groups is not None :
266324 assert isinstance (
267325 ignore_groups , list
268326 ), "Ignore Groups wasn't properly transformed to an array<GUID>."
269- checks .append (metadata_object ["author_guid" ] not in ignore_groups )
327+ checks .append (metadata_object ["author_guid" ] not in users_ignore )
270328
271329 if ignore_tags is not None :
272330 assert isinstance (ignore_tags , list ), "Ignore Tags wasn't properly transformed to an array<GUID>."
273- checks .append (any (t ["id" ] not in ignore_tags for t in metadata_object ["tags" ]))
331+ checks .append (not any (t ["id" ] in ignore_tags for t in metadata_object ["tags" ]))
274332
275333 if all (checks ):
276334 filtered .append (metadata_object )
0 commit comments