MODiX icon indicating copy to clipboard operation
MODiX copied to clipboard

Check permissions for tag edits before prompting for new data

Open thaumanovic opened this issue 6 months ago • 1 comments

Originally suggested by @333fred here, just logging here so it doesn't get lost.

Currently, when you run the tag edit command, it will prompt for the new tag content before actually checking if you have the permissions necessary to update it. This should be changed such that it will immediately respond with a notice stating you may not edit it if you do not have the appropriate rights.

Leads to no wasted time for those maintaining tags.

thaumanovic avatar Jun 17 '25 20:06 thaumanovic

This shouldn't be too difficult, would make a good first issue for anyone wishing to contribute.

Need to write a wrapper method to EnsureUserCanMaintainTagAsync() in the tag service that accepts a tag ID.

I would have liked to say it was a case of making EnsureUserCanMaintainTagAsync() public and just calling it like below, but GetTagAsync returns a projected entity so this is not possible (and I would prefer to keep it as a projection myself).

var currentTagData = await _tagService.GetTagAsync(Context.Guild.Id, name); 

await _tagService.EnsureUserCanMaintainTagAsync(currentTagData)

Relevant code sections:

https://github.com/discord-csharp/MODiX/blob/e1a5b1f82295d6d5b74cb8b1edf1fe28a054ff7d/src/Modix.Services/Tags/TagService.cs#L305-L315

https://github.com/discord-csharp/MODiX/blob/e1a5b1f82295d6d5b74cb8b1edf1fe28a054ff7d/src/Modix.Bot/Modules/TagModule.cs#L55-L78

thaumanovic avatar Jun 17 '25 23:06 thaumanovic