mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
- Automatically update permissions for CustomReactions to Expressions during
- Small refactor
This commit is contained in:
@@ -112,14 +112,14 @@ public static class GuildConfigExtensions
|
|||||||
return logSetting;
|
return logSetting;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<GuildConfig> Permissionsv2ForAll(this DbSet<GuildConfig> configs, List<ulong> include)
|
public static IEnumerable<GuildConfig> PermissionsForAll(this DbSet<GuildConfig> configs, List<ulong> include)
|
||||||
{
|
{
|
||||||
var query = configs.AsQueryable().Where(x => include.Contains(x.GuildId)).Include(gc => gc.Permissions);
|
var query = configs.AsQueryable().Where(x => include.Contains(x.GuildId)).Include(gc => gc.Permissions);
|
||||||
|
|
||||||
return query.ToList();
|
return query.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GuildConfig GcWithPermissionsv2For(this NadekoContext ctx, ulong guildId)
|
public static GuildConfig GcWithPermissionsFor(this NadekoContext ctx, ulong guildId)
|
||||||
{
|
{
|
||||||
var config = ctx.GuildConfigs.AsQueryable()
|
var config = ctx.GuildConfigs.AsQueryable()
|
||||||
.Where(gc => gc.GuildId == guildId)
|
.Where(gc => gc.GuildId == guildId)
|
||||||
|
@@ -53,6 +53,10 @@ namespace NadekoBot.Migrations
|
|||||||
migrationBuilder.Sql(@"UPDATE Permissions
|
migrationBuilder.Sql(@"UPDATE Permissions
|
||||||
SET SecondaryTargetName='ACTUALEXPRESSIONS'
|
SET SecondaryTargetName='ACTUALEXPRESSIONS'
|
||||||
WHERE SecondaryTargetName='ActualCustomReactions' COLLATE NOCASE;");
|
WHERE SecondaryTargetName='ActualCustomReactions' COLLATE NOCASE;");
|
||||||
|
|
||||||
|
migrationBuilder.Sql(@"UPDATE Permissions
|
||||||
|
SET SecondaryTargetName='EXPRESSIONS'
|
||||||
|
WHERE SecondaryTargetName='CustomReactions' COLLATE NOCASE;");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
@@ -23,7 +23,7 @@ public partial class Permissions : NadekoModule<PermissionService>
|
|||||||
{
|
{
|
||||||
await using (var uow = _db.GetDbContext())
|
await using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
|
var config = uow.GcWithPermissionsFor(ctx.Guild.Id);
|
||||||
if (action is null) action = new(!config.VerbosePermissions); // New behaviour, can toggle.
|
if (action is null) action = new(!config.VerbosePermissions); // New behaviour, can toggle.
|
||||||
config.VerbosePermissions = action.Value;
|
config.VerbosePermissions = action.Value;
|
||||||
await uow.SaveChangesAsync();
|
await uow.SaveChangesAsync();
|
||||||
@@ -58,7 +58,7 @@ public partial class Permissions : NadekoModule<PermissionService>
|
|||||||
|
|
||||||
await using (var uow = _db.GetDbContext())
|
await using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
|
var config = uow.GcWithPermissionsFor(ctx.Guild.Id);
|
||||||
config.PermissionRole = role.Id.ToString();
|
config.PermissionRole = role.Id.ToString();
|
||||||
uow.SaveChanges();
|
uow.SaveChanges();
|
||||||
_service.UpdateCache(config);
|
_service.UpdateCache(config);
|
||||||
@@ -75,7 +75,7 @@ public partial class Permissions : NadekoModule<PermissionService>
|
|||||||
{
|
{
|
||||||
await using (var uow = _db.GetDbContext())
|
await using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
|
var config = uow.GcWithPermissionsFor(ctx.Guild.Id);
|
||||||
config.PermissionRole = null;
|
config.PermissionRole = null;
|
||||||
await uow.SaveChangesAsync();
|
await uow.SaveChangesAsync();
|
||||||
_service.UpdateCache(config);
|
_service.UpdateCache(config);
|
||||||
@@ -129,7 +129,7 @@ public partial class Permissions : NadekoModule<PermissionService>
|
|||||||
Permissionv2 p;
|
Permissionv2 p;
|
||||||
await using (var uow = _db.GetDbContext())
|
await using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
|
var config = uow.GcWithPermissionsFor(ctx.Guild.Id);
|
||||||
var permsCol = new PermissionsCollection<Permissionv2>(config.Permissions);
|
var permsCol = new PermissionsCollection<Permissionv2>(config.Permissions);
|
||||||
p = permsCol[index];
|
p = permsCol[index];
|
||||||
permsCol.RemoveAt(index);
|
permsCol.RemoveAt(index);
|
||||||
@@ -159,7 +159,7 @@ public partial class Permissions : NadekoModule<PermissionService>
|
|||||||
Permissionv2 fromPerm;
|
Permissionv2 fromPerm;
|
||||||
await using (var uow = _db.GetDbContext())
|
await using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
|
var config = uow.GcWithPermissionsFor(ctx.Guild.Id);
|
||||||
var permsCol = new PermissionsCollection<Permissionv2>(config.Permissions);
|
var permsCol = new PermissionsCollection<Permissionv2>(config.Permissions);
|
||||||
|
|
||||||
var fromFound = from < permsCol.Count;
|
var fromFound = from < permsCol.Count;
|
||||||
|
@@ -32,7 +32,7 @@ public class PermissionService : ILateBlocker, INService
|
|||||||
_eb = eb;
|
_eb = eb;
|
||||||
|
|
||||||
using var uow = _db.GetDbContext();
|
using var uow = _db.GetDbContext();
|
||||||
foreach (var x in uow.GuildConfigs.Permissionsv2ForAll(client.Guilds.ToArray().Select(x => x.Id).ToList()))
|
foreach (var x in uow.GuildConfigs.PermissionsForAll(client.Guilds.ToArray().Select(x => x.Id).ToList()))
|
||||||
Cache.TryAdd(x.GuildId,
|
Cache.TryAdd(x.GuildId,
|
||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
@@ -61,7 +61,7 @@ public class PermissionService : ILateBlocker, INService
|
|||||||
public async Task AddPermissions(ulong guildId, params Permissionv2[] perms)
|
public async Task AddPermissions(ulong guildId, params Permissionv2[] perms)
|
||||||
{
|
{
|
||||||
await using var uow = _db.GetDbContext();
|
await using var uow = _db.GetDbContext();
|
||||||
var config = uow.GcWithPermissionsv2For(guildId);
|
var config = uow.GcWithPermissionsFor(guildId);
|
||||||
//var orderedPerms = new PermissionsCollection<Permissionv2>(config.Permissions);
|
//var orderedPerms = new PermissionsCollection<Permissionv2>(config.Permissions);
|
||||||
var max = config.Permissions.Max(x => x.Index); //have to set its index to be the highest
|
var max = config.Permissions.Max(x => x.Index); //have to set its index to be the highest
|
||||||
foreach (var perm in perms)
|
foreach (var perm in perms)
|
||||||
@@ -165,7 +165,7 @@ public class PermissionService : ILateBlocker, INService
|
|||||||
public async Task Reset(ulong guildId)
|
public async Task Reset(ulong guildId)
|
||||||
{
|
{
|
||||||
await using var uow = _db.GetDbContext();
|
await using var uow = _db.GetDbContext();
|
||||||
var config = uow.GcWithPermissionsv2For(guildId);
|
var config = uow.GcWithPermissionsFor(guildId);
|
||||||
config.Permissions = Permissionv2.GetDefaultPermlist;
|
config.Permissions = Permissionv2.GetDefaultPermlist;
|
||||||
await uow.SaveChangesAsync();
|
await uow.SaveChangesAsync();
|
||||||
UpdateCache(config);
|
UpdateCache(config);
|
||||||
|
Reference in New Issue
Block a user