From 88ca4687080a1a1ee4c76eb42366de5c7c1a031e Mon Sep 17 00:00:00 2001 From: Adam R Grey Date: Sat, 6 Apr 2024 00:01:31 -0400 Subject: [PATCH] get rid of feature permissions --- Models/ChattingContext.cs | 1 - Models/FeaturePermission.cs | 109 ------------------------------------ 2 files changed, 110 deletions(-) delete mode 100644 Models/FeaturePermission.cs diff --git a/Models/ChattingContext.cs b/Models/ChattingContext.cs index f72dafd..6ffbc66 100644 --- a/Models/ChattingContext.cs +++ b/Models/ChattingContext.cs @@ -9,7 +9,6 @@ public class ChattingContext : DbContext public DbSet Channels { get; set; } //public DbSet Emoji {get;set;} public DbSet Messages { get; set; } - public DbSet FeaturePermissions{get;set;} public DbSet Accounts { get; set; } public DbSet Users { get; set; } diff --git a/Models/FeaturePermission.cs b/Models/FeaturePermission.cs deleted file mode 100644 index a4475fc..0000000 --- a/Models/FeaturePermission.cs +++ /dev/null @@ -1,109 +0,0 @@ -namespace vassago.Models; - -using System; -using System.Linq; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Reflection; -using System.Threading.Tasks; -using Discord.WebSocket; -using static vassago.Models.Enumerations; - -public enum WellknownPermissions -{ - Administrator, - TwitchSummon, -} - -public class FeaturePermission -{ - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] - public Guid Id { get; set; } - - public string InternalName { get; set; } - public WellknownPermissions? InternalTag { get; set; } - - //a permissions-needing-feature can determine how to use these, but a default "matches" is provided - //for a message to "match", it must match in every category for which there are candidates. - //e.g., Administrator is going to be restricted to Users only, and that'll be me - //e.g., my future Torrent feature would be restricted to accounts and channels. - //hmmm, what would be inheritable and what wouldn't? - public IEnumerable RestrictedToUsers { get; set; } - public IEnumerable RestrictedToAccounts { get; set; } - public IEnumerable RestrictedToChannels { get; set; } - public bool Inheritable { get; set; } = true; - - public bool Matches(Message message) - { - if(RestrictedToUsers?.Count() > 0) - { - if(RestrictedToUsers.FirstOrDefault(u => u.Id == message.Author.IsUser.Id) == null) - { - return false; - } - } - - if(RestrictedToChannels?.Count() > 0) - { - if(Inheritable) - { - var found = false; - var walker = message.Channel; - if (RestrictedToChannels.FirstOrDefault(c => c.Id == walker.Id) != null) - { - found = true; - } - else - { - while (walker.ParentChannel != null) - { - walker = walker.ParentChannel; - if(walker.Users.FirstOrDefault(a => a.ExternalId == message.Author.ExternalId) == null) - { - //the chain is broken; I don't exist in this channel - break; - } - if (RestrictedToChannels.FirstOrDefault(c => c.Id == walker.Id) != null) - { - found = true; - break; - } - } - } - if (found) - { - - if(RestrictedToAccounts?.Count() > 0) - { - //walker is the "actual" restricted-to channel, but we're inheriting - if(walker.Users.FirstOrDefault(a => a.Id == message.Author.Id) == null) - { - return false; - } - } - } - else - { - return false; - } - } - else - { - if(RestrictedToChannels.FirstOrDefault(c => c.Id == message.Channel.Id) == null) - { - return false; - } - } - } - if(RestrictedToAccounts?.Count() > 0) - { - if(RestrictedToAccounts.FirstOrDefault(a => a.Id == message.Author.Id) == null) - { - return false; - } - } - - //if I got all the way down here, I must be good - return true; - } -}