share the workflow config
This commit is contained in:
@ -15,6 +15,7 @@ using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Yavsc.Helpers;
|
||||
using Yavsc.Interface;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Services;
|
||||
@ -71,13 +72,14 @@ internal class Program
|
||||
services.AddTransient<ITrueEmailSender, MailSender>()
|
||||
.AddTransient<IBillingService, BillingService>()
|
||||
.AddTransient<ICalendarManager, CalendarManager>();
|
||||
services.AddTransient<IFileSystemAuthManager, FileSystemAuthManager>();
|
||||
/*
|
||||
services.AddSingleton<IConnexionManager, HubConnectionManager>();
|
||||
services.AddSingleton<ILiveProcessor, LiveProcessor>();
|
||||
services.AddTransient<IFileSystemAuthManager, FileSystemAuthManager>();
|
||||
services.AddIdentityApiEndpoints<ApplicationUser>();
|
||||
services.AddSession();
|
||||
*/
|
||||
*/
|
||||
WorkflowHelpers.ConfigureBillingService();
|
||||
using (var app = builder.Build())
|
||||
{
|
||||
if (app.Environment.IsDevelopment())
|
||||
|
@ -5,13 +5,19 @@ namespace Yavsc.Helpers
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Yavsc.Abstract.Workflow;
|
||||
using Yavsc.Billing;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Billing;
|
||||
using Yavsc.Models.Haircut;
|
||||
using Yavsc.Models.Workflow;
|
||||
using Yavsc.Services;
|
||||
using Yavsc.ViewModels.FrontOffice;
|
||||
|
||||
public static class WorkflowHelpers
|
||||
{
|
||||
public static async Task<List<PerformerProfileViewModel>> ListPerformersAsync(this ApplicationDbContext context,
|
||||
public static async Task<List<PerformerProfileViewModel>>
|
||||
ListPerformersAsync(this ApplicationDbContext context,
|
||||
IBillingService billing,
|
||||
string actCode)
|
||||
{
|
||||
@ -32,5 +38,53 @@ namespace Yavsc.Helpers
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void RegisterBilling<T>(string code, Func<ApplicationDbContext, long,
|
||||
IDecidableQuery> getter) where T : IBillable
|
||||
{
|
||||
BillingService.Billing.Add(code, getter);
|
||||
BillingService.GlobalBillingMap.Add(typeof(T).Name, code);
|
||||
}
|
||||
|
||||
public static void ConfigureBillingService()
|
||||
{
|
||||
foreach (var a in System.AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
foreach (var c in a.GetTypes())
|
||||
{
|
||||
if (c.IsClass && !c.IsAbstract &&
|
||||
c.GetInterface("ISpecializationSettings") != null)
|
||||
{
|
||||
Config.ProfileTypes.Add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var propertyInfo in typeof(ApplicationDbContext).GetProperties())
|
||||
{
|
||||
foreach (var attr in propertyInfo.CustomAttributes)
|
||||
{
|
||||
// something like a DbSet?
|
||||
if (typeof(Yavsc.Attributes.ActivitySettingsAttribute).IsAssignableFrom(attr.AttributeType))
|
||||
{
|
||||
BillingService.UserSettings.Add(propertyInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RegisterBilling<HairCutQuery>(BillingCodes.Brush, new Func<ApplicationDbContext, long, IDecidableQuery>
|
||||
((db, id) =>
|
||||
{
|
||||
var query = db.HairCutQueries.Include(q => q.Prestation).Include(q => q.Regularisation).Single(q => q.Id == id);
|
||||
query.SelectedProfile = db.BrusherProfile.Single(b => b.UserId == query.PerformerId);
|
||||
return query;
|
||||
}));
|
||||
|
||||
RegisterBilling<HairMultiCutQuery>(BillingCodes.MBrush, new Func<ApplicationDbContext, long, IDecidableQuery>
|
||||
((db, id) => db.HairMultiCutQueries.Include(q => q.Regularisation).Single(q => q.Id == id)));
|
||||
|
||||
RegisterBilling<RdvQuery>(BillingCodes.Rdv, new Func<ApplicationDbContext, long, IDecidableQuery>
|
||||
((db, id) => db.RdvQueries.Include(q => q.Regularisation).Single(q => q.Id == id)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -32,40 +32,29 @@ namespace Yavsc.Services
|
||||
|
||||
private readonly SiteSettings SiteSettings;
|
||||
|
||||
private readonly string aclfileName;
|
||||
|
||||
readonly RuleSetParser ruleSetParser;
|
||||
|
||||
public FileSystemAuthManager(ApplicationDbContext dbContext, IOptions<SiteSettings> sitesOptions)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
SiteSettings = sitesOptions.Value;
|
||||
aclfileName = SiteSettings.AccessListFileName;
|
||||
ruleSetParser = new RuleSetParser(false);
|
||||
}
|
||||
|
||||
public FileAccessRight GetFilePathAccess(ClaimsPrincipal user, IFileInfo file)
|
||||
public FileAccessRight GetFilePathAccess(ClaimsPrincipal user, string fileRelativePath)
|
||||
{
|
||||
var parts = file.PhysicalPath.Split(Path.DirectorySeparatorChar);
|
||||
var cwd = Environment.CurrentDirectory.Split(Path.DirectorySeparatorChar).Length;
|
||||
|
||||
|
||||
// below 3 parts behind cwd, no file name.
|
||||
if (parts.Length < cwd + 3) return FileAccessRight.None;
|
||||
|
||||
var fileDir = string.Join("/", parts.Take(parts.Length - 1));
|
||||
var fileName = parts[parts.Length - 1];
|
||||
|
||||
|
||||
var cusername = user.GetUserName();
|
||||
|
||||
var funame = parts[cwd+1];
|
||||
if (funame == cusername)
|
||||
FileInfo fi = new FileInfo(
|
||||
Path.Combine(Config.UserFilesDirName, fileRelativePath));
|
||||
|
||||
if (fileRelativePath.StartsWith(cusername+'/'))
|
||||
{
|
||||
return FileAccessRight.Read | FileAccessRight.Write;
|
||||
}
|
||||
var funame = fileRelativePath.Split('/')[0];
|
||||
|
||||
if (aclfileName == fileName)
|
||||
return FileAccessRight.None;
|
||||
// TODO Assert valid user name
|
||||
|
||||
ruleSetParser.Reset();
|
||||
var cuserid = user.GetUserId();
|
||||
@ -81,15 +70,19 @@ namespace Yavsc.Services
|
||||
ruleSetParser.Definitions.Add(circle.Name, In);
|
||||
else ruleSetParser.Definitions.Add(circle.Name, Out);
|
||||
}
|
||||
|
||||
for (int dirlevel = parts.Length - 1; dirlevel > cwd + 1; dirlevel--)
|
||||
var userFilesDir = new DirectoryInfo(
|
||||
Path.Combine(Config.UserFilesDirName, funame));
|
||||
var currentACLDir = fi.Directory;
|
||||
do
|
||||
{
|
||||
fileDir = string.Join(Path.DirectorySeparatorChar.ToString(), parts.Take(dirlevel));
|
||||
var aclfin = Path.Combine(fileDir, aclfileName);
|
||||
var aclfi = new FileInfo(aclfin);
|
||||
if (!aclfi.Exists) continue;
|
||||
ruleSetParser.ParseFile(aclfi.FullName);
|
||||
}
|
||||
var aclfileName = Path.Combine(currentACLDir.FullName,
|
||||
SiteSettings.AccessListFileName);
|
||||
FileInfo accessFileInfo = new FileInfo(aclfileName);
|
||||
if (accessFileInfo.Exists)
|
||||
ruleSetParser.ParseFile(accessFileInfo.FullName);
|
||||
currentACLDir = currentACLDir.Parent;
|
||||
} while (currentACLDir != userFilesDir);
|
||||
|
||||
|
||||
if (ruleSetParser.Rules.Allow(cusername))
|
||||
{
|
||||
|
@ -16,14 +16,12 @@ namespace Yavsc.Services
|
||||
string NormalizePath (string path);
|
||||
|
||||
/// <summary>
|
||||
/// A full path starts with a slash,
|
||||
/// continues with a user name,
|
||||
/// and returns true by the helper fonction :
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="normalizedFullPath"></param>
|
||||
/// <returns></returns>
|
||||
FileAccessRight GetFilePathAccess(ClaimsPrincipal user, IFileInfo file);
|
||||
FileAccessRight GetFilePathAccess(ClaimsPrincipal user, string fileRelativePath);
|
||||
|
||||
void SetAccess (long circleId, string normalizedFullPath, FileAccessRight access);
|
||||
|
||||
|
@ -90,51 +90,6 @@ public static class HostingExtensions
|
||||
|
||||
#endregion
|
||||
|
||||
public static void ConfigureWorkflow()
|
||||
{
|
||||
foreach (var a in System.AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
foreach (var c in a.GetTypes())
|
||||
{
|
||||
if (c.IsClass && !c.IsAbstract &&
|
||||
c.GetInterface("ISpecializationSettings") != null)
|
||||
{
|
||||
Config.ProfileTypes.Add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var propertyInfo in typeof(ApplicationDbContext).GetProperties())
|
||||
{
|
||||
foreach (var attr in propertyInfo.CustomAttributes)
|
||||
{
|
||||
// something like a DbSet?
|
||||
if (typeof(Yavsc.Attributes.ActivitySettingsAttribute).IsAssignableFrom(attr.AttributeType))
|
||||
{
|
||||
BillingService.UserSettings.Add(propertyInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RegisterBilling<HairCutQuery>(BillingCodes.Brush, new Func<ApplicationDbContext, long, IDecidableQuery>
|
||||
((db, id) =>
|
||||
{
|
||||
var query = db.HairCutQueries.Include(q => q.Prestation).Include(q => q.Regularisation).Single(q => q.Id == id);
|
||||
query.SelectedProfile = db.BrusherProfile.Single(b => b.UserId == query.PerformerId);
|
||||
return query;
|
||||
}));
|
||||
|
||||
RegisterBilling<HairMultiCutQuery>(BillingCodes.MBrush, new Func<ApplicationDbContext, long, IDecidableQuery>
|
||||
((db, id) => db.HairMultiCutQueries.Include(q => q.Regularisation).Single(q => q.Id == id)));
|
||||
|
||||
RegisterBilling<RdvQuery>(BillingCodes.Rdv, new Func<ApplicationDbContext, long, IDecidableQuery>
|
||||
((db, id) => db.RdvQueries.Include(q => q.Regularisation).Single(q => q.Id == id)));
|
||||
}
|
||||
public static void RegisterBilling<T>(string code, Func<ApplicationDbContext, long, IDecidableQuery> getter) where T : IBillable
|
||||
{
|
||||
BillingService.Billing.Add(code, getter);
|
||||
BillingService.GlobalBillingMap.Add(typeof(T).Name, code);
|
||||
}
|
||||
|
||||
internal static WebApplication ConfigureWebAppServices(this WebApplicationBuilder builder)
|
||||
{
|
||||
@ -410,7 +365,8 @@ public static class HostingExtensions
|
||||
//pp.MapRazorPages();
|
||||
app.MapHub<ChatHub>("/chatHub");
|
||||
|
||||
ConfigureWorkflow();
|
||||
WorkflowHelpers.ConfigureBillingService();
|
||||
|
||||
var services = app.Services;
|
||||
ILoggerFactory loggerFactory = services.GetRequiredService<ILoggerFactory>();
|
||||
var siteSettings = services.GetRequiredService<IOptions<SiteSettings>>();
|
||||
|
Reference in New Issue
Block a user