Skip to content

Commit 59b99fa

Browse files
authored
Merge main into 453-action-reminders
2 parents 1e4d3a4 + 1a6ff75 commit 59b99fa

1 file changed

Lines changed: 39 additions & 13 deletions

File tree

cogs/committee_actions_tracking.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Contains cog classes for tracking committee-actions."""
22

3+
import contextlib
34
import logging
45
import random
56
import time
@@ -15,6 +16,7 @@
1516
from config import settings
1617
from db.core.models import AssignedCommitteeAction, DiscordMember
1718
from exceptions import (
19+
CommitteeElectRoleDoesNotExistError,
1820
CommitteeRoleDoesNotExistError,
1921
InvalidActionDescriptionError,
2022
InvalidActionTargetError,
@@ -360,11 +362,22 @@ async def autocomplete_get_committee_members(
360362
except CommitteeRoleDoesNotExistError:
361363
return set()
362364

365+
committee_elect_role: discord.Role | None = None
366+
with contextlib.suppress(CommitteeElectRoleDoesNotExistError):
367+
committee_elect_role = await ctx.bot.committee_elect_role
368+
363369
return {
364370
discord.OptionChoice(
365371
name=f"{member.display_name} ({member.global_name})", value=str(member.id)
366372
)
367-
for member in committee_role.members
373+
for member in (
374+
set(committee_role.members)
375+
| (
376+
set(committee_elect_role.members)
377+
if committee_elect_role is not None
378+
else set()
379+
)
380+
)
368381
if not member.bot
369382
}
370383

@@ -512,9 +525,7 @@ async def create(
512525
required=True,
513526
parameter_name="status",
514527
)
515-
@CommandChecks.check_interaction_user_has_committee_role
516-
@CommandChecks.check_interaction_user_in_main_guild
517-
async def update_status(
528+
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.
518529
self, ctx: "TeXBotApplicationContext", action_id: str, status: str
519530
) -> None:
520531
"""
@@ -796,9 +807,7 @@ async def action_all_committee(
796807
default=None,
797808
parameter_name="status",
798809
)
799-
@CommandChecks.check_interaction_user_has_committee_role
800-
@CommandChecks.check_interaction_user_in_main_guild
801-
async def list_user_actions(
810+
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.
802811
self,
803812
ctx: "TeXBotApplicationContext",
804813
*,
@@ -810,15 +819,32 @@ async def list_user_actions(
810819
Definition and callback of the "/list" command.
811820
812821
Takes in a user and lists out their current actions.
822+
If no user is specified, the user issuing the command will be used.
823+
If a user has the committee role, they can list actions for other users.
824+
If a user does not have the committee role, they can only list their own actions.
813825
"""
814-
action_member: discord.Member | discord.User
826+
action_member_id = action_member_id.strip()
827+
828+
action_member: discord.Member | discord.User = (
829+
await self.bot.get_member_from_str_id(action_member_id)
830+
if action_member_id
831+
else ctx.user
832+
)
815833

816-
if action_member_id:
817-
action_member = await self.bot.get_member_from_str_id(
818-
action_member_id,
834+
if action_member != ctx.user and not await self.bot.check_user_has_committee_role(
835+
ctx.user
836+
):
837+
await ctx.respond(
838+
content="Committee role is required to list actions for other users.",
839+
ephemeral=True,
819840
)
820-
else:
821-
action_member = ctx.user
841+
logger.debug(
842+
"User: %s, tried to list actions for user: %s, "
843+
"but did not have the committee role.",
844+
ctx.user,
845+
action_member,
846+
)
847+
return
822848

823849
desired_status: list[str] = (
824850
[status]

0 commit comments

Comments
 (0)