CircleAuthorizationToFile EF migration
All checks were successful
Dotnet build and test / build (pull_request) Successful in 6m15s
All checks were successful
Dotnet build and test / build (pull_request) Successful in 6m15s
This commit is contained in:
parent
10fdcb288c
commit
38bc659a58
7 changed files with 4950 additions and 11 deletions
|
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
namespace Yavsc.Models.Access
|
||||||
|
{
|
||||||
|
using Yavsc.Abstract.Identity.Security;
|
||||||
|
|
||||||
|
public class FileAccessControlRulePayload : CircleAuthorization
|
||||||
|
{
|
||||||
|
public virtual string Path { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
4818
src/Yavsc.Org/Migrations/20260907100133_fileACL.Designer.cs
generated
Normal file
4818
src/Yavsc.Org/Migrations/20260907100133_fileACL.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
52
src/Yavsc.Org/Migrations/20260907100133_fileACL.cs
Normal file
52
src/Yavsc.Org/Migrations/20260907100133_fileACL.cs
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Yavsc.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class fileACL : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "CircleAuthorizationToFile",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
CircleId = table.Column<long>(type: "bigint", nullable: false),
|
||||||
|
Path = table.Column<string>(type: "text", nullable: false),
|
||||||
|
OwnerId = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Access = table.Column<byte>(type: "smallint", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_CircleAuthorizationToFile", x => new { x.CircleId, x.Path, x.OwnerId });
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_CircleAuthorizationToFile_AspNetUsers_OwnerId",
|
||||||
|
column: x => x.OwnerId,
|
||||||
|
principalTable: "AspNetUsers",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_CircleAuthorizationToFile_Circle_CircleId",
|
||||||
|
column: x => x.CircleId,
|
||||||
|
principalTable: "Circle",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_CircleAuthorizationToFile_OwnerId",
|
||||||
|
table: "CircleAuthorizationToFile",
|
||||||
|
column: "OwnerId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "CircleAuthorizationToFile");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1088,6 +1088,27 @@ namespace Yavsc.Migrations
|
||||||
b.ToTable("CircleAuthorizationToBlogPost");
|
b.ToTable("CircleAuthorizationToBlogPost");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Yavsc.Models.Access.CircleAuthorizationToFile", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("CircleId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<string>("Path")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("OwnerId")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<byte>("Access")
|
||||||
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
|
b.HasKey("CircleId", "Path", "OwnerId");
|
||||||
|
|
||||||
|
b.HasIndex("OwnerId");
|
||||||
|
|
||||||
|
b.ToTable("CircleAuthorizationToFile");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Yavsc.Models.AccountBalance", b =>
|
modelBuilder.Entity("Yavsc.Models.AccountBalance", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("UserId")
|
b.Property<string>("UserId")
|
||||||
|
|
@ -3767,6 +3788,25 @@ namespace Yavsc.Migrations
|
||||||
b.Navigation("Target");
|
b.Navigation("Target");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Yavsc.Models.Access.CircleAuthorizationToFile", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Yavsc.Models.Relationship.Circle", "Allowed")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("CircleId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Yavsc.Models.ApplicationUser", "Owner")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("OwnerId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Allowed");
|
||||||
|
|
||||||
|
b.Navigation("Owner");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Yavsc.Models.AccountBalance", b =>
|
modelBuilder.Entity("Yavsc.Models.AccountBalance", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Yavsc.Models.ApplicationUser", "Owner")
|
b.HasOne("Yavsc.Models.ApplicationUser", "Owner")
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
namespace Yavsc.Models.Access
|
namespace Yavsc.Models.Access
|
||||||
{
|
{
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using Yavsc.Abstract.Identity.Security;
|
using System.Text.Json.Serialization;
|
||||||
using Models.Relationship;
|
using Models.Relationship;
|
||||||
using Yavsc.Services;
|
using Yavsc.Services;
|
||||||
|
|
||||||
|
|
@ -10,14 +10,15 @@ namespace Yavsc.Models.Access
|
||||||
{
|
{
|
||||||
public FileAccessRight Access { get; set; }
|
public FileAccessRight Access { get; set; }
|
||||||
|
|
||||||
}
|
[JsonIgnore]
|
||||||
|
|
||||||
public class FileAccessControlRulePayload : CircleAuthorization
|
|
||||||
{
|
|
||||||
public virtual string FileId { get; set; }
|
|
||||||
|
|
||||||
[ForeignKey("CircleId")]
|
[ForeignKey("CircleId")]
|
||||||
public virtual Circle Allowed { get; set; }
|
public virtual Circle Allowed { get; set; }
|
||||||
|
|
||||||
|
public string OwnerId { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
[ForeignKey("OwnerId")]
|
||||||
|
public virtual ApplicationUser Owner { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -96,12 +96,19 @@ namespace Yavsc.Models
|
||||||
builder.Entity<UserActivity>().HasKey(u => new { u.DoesCode, u.UserId });
|
builder.Entity<UserActivity>().HasKey(u => new { u.DoesCode, u.UserId });
|
||||||
builder.Entity<Instrumentation>().HasKey(u => new { u.InstrumentId, u.UserId });
|
builder.Entity<Instrumentation>().HasKey(u => new { u.InstrumentId, u.UserId });
|
||||||
builder.Entity<CircleAuthorizationToBlogPost>().HasKey(a => new { a.CircleId, a.BlogPostId });
|
builder.Entity<CircleAuthorizationToBlogPost>().HasKey(a => new { a.CircleId, a.BlogPostId });
|
||||||
builder.Entity<CircleAuthorizationToFile>().HasKey(a => new { a.CircleId, a.FileId });
|
builder.Entity<CircleAuthorizationToFile>().HasKey(a => new { a.CircleId, a.Path, a.OwnerId });
|
||||||
builder.Entity<CircleAuthorizationToFile>()
|
builder.Entity<CircleAuthorizationToFile>()
|
||||||
.HasOne(a => a.Allowed)
|
.HasOne(a => a.Allowed)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey(a => a.CircleId)
|
.HasForeignKey(a => a.CircleId)
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
;
|
||||||
|
builder.Entity<CircleAuthorizationToFile>()
|
||||||
|
.HasOne(a => a.Owner)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey(a => a.OwnerId)
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
;
|
||||||
builder.Entity<CircleAuthorizationToFile>()
|
builder.Entity<CircleAuthorizationToFile>()
|
||||||
.Property(a => a.Access)
|
.Property(a => a.Access)
|
||||||
.HasConversion<byte>();
|
.HasConversion<byte>();
|
||||||
|
|
|
||||||
|
|
@ -99,8 +99,16 @@ namespace Yavsc.Services
|
||||||
|
|
||||||
public void SetAccess(long circleId, string normalizedFullPath, FileAccessRight access)
|
public void SetAccess(long circleId, string normalizedFullPath, FileAccessRight access)
|
||||||
{
|
{
|
||||||
|
var providerUserName = normalizedFullPath.Split('/')[0];
|
||||||
|
var providerUserId = _dbContext.Users.SingleOrDefault(u => u.UserName == providerUserName)?.Id;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(providerUserId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var acl = _dbContext.CircleAuthorizationToFile.SingleOrDefault(a =>
|
var acl = _dbContext.CircleAuthorizationToFile.SingleOrDefault(a =>
|
||||||
a.CircleId == circleId && a.FileId == normalizedFullPath);
|
a.CircleId == circleId && a.Path == normalizedFullPath && a.OwnerId == providerUserId);
|
||||||
|
|
||||||
if (access == FileAccessRight.None)
|
if (access == FileAccessRight.None)
|
||||||
{
|
{
|
||||||
|
|
@ -118,7 +126,8 @@ namespace Yavsc.Services
|
||||||
_dbContext.CircleAuthorizationToFile.Add(new CircleAuthorizationToFile
|
_dbContext.CircleAuthorizationToFile.Add(new CircleAuthorizationToFile
|
||||||
{
|
{
|
||||||
CircleId = circleId,
|
CircleId = circleId,
|
||||||
FileId = normalizedFullPath,
|
Path = normalizedFullPath,
|
||||||
|
OwnerId = providerUserId,
|
||||||
Access = access
|
Access = access
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue