Skip to content

Commit f36602d

Browse files
Refactor the method to only return the list
1 parent af878ef commit f36602d

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

cogs/get_token_authorisation.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ async def get_token_status(self) -> TokenStatus:
100100
logger.debug(response_html)
101101
return self.TokenStatus.INVALID
102102

103-
async def get_token_groups(self, iterable: bool) -> "str | Iterable[str]": # noqa: FBT001
103+
async def get_token_groups(self) -> "Iterable[str]":
104104
"""
105105
Definition of method to get the groups the token has access to.
106106
@@ -118,14 +118,14 @@ async def get_token_groups(self, iterable: bool) -> "str | Iterable[str]": # no
118118
"Profile page returned no content when checking token authorisation."
119119
)
120120
logger.warning(PROFILE_PAGE_INVALID)
121-
return PROFILE_PAGE_INVALID
121+
return []
122122

123123
if "Login" in str(page_title):
124124
EXPIRED_AUTH_MESSAGE: Final[str] = (
125125
"Authentication redirected to login page. Token is invalid or expired."
126126
)
127127
logger.warning(EXPIRED_AUTH_MESSAGE)
128-
return EXPIRED_AUTH_MESSAGE
128+
return []
129129

130130
profile_section_html: bs4.Tag | bs4.NavigableString | None = response_object.find(
131131
"div",
@@ -139,7 +139,7 @@ async def get_token_groups(self, iterable: bool) -> "str | Iterable[str]": # no
139139
)
140140
logger.warning(NO_PROFILE_WARNING_MESSAGE)
141141
logger.debug("Retrieved HTML: %s", response_object.text)
142-
return NO_PROFILE_WARNING_MESSAGE
142+
return []
143143

144144
user_name: bs4.Tag | bs4.NavigableString | int | None = profile_section_html.find("h1")
145145

@@ -149,7 +149,7 @@ async def get_token_groups(self, iterable: bool) -> "str | Iterable[str]": # no
149149
)
150150
logger.warning(NO_PROFILE_DEBUG_MESSAGE)
151151
logger.debug("Retrieved HTML: %s", response_object.text)
152-
return NO_PROFILE_DEBUG_MESSAGE
152+
return []
153153

154154
parsed_html: bs4.Tag | bs4.NavigableString | None = response_object.find(
155155
"ul",
@@ -162,7 +162,7 @@ async def get_token_groups(self, iterable: bool) -> "str | Iterable[str]": # no
162162
"Please check you have used the correct token!"
163163
)
164164
logger.warning(NO_ADMIN_TABLE_MESSAGE)
165-
return NO_ADMIN_TABLE_MESSAGE
165+
return []
166166

167167
organisations: Iterable[str] = [
168168
list_item.get_text(strip=True) for list_item in parsed_html.find_all("li")
@@ -174,12 +174,7 @@ async def get_token_groups(self, iterable: bool) -> "str | Iterable[str]": # no
174174
user_name.text,
175175
)
176176

177-
constructed_organisations: str = (
178-
f"Admin token has access to the following MSL Organisations as "
179-
f"{user_name.text}:\n{', \n'.join(organisation for organisation in organisations)}"
180-
)
181-
182-
return organisations if iterable else constructed_organisations
177+
return organisations
183178

184179

185180
class GetTokenAuthorisationCommandCog(TokenAuthorisationBaseCog):
@@ -202,7 +197,14 @@ async def get_token_authorisation(self, ctx: "TeXBotApplicationContext") -> None
202197
await ctx.defer(ephemeral=True)
203198
async with ctx.typing():
204199
await ctx.followup.send(
205-
content=str(await self.get_token_groups(iterable=False)),
200+
content=(
201+
f"Admin token has access to the following MSL Organisations: "
202+
f"\n{
203+
', \n'.join(
204+
organisation for organisation in await self.get_token_groups()
205+
)
206+
}"
207+
),
206208
ephemeral=True,
207209
)
208210

0 commit comments

Comments
 (0)