Skip to content

Commit f47af61

Browse files
Thatsmusic99pre-commit-ci-lite[bot]MattyTheHacker
committed
Allow committee-elect to update actions (#508)
Signed-off-by: Holly <25277367+Thatsmusic99@users.noreply.github.com> Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com>
1 parent 84ab7ea commit f47af61

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

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
from enum import Enum
@@ -11,6 +12,7 @@
1112

1213
from db.core.models import AssignedCommitteeAction, DiscordMember
1314
from 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

Comments
 (0)