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
|
|
@ -2,7 +2,7 @@
|
|||
namespace Yavsc.Models.Access
|
||||
{
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Yavsc.Abstract.Identity.Security;
|
||||
using System.Text.Json.Serialization;
|
||||
using Models.Relationship;
|
||||
using Yavsc.Services;
|
||||
|
||||
|
|
@ -10,14 +10,15 @@ namespace Yavsc.Models.Access
|
|||
{
|
||||
public FileAccessRight Access { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class FileAccessControlRulePayload : CircleAuthorization
|
||||
{
|
||||
public virtual string FileId { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
[ForeignKey("CircleId")]
|
||||
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<Instrumentation>().HasKey(u => new { u.InstrumentId, u.UserId });
|
||||
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>()
|
||||
.HasOne(a => a.Allowed)
|
||||
.WithMany()
|
||||
.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>()
|
||||
.Property(a => a.Access)
|
||||
.HasConversion<byte>();
|
||||
|
|
|
|||
|
|
@ -99,8 +99,16 @@ namespace Yavsc.Services
|
|||
|
||||
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 =>
|
||||
a.CircleId == circleId && a.FileId == normalizedFullPath);
|
||||
a.CircleId == circleId && a.Path == normalizedFullPath && a.OwnerId == providerUserId);
|
||||
|
||||
if (access == FileAccessRight.None)
|
||||
{
|
||||
|
|
@ -118,7 +126,8 @@ namespace Yavsc.Services
|
|||
_dbContext.CircleAuthorizationToFile.Add(new CircleAuthorizationToFile
|
||||
{
|
||||
CircleId = circleId,
|
||||
FileId = normalizedFullPath,
|
||||
Path = normalizedFullPath,
|
||||
OwnerId = providerUserId,
|
||||
Access = access
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue