Open ryanlerch opened 11 months ago
@ryanlerch @abompard
Hello!, I made a PR that i hope potentially solves this issue. I find this codebase inclusive of FASJSON which i had to refer to several times very intresting, I just wish the docs were a bit more explainatory haha. (Half tempted to rewrite them myself given the chance)
As my previous PR is yet to be reviewed. You can find it at #74 to fix Issue #51
Description:
This pull request modifies the FasHandler
class to enhance the user_info
command by displaying a user's Fedora Accounts group memberships along with their membership types (member or sponsor).
Changes:
_user_info
function is updated to iterate through the user's retrieved groups (a dictionary with group names as keys and membership types as values).Benefits:
Implementation:
The following code snippet demonstrates the changes made to the _user_info
function:
async def _user_info(self, evt: MessageEvent, username: str | None) -> None:
await evt.mark_read()
try:
user = await get_fasuser(username or evt.sender, evt, self.plugin.fasjsonclient)
groups = await self.plugin.fasjsonclient.get_user_groups(user.get("username"))
except InfoGatherError as e:
await evt.respond(e.message)
return
respond_message = (
f"User: {user.get('username')},{NL}"
f"Name: {user.get('human_name')},{NL}"
f"Pronouns: {' or '.join(user.get('pronouns') or ['unset'])},{NL}"
f"Creation: {user.get('creation')},{NL}"
f"Timezone: {user.get('timezone')},{NL}"
f"Locale: {user.get('locale')},{NL}"
f"GPG Key IDs: {' and '.join(k for k in user['gpgkeyids'] or ['None'])}{NL}"
)
if groups:
respond_message += f"Groups : {', '.join(groups)}{NL}"
await evt.respond(respond_message)
Implemented get_user_groups
function
async def get_user_groups(self, username, params=None):
try:
response = await self._get("/".join(["users", username, "groups"]), params=params)
user_groups = response.json().get("groups", [])
group_details = []
for groupname in user_groups:
membership_type = await self.get_group_membership(
groupname, "sponsors", params=params
)
if membership_type is None:
membership_type = "member"
elif username in membership_type:
membership_type = "sponsor"
group_details.append({"groupname": groupname, "membership_type": membership_type})
return group_details
except NoResult as e:
raise InfoGatherError(
f"Sorry, but Fedora Accounts user '{username}' does not exist"
) from e
except InfoGatherError as e:
raise
Testing:
user_info
command response.This pull request aims to improve the user experience of the user_info
command by providing more informative group membership details. I appreciate your review and feedback.
Below are the screenshots of testcases passed
IRC zodbot used to also output the groups that a user is a member of.
Here we should also list the groups a user is a member of (and perhaps sponsor of) when someone uses the !user info command.