Blog Files model

This commit is contained in:
Paul Schneider 2026-03-01 02:13:26 +00:00
commit bfb37bc214
12 changed files with 318 additions and 173 deletions

View file

@ -76,7 +76,7 @@ namespace Yavsc.Models
builder.Entity<Notification>().Property(n => n.icon).HasDefaultValue("exclam");
builder.Entity<ChatRoomAccess>().HasKey(p => new { room = p.ChannelName, user = p.UserId });
builder.Entity<InstrumentRating>().HasAlternateKey(i => new { Instrument = i.InstrumentId, owner = i.OwnerId });
builder.Entity<BlogAttachedFile>().HasKey(i => new { i.FileId, i.PostId});
foreach (var et in builder.Model.GetEntityTypes())
{
if (et.ClrType.GetInterface("IBaseTrackedEntity") != null)
@ -283,5 +283,8 @@ namespace Yavsc.Models
public DbSet<ApiResourceProperty> ApiResourceProperties { get; set; }
public DbSet<ApiScopeClaim> ApiScopeClaims { get; set; }
public DbSet<ApiScopeProperty> ApiScopeProperties { get; set; }
public DbSet<BlogAttachedFile> blogAttachedFiles { get; set; }
public DbSet<UploadedFile> UploadedFiles { get; set; }
}
}

View file

@ -0,0 +1,59 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Org.BouncyCastle.Crypto.Modes;
namespace Yavsc.Models.Blog
{
public class UploadedFile
{
/// <summary>
/// File Identifier
/// </summary>
/// <value></value>
[Key(), DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Display(Name = "Identifiant du fichier")]
public long Id { get; set; }
/// <summary>
/// relative path to the file, relative to the poster space prefix
/// </summary>
/// <value></value>
public string Path { get; set; }
/// <summary>
/// Length
/// </summary> <summary>
///
/// </summary>
/// <value></value>
public long Length { get; set; }
/// <summary>
/// File Content type
/// </summary>
/// <value></value>
public string ContentType { get; set; }
}
public class BlogAttachedFile
{
/// <summary>
/// Post Id
/// </summary>
/// <value></value>
public long FileId { get; set; }
[ForeignKey("FileId")]
public virtual UploadedFile File { get; set; }
/// <summary>
/// Post Id
/// </summary>
/// <value></value>
public long PostId { get; set; }
[ForeignKey("PostId")]
public virtual BlogPost Post { get; set; }
}
}

View file

@ -9,26 +9,6 @@ using Yavsc.Models.Relationship;
namespace Yavsc.Models.Blog
{
public class BlogPostEditViewModel : BlogPost
{
public bool Publish { get; set; }
public BlogPostEditViewModel()
{
}
public BlogPostEditViewModel(BlogPost post, bool publish)
{
Id = post.Id;
AuthorId = post.AuthorId;
Photo = post.Photo;
Title = post.Title;
Article = post.Article;
Publish = publish;
ACL = post.ACL;
}
}
public class BlogPost :
IBlogPost, ICircleAuthorized, ITaggable<long>

View file

@ -0,0 +1,23 @@
namespace Yavsc.Models.Blog
{
public class BlogPostEditViewModel : BlogPost
{
public bool Publish { get; set; }
public BlogPostEditViewModel()
{
}
public BlogPostEditViewModel(BlogPost post, bool publish)
{
Id = post.Id;
AuthorId = post.AuthorId;
Photo = post.Photo;
Title = post.Title;
Article = post.Article;
Publish = publish;
ACL = post.ACL;
}
}
}

View file

@ -20,8 +20,6 @@ namespace Yavsc.Models.Haircut
public class HairCutQuery : NominativeServiceCommand
{
// Bill description
string _description = null;
public override string Description
{
get; set;
@ -62,7 +60,6 @@ namespace Yavsc.Models.Haircut
public string AdditionalInfo { get; set; }
public override List<IBillItem> GetBillItems()
{
string longhairsuffix = " (cheveux longs)";

View file

@ -42,29 +42,33 @@ namespace Yavsc.Services
ruleSetParser = new RuleSetParser(false);
}
public FileAccessRight GetFilePathAccess(ClaimsPrincipal user, string fileRelativePath)
/// <summary>
/// Get the file access info, for a given user, to a given FS absolute path
/// </summary>
/// <param name="clientUser"></param>
/// <param name="providerUserFilePath"></param>
/// <returns></returns>
public FileAccessRight GetFilePathAccess(ClaimsPrincipal clientUser, string providerUserFilePath)
{
var cusername = user.GetUserName();
var clientUserName = clientUser.GetUserName();
FileInfo fi = new FileInfo(
Path.Combine(Config.UserFilesDirName, fileRelativePath));
if (fileRelativePath.StartsWith(cusername+'/'))
Path.Combine(Config.UserFilesDirName, providerUserFilePath));
if (providerUserFilePath.StartsWith(clientUserName + '/'))
{
return FileAccessRight.Read | FileAccessRight.Write;
}
var funame = fileRelativePath.Split('/')[0];
// TODO Assert valid user name
var providerUserName = providerUserFilePath.Split('/')[0];
ruleSetParser.Reset();
var cuserid = user.GetUserId();
var cuserid = clientUser.GetUserId();
var fuserid = _dbContext.Users.SingleOrDefault(u => u.UserName == funame).Id;
var providerUserId = _dbContext.Users.SingleOrDefault(u => u.UserName == providerUserName).Id;
if (string.IsNullOrEmpty(fuserid)) return FileAccessRight.None;
if (string.IsNullOrEmpty(providerUserId)) return FileAccessRight.None;
var circles = _dbContext.Circle.Include(mb => mb.Members).Where(c => c.OwnerId == fuserid).ToArray();
var circles = _dbContext.Circle.Include(mb => mb.Members).Where(c => c.OwnerId == providerUserId).ToArray();
foreach (var circle in circles)
{
if (circle.Members.Any(m => m.MemberId == cuserid))
@ -72,11 +76,11 @@ namespace Yavsc.Services
else ruleSetParser.Definitions.Add(circle.Name, Out);
}
var userFilesDir = new DirectoryInfo(
Path.Combine(Config.UserFilesDirName, funame));
Path.Combine(Config.UserFilesDirName, providerUserName));
var currentACLDir = fi.Directory;
do
{
var aclfileName = Path.Combine(currentACLDir.FullName,
var aclfileName = Path.Combine(currentACLDir.FullName,
SiteSettings.AccessListFileName);
FileInfo accessFileInfo = new FileInfo(aclfileName);
if (accessFileInfo.Exists)
@ -85,20 +89,15 @@ namespace Yavsc.Services
} while (currentACLDir != userFilesDir);
if (ruleSetParser.Rules.Allow(cusername))
if (ruleSetParser.Rules.Allow(clientUserName))
{
return FileAccessRight.Read;
}
return FileAccessRight.None;
return FileAccessRight.None;
// TODO default user scoped file access policy
}
public string NormalizePath(string path)
{
throw new NotImplementedException();
}
public void SetAccess(long circleId, string normalizedFullPath, FileAccessRight access)
{
throw new NotImplementedException();

View file

@ -5,7 +5,7 @@ using Microsoft.Extensions.FileProviders;
namespace Yavsc.Services
{
[Flags]
public enum FileAccessRight {
public enum FileAccessRight : Byte {
None = 0,
Read = 1,
@ -13,7 +13,6 @@ namespace Yavsc.Services
}
public interface IFileSystemAuthManager {
string NormalizePath (string path);
/// <summary>
///