share the workflow config
This commit is contained in:
parent
005a4f1ef8
commit
2bc0ce7a18
5 changed files with 83 additions and 80 deletions
|
|
@ -15,6 +15,7 @@ using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Yavsc.Helpers;
|
||||||
using Yavsc.Interface;
|
using Yavsc.Interface;
|
||||||
using Yavsc.Models;
|
using Yavsc.Models;
|
||||||
using Yavsc.Services;
|
using Yavsc.Services;
|
||||||
|
|
@ -71,13 +72,14 @@ internal class Program
|
||||||
services.AddTransient<ITrueEmailSender, MailSender>()
|
services.AddTransient<ITrueEmailSender, MailSender>()
|
||||||
.AddTransient<IBillingService, BillingService>()
|
.AddTransient<IBillingService, BillingService>()
|
||||||
.AddTransient<ICalendarManager, CalendarManager>();
|
.AddTransient<ICalendarManager, CalendarManager>();
|
||||||
|
services.AddTransient<IFileSystemAuthManager, FileSystemAuthManager>();
|
||||||
/*
|
/*
|
||||||
services.AddSingleton<IConnexionManager, HubConnectionManager>();
|
services.AddSingleton<IConnexionManager, HubConnectionManager>();
|
||||||
services.AddSingleton<ILiveProcessor, LiveProcessor>();
|
services.AddSingleton<ILiveProcessor, LiveProcessor>();
|
||||||
services.AddTransient<IFileSystemAuthManager, FileSystemAuthManager>();
|
|
||||||
services.AddIdentityApiEndpoints<ApplicationUser>();
|
services.AddIdentityApiEndpoints<ApplicationUser>();
|
||||||
services.AddSession();
|
services.AddSession();
|
||||||
*/
|
*/
|
||||||
|
WorkflowHelpers.ConfigureBillingService();
|
||||||
using (var app = builder.Build())
|
using (var app = builder.Build())
|
||||||
{
|
{
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,19 @@ namespace Yavsc.Helpers
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Yavsc.Abstract.Workflow;
|
||||||
|
using Yavsc.Billing;
|
||||||
using Yavsc.Models;
|
using Yavsc.Models;
|
||||||
|
using Yavsc.Models.Billing;
|
||||||
|
using Yavsc.Models.Haircut;
|
||||||
|
using Yavsc.Models.Workflow;
|
||||||
using Yavsc.Services;
|
using Yavsc.Services;
|
||||||
using Yavsc.ViewModels.FrontOffice;
|
using Yavsc.ViewModels.FrontOffice;
|
||||||
|
|
||||||
public static class WorkflowHelpers
|
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,
|
IBillingService billing,
|
||||||
string actCode)
|
string actCode)
|
||||||
{
|
{
|
||||||
|
|
@ -32,5 +38,53 @@ namespace Yavsc.Helpers
|
||||||
return result;
|
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 SiteSettings SiteSettings;
|
||||||
|
|
||||||
private readonly string aclfileName;
|
|
||||||
|
|
||||||
readonly RuleSetParser ruleSetParser;
|
readonly RuleSetParser ruleSetParser;
|
||||||
|
|
||||||
public FileSystemAuthManager(ApplicationDbContext dbContext, IOptions<SiteSettings> sitesOptions)
|
public FileSystemAuthManager(ApplicationDbContext dbContext, IOptions<SiteSettings> sitesOptions)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
SiteSettings = sitesOptions.Value;
|
SiteSettings = sitesOptions.Value;
|
||||||
aclfileName = SiteSettings.AccessListFileName;
|
|
||||||
ruleSetParser = new RuleSetParser(false);
|
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 cusername = user.GetUserName();
|
||||||
|
FileInfo fi = new FileInfo(
|
||||||
var funame = parts[cwd+1];
|
Path.Combine(Config.UserFilesDirName, fileRelativePath));
|
||||||
if (funame == cusername)
|
|
||||||
|
if (fileRelativePath.StartsWith(cusername+'/'))
|
||||||
{
|
{
|
||||||
return FileAccessRight.Read | FileAccessRight.Write;
|
return FileAccessRight.Read | FileAccessRight.Write;
|
||||||
}
|
}
|
||||||
|
var funame = fileRelativePath.Split('/')[0];
|
||||||
|
|
||||||
if (aclfileName == fileName)
|
// TODO Assert valid user name
|
||||||
return FileAccessRight.None;
|
|
||||||
|
|
||||||
ruleSetParser.Reset();
|
ruleSetParser.Reset();
|
||||||
var cuserid = user.GetUserId();
|
var cuserid = user.GetUserId();
|
||||||
|
|
@ -81,15 +70,19 @@ namespace Yavsc.Services
|
||||||
ruleSetParser.Definitions.Add(circle.Name, In);
|
ruleSetParser.Definitions.Add(circle.Name, In);
|
||||||
else ruleSetParser.Definitions.Add(circle.Name, Out);
|
else ruleSetParser.Definitions.Add(circle.Name, Out);
|
||||||
}
|
}
|
||||||
|
var userFilesDir = new DirectoryInfo(
|
||||||
for (int dirlevel = parts.Length - 1; dirlevel > cwd + 1; dirlevel--)
|
Path.Combine(Config.UserFilesDirName, funame));
|
||||||
|
var currentACLDir = fi.Directory;
|
||||||
|
do
|
||||||
{
|
{
|
||||||
fileDir = string.Join(Path.DirectorySeparatorChar.ToString(), parts.Take(dirlevel));
|
var aclfileName = Path.Combine(currentACLDir.FullName,
|
||||||
var aclfin = Path.Combine(fileDir, aclfileName);
|
SiteSettings.AccessListFileName);
|
||||||
var aclfi = new FileInfo(aclfin);
|
FileInfo accessFileInfo = new FileInfo(aclfileName);
|
||||||
if (!aclfi.Exists) continue;
|
if (accessFileInfo.Exists)
|
||||||
ruleSetParser.ParseFile(aclfi.FullName);
|
ruleSetParser.ParseFile(accessFileInfo.FullName);
|
||||||
}
|
currentACLDir = currentACLDir.Parent;
|
||||||
|
} while (currentACLDir != userFilesDir);
|
||||||
|
|
||||||
|
|
||||||
if (ruleSetParser.Rules.Allow(cusername))
|
if (ruleSetParser.Rules.Allow(cusername))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,12 @@ namespace Yavsc.Services
|
||||||
string NormalizePath (string path);
|
string NormalizePath (string path);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A full path starts with a slash,
|
///
|
||||||
/// continues with a user name,
|
|
||||||
/// and returns true by the helper fonction :
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="user"></param>
|
/// <param name="user"></param>
|
||||||
/// <param name="normalizedFullPath"></param>
|
/// <param name="normalizedFullPath"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
FileAccessRight GetFilePathAccess(ClaimsPrincipal user, IFileInfo file);
|
FileAccessRight GetFilePathAccess(ClaimsPrincipal user, string fileRelativePath);
|
||||||
|
|
||||||
void SetAccess (long circleId, string normalizedFullPath, FileAccessRight access);
|
void SetAccess (long circleId, string normalizedFullPath, FileAccessRight access);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,51 +90,6 @@ public static class HostingExtensions
|
||||||
|
|
||||||
#endregion
|
#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)
|
internal static WebApplication ConfigureWebAppServices(this WebApplicationBuilder builder)
|
||||||
{
|
{
|
||||||
|
|
@ -410,7 +365,8 @@ public static class HostingExtensions
|
||||||
//pp.MapRazorPages();
|
//pp.MapRazorPages();
|
||||||
app.MapHub<ChatHub>("/chatHub");
|
app.MapHub<ChatHub>("/chatHub");
|
||||||
|
|
||||||
ConfigureWorkflow();
|
WorkflowHelpers.ConfigureBillingService();
|
||||||
|
|
||||||
var services = app.Services;
|
var services = app.Services;
|
||||||
ILoggerFactory loggerFactory = services.GetRequiredService<ILoggerFactory>();
|
ILoggerFactory loggerFactory = services.GetRequiredService<ILoggerFactory>();
|
||||||
var siteSettings = services.GetRequiredService<IOptions<SiteSettings>>();
|
var siteSettings = services.GetRequiredService<IOptions<SiteSettings>>();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue