11"""Contains cog classes for tracking committee-actions."""
22
3+ import contextlib
34import logging
45import random
56from enum import Enum
1112
1213from db .core .models import AssignedCommitteeAction , DiscordMember
1314from exceptions import (
15+ CommitteeElectRoleDoesNotExistError ,
1416 CommitteeRoleDoesNotExistError ,
1517 InvalidActionDescriptionError ,
1618 InvalidActionTargetError ,
@@ -129,11 +131,22 @@ async def autocomplete_get_committee_members(
129131 except CommitteeRoleDoesNotExistError :
130132 return set ()
131133
134+ committee_elect_role : discord .Role | None = None
135+ with contextlib .suppress (CommitteeElectRoleDoesNotExistError ):
136+ committee_elect_role = await ctx .bot .committee_elect_role
137+
132138 return {
133139 discord .OptionChoice (
134140 name = f"{ member .display_name } ({ member .global_name } )" , value = str (member .id )
135141 )
136- for member in committee_role .members
142+ for member in (
143+ set (committee_role .members )
144+ | (
145+ set (committee_elect_role .members )
146+ if committee_elect_role is not None
147+ else set ()
148+ )
149+ )
137150 if not member .bot
138151 }
139152
@@ -281,9 +294,7 @@ async def create(
281294 required = True ,
282295 parameter_name = "status" ,
283296 )
284- @CommandChecks .check_interaction_user_has_committee_role
285- @CommandChecks .check_interaction_user_in_main_guild
286- async def update_status (
297+ async def update_status ( # NOTE: Committee role check is not present because non-committee can have actions, and need to be able to list their own actions.
287298 self , ctx : "TeXBotApplicationContext" , action_id : str , status : str
288299 ) -> None :
289300 """
@@ -561,9 +572,7 @@ async def action_all_committee(
561572 default = None ,
562573 parameter_name = "status" ,
563574 )
564- @CommandChecks .check_interaction_user_has_committee_role
565- @CommandChecks .check_interaction_user_in_main_guild
566- async def list_user_actions (
575+ async def list_user_actions ( # NOTE: Committee role check is not present because non-committee can have actions, and need to be able to list their own actions.
567576 self ,
568577 ctx : "TeXBotApplicationContext" ,
569578 * ,
@@ -575,15 +584,32 @@ async def list_user_actions(
575584 Definition and callback of the "/list" command.
576585
577586 Takes in a user and lists out their current actions.
587+ If no user is specified, the user issuing the command will be used.
588+ If a user has the committee role, they can list actions for other users.
589+ If a user does not have the committee role, they can only list their own actions.
578590 """
579- action_member : discord .Member | discord .User
591+ action_member_id = action_member_id .strip ()
592+
593+ action_member : discord .Member | discord .User = (
594+ await self .bot .get_member_from_str_id (action_member_id )
595+ if action_member_id
596+ else ctx .user
597+ )
580598
581- if action_member_id :
582- action_member = await self .bot .get_member_from_str_id (
583- action_member_id ,
599+ if action_member != ctx .user and not await self .bot .check_user_has_committee_role (
600+ ctx .user
601+ ):
602+ await ctx .respond (
603+ content = "Committee role is required to list actions for other users." ,
604+ ephemeral = True ,
584605 )
585- else :
586- action_member = ctx .user
606+ logger .debug (
607+ "User: %s, tried to list actions for user: %s, "
608+ "but did not have the committee role." ,
609+ ctx .user ,
610+ action_member ,
611+ )
612+ return
587613
588614 user_actions : list [AssignedCommitteeAction ]
589615
0 commit comments