Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Modix.Bot/Modules/TagModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public async Task ModifyTagAsync(
{
name = name.Trim().ToLower();

await _tagService.EnsureUserCanMaintainTagAsync(Context.Guild.Id, name, Context.User.Id);

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

if (currentTagData is null)
Expand Down
16 changes: 16 additions & 0 deletions src/Modix.Services/Tags/TagService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public interface ITagService
Task<bool> TagExistsAsync(ulong guildId, string name);

Task RefreshCache(ulong guildId);

Task EnsureUserCanMaintainTagAsync(ulong guildId, string name, ulong currentUserId);
}

internal class TagService : ITagService
Expand Down Expand Up @@ -340,6 +342,20 @@ public async Task RefreshCache(ulong guildId)
_tagCache.Set(guildId, tags);
}

public async Task EnsureUserCanMaintainTagAsync(ulong guildId, string name, ulong currentUserId)
{
var tag = await _modixContext
.Set<TagEntity>()
.Include(x => x.OwnerRole)
.Include(x => x.OwnerUser)
.Where(x => x.GuildId == guildId)
.Where(x => x.DeleteActionId == null)
.Where(x => x.Name == name)
.SingleOrDefaultAsync();

await EnsureUserCanMaintainTagAsync(tag, currentUserId);
}

private async Task EnsureUserCanMaintainTagAsync(TagEntity tag, ulong currentUserId)
{
var currentUser = await _userService.GetGuildUserAsync(tag.GuildId, currentUserId);
Expand Down
Loading