From 39eead0052215d7be4f49906e987fef7fb0c700b Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Wed, 20 Sep 2023 15:53:05 +1000 Subject: Fixed migration and began adding ACL edit dialog --- Acl.cs | 1 + AclEnum.cs | 14 + Migrations/20230920014958_Security.Designer.cs | 455 ------------------------- Migrations/20230920014958_Security.cs | 194 ----------- Migrations/20230920052204_Security.Designer.cs | 455 +++++++++++++++++++++++++ Migrations/20230920052204_Security.cs | 194 +++++++++++ Migrations/HBContextModelSnapshot.cs | 6 +- Pages/Component/AclDialog.razor | 19 ++ Properties/launchSettings.json | 1 - Server.csproj | 10 +- Services/SecurityService.cs | 5 +- 11 files changed, 694 insertions(+), 660 deletions(-) create mode 100644 AclEnum.cs delete mode 100644 Migrations/20230920014958_Security.Designer.cs delete mode 100644 Migrations/20230920014958_Security.cs create mode 100644 Migrations/20230920052204_Security.Designer.cs create mode 100644 Migrations/20230920052204_Security.cs create mode 100644 Pages/Component/AclDialog.razor diff --git a/Acl.cs b/Acl.cs index 72d0bf2..297144e 100644 --- a/Acl.cs +++ b/Acl.cs @@ -25,6 +25,7 @@ public class Acl : Acl where T : Enum { public class AclRule : HBObject { public HBPrincipal Principal { get; set; } public AclRuleAction Action { get; set; } + [Column(TypeName = "bigint")] public ulong Permissions { get; set; } } diff --git a/AclEnum.cs b/AclEnum.cs new file mode 100644 index 0000000..e195444 --- /dev/null +++ b/AclEnum.cs @@ -0,0 +1,14 @@ +namespace HyperBooru; + +[Flags] +public enum HBMediaPermissions { + [AclPermission] Read = 0x01, + [AclPermission] Write = 0x02, + [AclPermission] Delete = 0x04, + [AclPermission] GetTags = 0x08, + [AclPermission] SetTags = 0x10 +} + +public class AclPermissionAttribute : Attribute { + public string Name { get; set; } +} diff --git a/Migrations/20230920014958_Security.Designer.cs b/Migrations/20230920014958_Security.Designer.cs deleted file mode 100644 index 7933a93..0000000 --- a/Migrations/20230920014958_Security.Designer.cs +++ /dev/null @@ -1,455 +0,0 @@ -// -using System; -using HyperBooru; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace HyperBooru.Migrations -{ - [DbContext(typeof(HBContext))] - [Migration("20230920014958_Security")] - partial class Security - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.10") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("HyperBooru.HBObject", b => - { - b.Property("ObjectId") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ObjectId")); - - b.Property("Guid") - .HasColumnType("uuid"); - - b.HasKey("ObjectId"); - - b.HasIndex("Guid"); - - b.ToTable("Objects", (string)null); - - b.UseTptMappingStrategy(); - }); - - modelBuilder.Entity("HyperBooru.OcrData", b => - { - b.Property("OcrDataId") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("OcrDataId")); - - b.Property("MediaId") - .HasColumnType("integer"); - - b.Property("SearchableText") - .IsRequired() - .HasColumnType("text"); - - b.Property("Text") - .IsRequired() - .HasColumnType("text"); - - b.Property("Timestamp") - .HasColumnType("timestamp with time zone"); - - b.HasKey("OcrDataId"); - - b.HasIndex("MediaId") - .IsUnique(); - - b.ToTable("OcrData"); - }); - - modelBuilder.Entity("TagDefinitionTagDefinition", b => - { - b.Property("ImplicitTagsObjectId") - .HasColumnType("integer"); - - b.Property("TagDefinitionObjectId") - .HasColumnType("integer"); - - b.HasKey("ImplicitTagsObjectId", "TagDefinitionObjectId"); - - b.HasIndex("TagDefinitionObjectId"); - - b.ToTable("TagDefinitionTagDefinition"); - }); - - modelBuilder.Entity("HyperBooru.Acl", b => - { - b.HasBaseType("HyperBooru.HBObject"); - - b.Property("SubjectTempId1") - .HasColumnType("integer"); - - b.ToTable("Acls"); - }); - - modelBuilder.Entity("HyperBooru.AclRule", b => - { - b.HasBaseType("HyperBooru.HBObject"); - - b.Property("AclObjectId") - .HasColumnType("integer"); - - b.Property("Action") - .HasColumnType("integer"); - - b.Property("Permissions") - .HasColumnType("numeric(20,0)"); - - b.Property("PrincipalObjectId") - .HasColumnType("integer"); - - b.HasIndex("AclObjectId"); - - b.HasIndex("PrincipalObjectId"); - - b.ToTable("AclRules"); - }); - - modelBuilder.Entity("HyperBooru.HBPrincipal", b => - { - b.HasBaseType("HyperBooru.HBObject"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.HasIndex("Name"); - - b.ToTable("Principals"); - }); - - modelBuilder.Entity("HyperBooru.Media", b => - { - b.HasBaseType("HyperBooru.HBObject"); - - b.Property("CurrentUploadedFileId") - .HasColumnType("integer"); - - b.Property("LongDescription") - .HasColumnType("text"); - - b.Property("ShortDescription") - .HasColumnType("text"); - - b.HasIndex("CurrentUploadedFileId") - .IsUnique(); - - b.ToTable("Media", (string)null); - }); - - modelBuilder.Entity("HyperBooru.Tag", b => - { - b.HasBaseType("HyperBooru.HBObject"); - - b.Property("CreateTime") - .HasColumnType("timestamp with time zone"); - - b.Property("TagDefinitionId") - .HasColumnType("integer"); - - b.Property("TargetObjectId") - .HasColumnType("integer"); - - b.HasIndex("TagDefinitionId"); - - b.HasIndex("TargetObjectId"); - - b.ToTable("Tags", (string)null); - }); - - modelBuilder.Entity("HyperBooru.TagDefinition", b => - { - b.HasBaseType("HyperBooru.HBObject"); - - b.Property("Alias") - .HasColumnType("text"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.Property("Namespace") - .HasColumnType("text"); - - b.Property("Source") - .HasColumnType("integer"); - - b.ToTable("TagDefinitions", (string)null); - - b.HasData( - new - { - ObjectId = -1, - Guid = new Guid("ebdad4f8-455a-4351-8017-1d4854d6fa38"), - Name = "nsfw", - Source = 0 - }, - new - { - ObjectId = -2, - Guid = new Guid("ea212801-5bcc-4c0e-814f-fb9d30db58bc"), - Name = "ingest", - Source = 0 - }); - }); - - modelBuilder.Entity("HyperBooru.UploadedFile", b => - { - b.HasBaseType("HyperBooru.HBObject"); - - b.Property("Checksum") - .IsRequired() - .HasColumnType("text"); - - b.Property("ChecksumVerified") - .HasColumnType("boolean"); - - b.Property("CreateTime") - .HasColumnType("timestamp with time zone"); - - b.Property("Filename") - .HasColumnType("text"); - - b.Property("Height") - .HasColumnType("integer"); - - b.Property("LastAccessTime") - .HasColumnType("timestamp with time zone"); - - b.Property("LastWriteTime") - .HasColumnType("timestamp with time zone"); - - b.Property("Length") - .HasColumnType("bigint"); - - b.Property("MediaObjectId") - .HasColumnType("integer"); - - b.Property("MimeType") - .IsRequired() - .HasColumnType("text"); - - b.Property("UploadTime") - .HasColumnType("timestamp with time zone"); - - b.Property("Width") - .HasColumnType("integer"); - - b.HasIndex("MediaObjectId"); - - b.ToTable("UploadedFiles", (string)null); - }); - - modelBuilder.Entity("HyperBooru.Group", b => - { - b.HasBaseType("HyperBooru.HBPrincipal"); - - b.Property("HBPrincipalObjectId") - .HasColumnType("integer"); - - b.HasIndex("HBPrincipalObjectId"); - - b.ToTable("Groups"); - }); - - modelBuilder.Entity("HyperBooru.User", b => - { - b.HasBaseType("HyperBooru.HBPrincipal"); - - b.Property("PasswordHash") - .IsRequired() - .HasColumnType("text"); - - b.ToTable("Users"); - - b.HasData( - new - { - ObjectId = -3, - Guid = new Guid("bf62bd4c-806e-4d1b-a62d-0efffce8628a"), - Name = "admin", - PasswordHash = "P4geAuE2yX/PDRHuJSq74FF5vO782rWz5c0LAQPR8m45DEYAONhu1wYnAn60PSNyjocqEBdnCeKCJfK3sKyuWw==" - }); - }); - - modelBuilder.Entity("HyperBooru.OcrData", b => - { - b.HasOne("HyperBooru.Media", "Media") - .WithOne("OcrData") - .HasForeignKey("HyperBooru.OcrData", "MediaId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Media"); - }); - - modelBuilder.Entity("TagDefinitionTagDefinition", b => - { - b.HasOne("HyperBooru.TagDefinition", null) - .WithMany() - .HasForeignKey("ImplicitTagsObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("HyperBooru.TagDefinition", null) - .WithMany() - .HasForeignKey("TagDefinitionObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("HyperBooru.Acl", b => - { - b.HasOne("HyperBooru.HBObject", "Subject") - .WithOne("Acl") - .HasForeignKey("HyperBooru.Acl", "ObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Subject"); - }); - - modelBuilder.Entity("HyperBooru.AclRule", b => - { - b.HasOne("HyperBooru.Acl", null) - .WithMany("Rules") - .HasForeignKey("AclObjectId"); - - b.HasOne("HyperBooru.HBPrincipal", "Principal") - .WithMany() - .HasForeignKey("PrincipalObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Principal"); - }); - - modelBuilder.Entity("HyperBooru.Media", b => - { - b.HasOne("HyperBooru.UploadedFile", "CurrentUploadedFile") - .WithOne() - .HasForeignKey("HyperBooru.Media", "CurrentUploadedFileId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("HyperBooru.HBObject", null) - .WithOne() - .HasForeignKey("HyperBooru.Media", "ObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("CurrentUploadedFile"); - }); - - modelBuilder.Entity("HyperBooru.Tag", b => - { - b.HasOne("HyperBooru.HBObject", null) - .WithOne() - .HasForeignKey("HyperBooru.Tag", "ObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("HyperBooru.TagDefinition", "TagDefinition") - .WithMany() - .HasForeignKey("TagDefinitionId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("HyperBooru.HBObject", "Target") - .WithMany("Tags") - .HasForeignKey("TargetObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("TagDefinition"); - - b.Navigation("Target"); - }); - - modelBuilder.Entity("HyperBooru.TagDefinition", b => - { - b.HasOne("HyperBooru.HBObject", null) - .WithOne() - .HasForeignKey("HyperBooru.TagDefinition", "ObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("HyperBooru.UploadedFile", b => - { - b.HasOne("HyperBooru.Media", "Media") - .WithMany("UploadedFiles") - .HasForeignKey("MediaObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("HyperBooru.HBObject", null) - .WithOne() - .HasForeignKey("HyperBooru.UploadedFile", "ObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Media"); - }); - - modelBuilder.Entity("HyperBooru.Group", b => - { - b.HasOne("HyperBooru.HBPrincipal", null) - .WithMany("MemberOf") - .HasForeignKey("HBPrincipalObjectId"); - }); - - modelBuilder.Entity("HyperBooru.User", b => - { - b.HasOne("HyperBooru.HBPrincipal", null) - .WithOne() - .HasForeignKey("HyperBooru.User", "ObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("HyperBooru.HBObject", b => - { - b.Navigation("Acl"); - - b.Navigation("Tags"); - }); - - modelBuilder.Entity("HyperBooru.Acl", b => - { - b.Navigation("Rules"); - }); - - modelBuilder.Entity("HyperBooru.HBPrincipal", b => - { - b.Navigation("MemberOf"); - }); - - modelBuilder.Entity("HyperBooru.Media", b => - { - b.Navigation("OcrData"); - - b.Navigation("UploadedFiles"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Migrations/20230920014958_Security.cs b/Migrations/20230920014958_Security.cs deleted file mode 100644 index ed7def8..0000000 --- a/Migrations/20230920014958_Security.cs +++ /dev/null @@ -1,194 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace HyperBooru.Migrations -{ - /// - public partial class Security : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Users_Objects_ObjectId", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_Username", - table: "Users"); - - migrationBuilder.CreateTable( - name: "Acls", - columns: table => new - { - ObjectId = table.Column(type: "integer", nullable: false), - SubjectTempId1 = table.Column(type: "integer", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Acls", x => x.ObjectId); - table.ForeignKey( - name: "FK_Acls_Objects_ObjectId", - column: x => x.ObjectId, - principalTable: "Objects", - principalColumn: "ObjectId", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Principals", - columns: table => new - { - ObjectId = table.Column(type: "integer", nullable: false), - Name = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Principals", x => x.ObjectId); - }); - - migrationBuilder.CreateTable( - name: "AclRules", - columns: table => new - { - ObjectId = table.Column(type: "integer", nullable: false), - PrincipalObjectId = table.Column(type: "integer", nullable: false), - Action = table.Column(type: "integer", nullable: false), - Permissions = table.Column(type: "numeric(20,0)", nullable: false), - AclObjectId = table.Column(type: "integer", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AclRules", x => x.ObjectId); - table.ForeignKey( - name: "FK_AclRules_Acls_AclObjectId", - column: x => x.AclObjectId, - principalTable: "Acls", - principalColumn: "ObjectId"); - table.ForeignKey( - name: "FK_AclRules_Principals_PrincipalObjectId", - column: x => x.PrincipalObjectId, - principalTable: "Principals", - principalColumn: "ObjectId", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Groups", - columns: table => new - { - ObjectId = table.Column(type: "integer", nullable: false), - HBPrincipalObjectId = table.Column(type: "integer", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Groups", x => x.ObjectId); - table.ForeignKey( - name: "FK_Groups_Principals_HBPrincipalObjectId", - column: x => x.HBPrincipalObjectId, - principalTable: "Principals", - principalColumn: "ObjectId"); - }); - - migrationBuilder.UpdateData( - table: "Objects", - keyColumn: "ObjectId", - keyValue: -3, - column: "Guid", - value: new Guid("bf62bd4c-806e-4d1b-a62d-0efffce8628a")); - - migrationBuilder.InsertData( - table: "Principals", - columns: new[] { "ObjectId", "Name" }, - values: new object[] { -3, "admin" }); - - migrationBuilder.CreateIndex( - name: "IX_AclRules_AclObjectId", - table: "AclRules", - column: "AclObjectId"); - - migrationBuilder.CreateIndex( - name: "IX_AclRules_PrincipalObjectId", - table: "AclRules", - column: "PrincipalObjectId"); - - migrationBuilder.CreateIndex( - name: "IX_Groups_HBPrincipalObjectId", - table: "Groups", - column: "HBPrincipalObjectId"); - - migrationBuilder.CreateIndex( - name: "IX_Principals_Name", - table: "Principals", - column: "Name"); - - migrationBuilder.AddForeignKey( - name: "FK_Users_Principals_ObjectId", - table: "Users", - column: "ObjectId", - principalTable: "Principals", - principalColumn: "ObjectId", - onDelete: ReferentialAction.Cascade); - - migrationBuilder.DropColumn( - name: "Username", - table: "Users"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Users_Principals_ObjectId", - table: "Users"); - - migrationBuilder.DropTable( - name: "AclRules"); - - migrationBuilder.DropTable( - name: "Groups"); - - migrationBuilder.DropTable( - name: "Acls"); - - migrationBuilder.DropTable( - name: "Principals"); - - migrationBuilder.AddColumn( - name: "Username", - table: "Users", - type: "text", - nullable: false, - defaultValue: ""); - - migrationBuilder.UpdateData( - table: "Objects", - keyColumn: "ObjectId", - keyValue: -3, - column: "Guid", - value: new Guid("4fa948f4-7c45-4f81-bb6b-e417491e6c96")); - - migrationBuilder.UpdateData( - table: "Users", - keyColumn: "ObjectId", - keyValue: -3, - column: "Username", - value: "admin"); - - migrationBuilder.CreateIndex( - name: "IX_Users_Username", - table: "Users", - column: "Username"); - - migrationBuilder.AddForeignKey( - name: "FK_Users_Objects_ObjectId", - table: "Users", - column: "ObjectId", - principalTable: "Objects", - principalColumn: "ObjectId", - onDelete: ReferentialAction.Cascade); - } - } -} diff --git a/Migrations/20230920052204_Security.Designer.cs b/Migrations/20230920052204_Security.Designer.cs new file mode 100644 index 0000000..8640c30 --- /dev/null +++ b/Migrations/20230920052204_Security.Designer.cs @@ -0,0 +1,455 @@ +// +using System; +using HyperBooru; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HyperBooru.Migrations +{ + [DbContext(typeof(HBContext))] + [Migration("20230920052204_Security")] + partial class Security + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("HyperBooru.HBObject", b => + { + b.Property("ObjectId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ObjectId")); + + b.Property("Guid") + .HasColumnType("uuid"); + + b.HasKey("ObjectId"); + + b.HasIndex("Guid"); + + b.ToTable("Objects", (string)null); + + b.UseTptMappingStrategy(); + }); + + modelBuilder.Entity("HyperBooru.OcrData", b => + { + b.Property("OcrDataId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("OcrDataId")); + + b.Property("MediaId") + .HasColumnType("integer"); + + b.Property("SearchableText") + .IsRequired() + .HasColumnType("text"); + + b.Property("Text") + .IsRequired() + .HasColumnType("text"); + + b.Property("Timestamp") + .HasColumnType("timestamp with time zone"); + + b.HasKey("OcrDataId"); + + b.HasIndex("MediaId") + .IsUnique(); + + b.ToTable("OcrData"); + }); + + modelBuilder.Entity("TagDefinitionTagDefinition", b => + { + b.Property("ImplicitTagsObjectId") + .HasColumnType("integer"); + + b.Property("TagDefinitionObjectId") + .HasColumnType("integer"); + + b.HasKey("ImplicitTagsObjectId", "TagDefinitionObjectId"); + + b.HasIndex("TagDefinitionObjectId"); + + b.ToTable("TagDefinitionTagDefinition"); + }); + + modelBuilder.Entity("HyperBooru.Acl", b => + { + b.HasBaseType("HyperBooru.HBObject"); + + b.Property("SubjectTempId1") + .HasColumnType("integer"); + + b.ToTable("Acls"); + }); + + modelBuilder.Entity("HyperBooru.AclRule", b => + { + b.HasBaseType("HyperBooru.HBObject"); + + b.Property("AclObjectId") + .HasColumnType("integer"); + + b.Property("Action") + .HasColumnType("integer"); + + b.Property("Permissions") + .HasColumnType("bigint"); + + b.Property("PrincipalObjectId") + .HasColumnType("integer"); + + b.HasIndex("AclObjectId"); + + b.HasIndex("PrincipalObjectId"); + + b.ToTable("AclRules"); + }); + + modelBuilder.Entity("HyperBooru.HBPrincipal", b => + { + b.HasBaseType("HyperBooru.HBObject"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasIndex("Name"); + + b.ToTable("Principals"); + }); + + modelBuilder.Entity("HyperBooru.Media", b => + { + b.HasBaseType("HyperBooru.HBObject"); + + b.Property("CurrentUploadedFileId") + .HasColumnType("integer"); + + b.Property("LongDescription") + .HasColumnType("text"); + + b.Property("ShortDescription") + .HasColumnType("text"); + + b.HasIndex("CurrentUploadedFileId") + .IsUnique(); + + b.ToTable("Media", (string)null); + }); + + modelBuilder.Entity("HyperBooru.Tag", b => + { + b.HasBaseType("HyperBooru.HBObject"); + + b.Property("CreateTime") + .HasColumnType("timestamp with time zone"); + + b.Property("TagDefinitionId") + .HasColumnType("integer"); + + b.Property("TargetObjectId") + .HasColumnType("integer"); + + b.HasIndex("TagDefinitionId"); + + b.HasIndex("TargetObjectId"); + + b.ToTable("Tags", (string)null); + }); + + modelBuilder.Entity("HyperBooru.TagDefinition", b => + { + b.HasBaseType("HyperBooru.HBObject"); + + b.Property("Alias") + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Namespace") + .HasColumnType("text"); + + b.Property("Source") + .HasColumnType("integer"); + + b.ToTable("TagDefinitions", (string)null); + + b.HasData( + new + { + ObjectId = -1, + Guid = new Guid("ebdad4f8-455a-4351-8017-1d4854d6fa38"), + Name = "nsfw", + Source = 0 + }, + new + { + ObjectId = -2, + Guid = new Guid("ea212801-5bcc-4c0e-814f-fb9d30db58bc"), + Name = "ingest", + Source = 0 + }); + }); + + modelBuilder.Entity("HyperBooru.UploadedFile", b => + { + b.HasBaseType("HyperBooru.HBObject"); + + b.Property("Checksum") + .IsRequired() + .HasColumnType("text"); + + b.Property("ChecksumVerified") + .HasColumnType("boolean"); + + b.Property("CreateTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Filename") + .HasColumnType("text"); + + b.Property("Height") + .HasColumnType("integer"); + + b.Property("LastAccessTime") + .HasColumnType("timestamp with time zone"); + + b.Property("LastWriteTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Length") + .HasColumnType("bigint"); + + b.Property("MediaObjectId") + .HasColumnType("integer"); + + b.Property("MimeType") + .IsRequired() + .HasColumnType("text"); + + b.Property("UploadTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Width") + .HasColumnType("integer"); + + b.HasIndex("MediaObjectId"); + + b.ToTable("UploadedFiles", (string)null); + }); + + modelBuilder.Entity("HyperBooru.Group", b => + { + b.HasBaseType("HyperBooru.HBPrincipal"); + + b.Property("HBPrincipalObjectId") + .HasColumnType("integer"); + + b.HasIndex("HBPrincipalObjectId"); + + b.ToTable("Groups"); + }); + + modelBuilder.Entity("HyperBooru.User", b => + { + b.HasBaseType("HyperBooru.HBPrincipal"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.ToTable("Users"); + + b.HasData( + new + { + ObjectId = -3, + Guid = new Guid("8fbbc2e9-0609-460a-ab3a-c3bdd10ab793"), + Name = "admin", + PasswordHash = "P4geAuE2yX/PDRHuJSq74FF5vO782rWz5c0LAQPR8m45DEYAONhu1wYnAn60PSNyjocqEBdnCeKCJfK3sKyuWw==" + }); + }); + + modelBuilder.Entity("HyperBooru.OcrData", b => + { + b.HasOne("HyperBooru.Media", "Media") + .WithOne("OcrData") + .HasForeignKey("HyperBooru.OcrData", "MediaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Media"); + }); + + modelBuilder.Entity("TagDefinitionTagDefinition", b => + { + b.HasOne("HyperBooru.TagDefinition", null) + .WithMany() + .HasForeignKey("ImplicitTagsObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HyperBooru.TagDefinition", null) + .WithMany() + .HasForeignKey("TagDefinitionObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HyperBooru.Acl", b => + { + b.HasOne("HyperBooru.HBObject", "Subject") + .WithOne("Acl") + .HasForeignKey("HyperBooru.Acl", "ObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Subject"); + }); + + modelBuilder.Entity("HyperBooru.AclRule", b => + { + b.HasOne("HyperBooru.Acl", null) + .WithMany("Rules") + .HasForeignKey("AclObjectId"); + + b.HasOne("HyperBooru.HBPrincipal", "Principal") + .WithMany() + .HasForeignKey("PrincipalObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Principal"); + }); + + modelBuilder.Entity("HyperBooru.Media", b => + { + b.HasOne("HyperBooru.UploadedFile", "CurrentUploadedFile") + .WithOne() + .HasForeignKey("HyperBooru.Media", "CurrentUploadedFileId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HyperBooru.HBObject", null) + .WithOne() + .HasForeignKey("HyperBooru.Media", "ObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CurrentUploadedFile"); + }); + + modelBuilder.Entity("HyperBooru.Tag", b => + { + b.HasOne("HyperBooru.HBObject", null) + .WithOne() + .HasForeignKey("HyperBooru.Tag", "ObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HyperBooru.TagDefinition", "TagDefinition") + .WithMany() + .HasForeignKey("TagDefinitionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HyperBooru.HBObject", "Target") + .WithMany("Tags") + .HasForeignKey("TargetObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("TagDefinition"); + + b.Navigation("Target"); + }); + + modelBuilder.Entity("HyperBooru.TagDefinition", b => + { + b.HasOne("HyperBooru.HBObject", null) + .WithOne() + .HasForeignKey("HyperBooru.TagDefinition", "ObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HyperBooru.UploadedFile", b => + { + b.HasOne("HyperBooru.Media", "Media") + .WithMany("UploadedFiles") + .HasForeignKey("MediaObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HyperBooru.HBObject", null) + .WithOne() + .HasForeignKey("HyperBooru.UploadedFile", "ObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Media"); + }); + + modelBuilder.Entity("HyperBooru.Group", b => + { + b.HasOne("HyperBooru.HBPrincipal", null) + .WithMany("MemberOf") + .HasForeignKey("HBPrincipalObjectId"); + }); + + modelBuilder.Entity("HyperBooru.User", b => + { + b.HasOne("HyperBooru.HBPrincipal", null) + .WithOne() + .HasForeignKey("HyperBooru.User", "ObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HyperBooru.HBObject", b => + { + b.Navigation("Acl"); + + b.Navigation("Tags"); + }); + + modelBuilder.Entity("HyperBooru.Acl", b => + { + b.Navigation("Rules"); + }); + + modelBuilder.Entity("HyperBooru.HBPrincipal", b => + { + b.Navigation("MemberOf"); + }); + + modelBuilder.Entity("HyperBooru.Media", b => + { + b.Navigation("OcrData"); + + b.Navigation("UploadedFiles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20230920052204_Security.cs b/Migrations/20230920052204_Security.cs new file mode 100644 index 0000000..982cb97 --- /dev/null +++ b/Migrations/20230920052204_Security.cs @@ -0,0 +1,194 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace HyperBooru.Migrations +{ + /// + public partial class Security : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Users_Objects_ObjectId", + table: "Users"); + + migrationBuilder.DropIndex( + name: "IX_Users_Username", + table: "Users"); + + migrationBuilder.DropColumn( + name: "Username", + table: "Users"); + + migrationBuilder.CreateTable( + name: "Acls", + columns: table => new + { + ObjectId = table.Column(type: "integer", nullable: false), + SubjectTempId1 = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Acls", x => x.ObjectId); + table.ForeignKey( + name: "FK_Acls_Objects_ObjectId", + column: x => x.ObjectId, + principalTable: "Objects", + principalColumn: "ObjectId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Principals", + columns: table => new + { + ObjectId = table.Column(type: "integer", nullable: false), + Name = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Principals", x => x.ObjectId); + }); + + migrationBuilder.CreateTable( + name: "AclRules", + columns: table => new + { + ObjectId = table.Column(type: "integer", nullable: false), + PrincipalObjectId = table.Column(type: "integer", nullable: false), + Action = table.Column(type: "integer", nullable: false), + Permissions = table.Column(type: "bigint", nullable: false), + AclObjectId = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AclRules", x => x.ObjectId); + table.ForeignKey( + name: "FK_AclRules_Acls_AclObjectId", + column: x => x.AclObjectId, + principalTable: "Acls", + principalColumn: "ObjectId"); + table.ForeignKey( + name: "FK_AclRules_Principals_PrincipalObjectId", + column: x => x.PrincipalObjectId, + principalTable: "Principals", + principalColumn: "ObjectId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Groups", + columns: table => new + { + ObjectId = table.Column(type: "integer", nullable: false), + HBPrincipalObjectId = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Groups", x => x.ObjectId); + table.ForeignKey( + name: "FK_Groups_Principals_HBPrincipalObjectId", + column: x => x.HBPrincipalObjectId, + principalTable: "Principals", + principalColumn: "ObjectId"); + }); + + migrationBuilder.UpdateData( + table: "Objects", + keyColumn: "ObjectId", + keyValue: -3, + column: "Guid", + value: new Guid("8fbbc2e9-0609-460a-ab3a-c3bdd10ab793")); + + migrationBuilder.InsertData( + table: "Principals", + columns: new[] { "ObjectId", "Name" }, + values: new object[] { -3, "admin" }); + + migrationBuilder.CreateIndex( + name: "IX_AclRules_AclObjectId", + table: "AclRules", + column: "AclObjectId"); + + migrationBuilder.CreateIndex( + name: "IX_AclRules_PrincipalObjectId", + table: "AclRules", + column: "PrincipalObjectId"); + + migrationBuilder.CreateIndex( + name: "IX_Groups_HBPrincipalObjectId", + table: "Groups", + column: "HBPrincipalObjectId"); + + migrationBuilder.CreateIndex( + name: "IX_Principals_Name", + table: "Principals", + column: "Name"); + + migrationBuilder.AddForeignKey( + name: "FK_Users_Principals_ObjectId", + table: "Users", + column: "ObjectId", + principalTable: "Principals", + principalColumn: "ObjectId", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Users_Principals_ObjectId", + table: "Users"); + + migrationBuilder.DropTable( + name: "AclRules"); + + migrationBuilder.DropTable( + name: "Groups"); + + migrationBuilder.DropTable( + name: "Acls"); + + migrationBuilder.DropTable( + name: "Principals"); + + migrationBuilder.AddColumn( + name: "Username", + table: "Users", + type: "text", + nullable: false, + defaultValue: ""); + + migrationBuilder.UpdateData( + table: "Objects", + keyColumn: "ObjectId", + keyValue: -3, + column: "Guid", + value: new Guid("4fa948f4-7c45-4f81-bb6b-e417491e6c96")); + + migrationBuilder.UpdateData( + table: "Users", + keyColumn: "ObjectId", + keyValue: -3, + column: "Username", + value: "admin"); + + migrationBuilder.CreateIndex( + name: "IX_Users_Username", + table: "Users", + column: "Username"); + + migrationBuilder.AddForeignKey( + name: "FK_Users_Objects_ObjectId", + table: "Users", + column: "ObjectId", + principalTable: "Objects", + principalColumn: "ObjectId", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/Migrations/HBContextModelSnapshot.cs b/Migrations/HBContextModelSnapshot.cs index da4c444..5514b9b 100644 --- a/Migrations/HBContextModelSnapshot.cs +++ b/Migrations/HBContextModelSnapshot.cs @@ -107,8 +107,8 @@ namespace HyperBooru.Migrations b.Property("Action") .HasColumnType("integer"); - b.Property("Permissions") - .HasColumnType("numeric(20,0)"); + b.Property("Permissions") + .HasColumnType("bigint"); b.Property("PrincipalObjectId") .HasColumnType("integer"); @@ -281,7 +281,7 @@ namespace HyperBooru.Migrations new { ObjectId = -3, - Guid = new Guid("bf62bd4c-806e-4d1b-a62d-0efffce8628a"), + Guid = new Guid("8fbbc2e9-0609-460a-ab3a-c3bdd10ab793"), Name = "admin", PasswordHash = "P4geAuE2yX/PDRHuJSq74FF5vO782rWz5c0LAQPR8m45DEYAONhu1wYnAn60PSNyjocqEBdnCeKCJfK3sKyuWw==" }); diff --git a/Pages/Component/AclDialog.razor b/Pages/Component/AclDialog.razor new file mode 100644 index 0000000..33d1f03 --- /dev/null +++ b/Pages/Component/AclDialog.razor @@ -0,0 +1,19 @@ +@implements IDialog + + + + +@code { + [Parameter] + public HBObject Object { get; set; } + + public bool Visible { + get => dialog.Visible; + set => dialog.Visible = value; + } + + private Dialog dialog; + + public void Show() => Visible = true; + public void Hide() => Visible = false; +} \ No newline at end of file diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json index b1659dc..9f4966c 100644 --- a/Properties/launchSettings.json +++ b/Properties/launchSettings.json @@ -13,7 +13,6 @@ "HyperBooru": { "commandName": "Project", "launchBrowser": true, - "launchUrl": "Login", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, diff --git a/Server.csproj b/Server.csproj index 3302b3e..ae08913 100644 --- a/Server.csproj +++ b/Server.csproj @@ -21,14 +21,14 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + diff --git a/Services/SecurityService.cs b/Services/SecurityService.cs index c8dafd5..6e5ecb8 100644 --- a/Services/SecurityService.cs +++ b/Services/SecurityService.cs @@ -1,4 +1,5 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Caching.Memory; using System.Data; namespace HyperBooru.Services; @@ -6,8 +7,8 @@ namespace HyperBooru.Services; public class SecurityService { private IDbContextFactory dbFactory; - private Group[] groups; - private Acl[] acls; + private Group[] groups; + private Acl[] acls; public SecurityService(IDbContextFactory dbFactory) { this.dbFactory = dbFactory; -- cgit v1.3