From e24208e77b77fced882184391faeac6b30251b29 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sat, 30 May 2026 19:34:22 +0100 Subject: [PATCH] refact --- .../Business/EstimateApiController.cs | 10 ++++---- .../EstimateTemplatesApiController.cs | 4 ++-- .../Business/ProductApiController.cs | 6 ++--- src/Api/Controllers/PostRateApiController.cs | 2 +- .../Relationship/BlackListApiController.cs | 4 ++-- .../ChatRoomAccessApiController.cs | 8 +++---- .../Relationship/ChatRoomApiController.cs | 2 +- src/Api/Controllers/ServiceApiController.cs | 6 ++--- src/Api/Program.cs | 2 +- .../Authentication/RegisterModel.cs | 4 ++-- src/Yavsc.Abstract/Constants.cs | 2 +- src/Yavsc.Blogs/Program.cs | 4 ++-- .../Accounting/AccountController.cs | 12 +++++----- .../AdministrationController.cs | 22 ++++++++--------- .../Communicating/AnnouncesController.cs | 8 +++---- .../Communicating/BlogspotController.cs | 2 +- .../Contracting/ActivityController.cs | 12 +++++----- src/Yavsc.Org/Controllers/HomeController.cs | 4 ++-- .../Musical/InstrumentationController.cs | 10 ++++---- src/Yavsc.Org/Extensions/HostingExtensions.cs | 24 +++++++++---------- src/Yavsc.Org/Program.cs | 4 +++- .../ViewModels/Manage/SetUserNameViewModel.cs | 2 +- .../Views/Shared/_LoginPartial.cshtml | 2 +- src/Yavsc.Server/Helpers/HtmlHelpers.cs | 2 +- src/Yavsc.Server/Hubs/ChatHub.cs | 4 ++-- .../Models/ApplicationDbContext.cs | 4 ++-- src/Yavsc.Server/Services/LiveProcessor.cs | 4 ++-- src/Yavsc.Server/Services/ProfileService.cs | 6 ++--- .../ExternalLoginConfirmationViewModel.cs | 4 ++-- src/cli/Commands/Streamer.cs | 4 ++-- src/cli/Settings/ConnectionSettings.cs | 4 ++-- test/yavscTests/WebServerFixture.cs | 2 +- 32 files changed, 96 insertions(+), 94 deletions(-) diff --git a/src/Api/Controllers/Business/EstimateApiController.cs b/src/Api/Controllers/Business/EstimateApiController.cs index f7cb1e6c..9b3ca807 100644 --- a/src/Api/Controllers/Business/EstimateApiController.cs +++ b/src/Api/Controllers/Business/EstimateApiController.cs @@ -27,12 +27,12 @@ namespace Yavsc.Controllers } bool UserIsAdminOrThis(string uid) { - if (User.IsInRole(Constants.AdminGroupName)) return true; + if (User.IsInRole(YavscConstants.AdminGroupName)) return true; return uid == User.GetUserId(); } bool UserIsAdminOrInThese(string oid, string uid) { - if (User.IsInRole(Constants.AdminGroupName)) return true; + if (User.IsInRole(YavscConstants.AdminGroupName)) return true; var cuid = User.GetUserId(); return cuid == uid || cuid == oid; } @@ -82,7 +82,7 @@ namespace Yavsc.Controllers return BadRequest(); } var uid = User.FindFirstValue(ClaimTypes.NameIdentifier); - if (!User.IsInRole(Constants.AdminGroupName)) + if (!User.IsInRole(YavscConstants.AdminGroupName)) { if (uid != estimate.OwnerId) { @@ -118,7 +118,7 @@ namespace Yavsc.Controllers var uid = User.FindFirstValue(ClaimTypes.NameIdentifier); if (estimate.OwnerId == null) estimate.OwnerId = uid; - if (!User.IsInRole(Constants.AdminGroupName)) + if (!User.IsInRole(YavscConstants.AdminGroupName)) { if (uid != estimate.OwnerId) { @@ -187,7 +187,7 @@ namespace Yavsc.Controllers return NotFound(); } var uid = User.FindFirstValue(ClaimTypes.NameIdentifier); - if (!User.IsInRole(Constants.AdminGroupName)) + if (!User.IsInRole(YavscConstants.AdminGroupName)) { if (uid != estimate.OwnerId) { diff --git a/src/Api/Controllers/Business/EstimateTemplatesApiController.cs b/src/Api/Controllers/Business/EstimateTemplatesApiController.cs index 073cb7ce..4442e0b3 100644 --- a/src/Api/Controllers/Business/EstimateTemplatesApiController.cs +++ b/src/Api/Controllers/Business/EstimateTemplatesApiController.cs @@ -62,7 +62,7 @@ namespace Yavsc.Controllers } var uid = User.FindFirstValue(ClaimTypes.NameIdentifier); if (estimateTemplate.OwnerId!=uid) - if (!User.IsInRole(Constants.AdminGroupName)) + if (!User.IsInRole(YavscConstants.AdminGroupName)) return new StatusCodeResult(StatusCodes.Status403Forbidden); _context.Entry(estimateTemplate).State = EntityState.Modified; @@ -132,7 +132,7 @@ namespace Yavsc.Controllers } var uid = User.FindFirstValue(ClaimTypes.NameIdentifier); if (estimateTemplate.OwnerId!=uid) - if (!User.IsInRole(Constants.AdminGroupName)) + if (!User.IsInRole(YavscConstants.AdminGroupName)) return new StatusCodeResult(StatusCodes.Status403Forbidden); _context.EstimateTemplates.Remove(estimateTemplate); diff --git a/src/Api/Controllers/Business/ProductApiController.cs b/src/Api/Controllers/Business/ProductApiController.cs index 211104c9..abd621c3 100644 --- a/src/Api/Controllers/Business/ProductApiController.cs +++ b/src/Api/Controllers/Business/ProductApiController.cs @@ -46,7 +46,7 @@ namespace Yavsc.Controllers } // PUT: api/ProductApi/5 - [HttpPut("{id}"),Authorize(Constants.FrontOfficeGroupName)] + [HttpPut("{id}"),Authorize(YavscConstants.FrontOfficeGroupName)] public IActionResult PutProduct(long id, [FromBody] Product product) { if (!ModelState.IsValid) @@ -81,7 +81,7 @@ namespace Yavsc.Controllers } // POST: api/ProductApi - [HttpPost,Authorize(Constants.FrontOfficeGroupName)] + [HttpPost,Authorize(YavscConstants.FrontOfficeGroupName)] public IActionResult PostProduct([FromBody] Product product) { if (!ModelState.IsValid) @@ -110,7 +110,7 @@ namespace Yavsc.Controllers } // DELETE: api/ProductApi/5 - [HttpDelete("{id}"),Authorize(Constants.FrontOfficeGroupName)] + [HttpDelete("{id}"),Authorize(YavscConstants.FrontOfficeGroupName)] public IActionResult DeleteProduct(long id) { if (!ModelState.IsValid) diff --git a/src/Api/Controllers/PostRateApiController.cs b/src/Api/Controllers/PostRateApiController.cs index 50d6d2e9..dc132da4 100644 --- a/src/Api/Controllers/PostRateApiController.cs +++ b/src/Api/Controllers/PostRateApiController.cs @@ -37,7 +37,7 @@ namespace Yavsc.Controllers var uid = User.FindFirstValue(ClaimTypes.NameIdentifier); if (blogpost.AuthorId!=uid) - if (!User.IsInRole(Constants.AdminGroupName)) + if (!User.IsInRole(YavscConstants.AdminGroupName)) return BadRequest(); _context.SaveChanges(User.GetUserId()); diff --git a/src/Api/Controllers/Relationship/BlackListApiController.cs b/src/Api/Controllers/Relationship/BlackListApiController.cs index a8c00d40..ebc1c03b 100644 --- a/src/Api/Controllers/Relationship/BlackListApiController.cs +++ b/src/Api/Controllers/Relationship/BlackListApiController.cs @@ -50,8 +50,8 @@ namespace Yavsc.Controllers { var uid = User.FindFirstValue(ClaimTypes.NameIdentifier); if (uid != blackListed.OwnerId) - if (!User.IsInRole(Constants.AdminGroupName)) - if (!User.IsInRole(Constants.FrontOfficeGroupName)) + if (!User.IsInRole(YavscConstants.AdminGroupName)) + if (!User.IsInRole(YavscConstants.FrontOfficeGroupName)) return false; return true; } diff --git a/src/Api/Controllers/Relationship/ChatRoomAccessApiController.cs b/src/Api/Controllers/Relationship/ChatRoomAccessApiController.cs index 376b1f14..5fe3a0bf 100644 --- a/src/Api/Controllers/Relationship/ChatRoomAccessApiController.cs +++ b/src/Api/Controllers/Relationship/ChatRoomAccessApiController.cs @@ -46,7 +46,7 @@ namespace Yavsc.Controllers var uid = User.FindFirstValue(ClaimTypes.NameIdentifier); if (uid != chatRoomAccess.UserId && uid != chatRoomAccess.Room.OwnerId - && ! User.IsInMsRole(Constants.AdminGroupName)) + && ! User.IsInMsRole(YavscConstants.AdminGroupName)) { ModelState.AddModelError("UserId","get refused"); @@ -72,7 +72,7 @@ namespace Yavsc.Controllers } var room = _context.ChatRoom.First(channel => channel.Name == chatRoomAccess.ChannelName ); - if (uid != room.OwnerId && ! User.IsInMsRole(Constants.AdminGroupName)) + if (uid != room.OwnerId && ! User.IsInMsRole(YavscConstants.AdminGroupName)) { ModelState.AddModelError("ChannelName", "access put refused"); return BadRequest(ModelState); @@ -110,7 +110,7 @@ namespace Yavsc.Controllers var uid = User.FindFirstValue(ClaimTypes.NameIdentifier); var room = _context.ChatRoom.First(channel => channel.Name == chatRoomAccess.ChannelName ); - if (room == null || (uid != room.OwnerId && ! User.IsInMsRole(Constants.AdminGroupName))) + if (room == null || (uid != room.OwnerId && ! User.IsInMsRole(YavscConstants.AdminGroupName))) { ModelState.AddModelError("ChannelName", "access post refused"); return BadRequest(ModelState); @@ -154,7 +154,7 @@ namespace Yavsc.Controllers var uid = User.FindFirstValue(ClaimTypes.NameIdentifier); var room = _context.ChatRoom.First(channel => channel.Name == chatRoomAccess.ChannelName ); - if (room == null || (uid != room.OwnerId && chatRoomAccess.UserId != uid && ! User.IsInMsRole(Constants.AdminGroupName))) + if (room == null || (uid != room.OwnerId && chatRoomAccess.UserId != uid && ! User.IsInMsRole(YavscConstants.AdminGroupName))) { ModelState.AddModelError("UserId", "access drop refused"); return BadRequest(ModelState); diff --git a/src/Api/Controllers/Relationship/ChatRoomApiController.cs b/src/Api/Controllers/Relationship/ChatRoomApiController.cs index d698002d..990646fc 100644 --- a/src/Api/Controllers/Relationship/ChatRoomApiController.cs +++ b/src/Api/Controllers/Relationship/ChatRoomApiController.cs @@ -137,7 +137,7 @@ namespace Yavsc.Controllers if (User.GetUserId() != chatRoom.OwnerId ) { - if (!User.IsInMsRole(Constants.AdminGroupName)) + if (!User.IsInMsRole(YavscConstants.AdminGroupName)) return BadRequest(new {error = "OwnerId"}); } diff --git a/src/Api/Controllers/ServiceApiController.cs b/src/Api/Controllers/ServiceApiController.cs index 63528335..e9330543 100644 --- a/src/Api/Controllers/ServiceApiController.cs +++ b/src/Api/Controllers/ServiceApiController.cs @@ -46,7 +46,7 @@ namespace Yavsc.Controllers } // PUT: api/ServiceApi/5 - [HttpPut("{id}"),Authorize(Constants.FrontOfficeGroupName)] + [HttpPut("{id}"),Authorize(YavscConstants.FrontOfficeGroupName)] public IActionResult PutService(long id, [FromBody] Service service) { if (!ModelState.IsValid) @@ -81,7 +81,7 @@ namespace Yavsc.Controllers } // POST: api/ServiceApi - [HttpPost,Authorize(Constants.FrontOfficeGroupName)] + [HttpPost,Authorize(YavscConstants.FrontOfficeGroupName)] public IActionResult PostService([FromBody] Service service) { if (!ModelState.IsValid) @@ -110,7 +110,7 @@ namespace Yavsc.Controllers } // DELETE: api/ServiceApi/5 - [HttpDelete("{id}"),Authorize(Constants.FrontOfficeGroupName)] + [HttpDelete("{id}"),Authorize(YavscConstants.FrontOfficeGroupName)] public IActionResult DeleteService(long id) { if (!ModelState.IsValid) diff --git a/src/Api/Program.cs b/src/Api/Program.cs index c88951b6..ea884e2f 100644 --- a/src/Api/Program.cs +++ b/src/Api/Program.cs @@ -62,7 +62,7 @@ internal class Program options.IncludeErrorDetails = true; options.Authority = "https://localhost:5001"; options.TokenValidationParameters = - new() { ValidateAudience = false, RoleClaimType = Constants.RoleClaimType }; + new() { ValidateAudience = false, RoleClaimType = YavscConstants.RoleClaimType }; options.MapInboundClaims = true; }); diff --git a/src/Yavsc.Abstract/Authentication/RegisterModel.cs b/src/Yavsc.Abstract/Authentication/RegisterModel.cs index e4285f06..f55aa71e 100644 --- a/src/Yavsc.Abstract/Authentication/RegisterModel.cs +++ b/src/Yavsc.Abstract/Authentication/RegisterModel.cs @@ -8,8 +8,8 @@ namespace Yavsc.ViewModels.Account public class RegisterModel { - [StringLength(Constants.MaxUserNameLength)] - [RegularExpression(Constants.UserNameRegExp)] + [StringLength(YavscConstants.MaxUserNameLength)] + [RegularExpression(YavscConstants.UserNameRegExp)] [DataType(DataType.Text)] [Display(Name = "UserName", Description = "User name")] public string UserName { get; set; } diff --git a/src/Yavsc.Abstract/Constants.cs b/src/Yavsc.Abstract/Constants.cs index e1a8e717..d303b629 100644 --- a/src/Yavsc.Abstract/Constants.cs +++ b/src/Yavsc.Abstract/Constants.cs @@ -3,7 +3,7 @@ using Yavsc.Models.Auth; namespace Yavsc { - public static class Constants + public static class YavscConstants { public static readonly Scope[] SiteScopes = { new Scope { Id = "profile", Description = "Your profile informations" }, diff --git a/src/Yavsc.Blogs/Program.cs b/src/Yavsc.Blogs/Program.cs index 96918dc5..e7dca81f 100644 --- a/src/Yavsc.Blogs/Program.cs +++ b/src/Yavsc.Blogs/Program.cs @@ -67,12 +67,12 @@ internal class Program options.IncludeErrorDetails = true; options.Authority = authority; options.TokenValidationParameters = - new() { ValidateAudience = false, RoleClaimType = Constants.RoleClaimType }; + new() { ValidateAudience = false, RoleClaimType = YavscConstants.RoleClaimType }; options.MapInboundClaims = true; }); services.AddDbContext(options => - options.UseNpgsql(builder.Configuration.GetConnectionString(Constants.YavscConnectionStringName))); + options.UseNpgsql(builder.Configuration.GetConnectionString(YavscConstants.YavscConnectionStringName))); services.AddTransient() .AddTransient() diff --git a/src/Yavsc.Org/Controllers/Accounting/AccountController.cs b/src/Yavsc.Org/Controllers/Accounting/AccountController.cs index 86073433..30168c54 100644 --- a/src/Yavsc.Org/Controllers/Accounting/AccountController.cs +++ b/src/Yavsc.Org/Controllers/Accounting/AccountController.cs @@ -198,7 +198,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory, /// /// Entry point into the login workflow /// - [HttpGet(Constants.SigninPath)] + [HttpGet(YavscConstants.SigninPath)] public async Task Signin(SignInModel model) { // build a model so we know what to show on the login page @@ -217,7 +217,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory, /// Handle postback from username/password login /// /// - [HttpPost(Constants.SigninPath)] + [HttpPost(YavscConstants.SigninPath)] [ValidateAntiForgeryToken] [AllowAnonymous] @@ -659,7 +659,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory, } // // POST: /Account/LogOff - [HttpPost(Constants.LogoutPath)] + [HttpPost(YavscConstants.LogoutPath)] [ValidateAntiForgeryToken] public async Task LogOff(string returnUrl = null) { @@ -829,7 +829,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory, bool result = false; try { - result = await _userManager.VerifyTwoFactorTokenAsync(user, Constants.DefaultFactor, code); + result = await _userManager.VerifyTwoFactorTokenAsync(user, YavscConstants.DefaultFactor, code); _dbContext.SaveChanges(userId); } catch (Exception ex) @@ -1024,12 +1024,12 @@ IHtmlLocalizerFactory htmlLocalizerFactory, } // Generate the token and send it - if (model.SelectedProvider == Constants.MobileAppFactor) + if (model.SelectedProvider == YavscConstants.MobileAppFactor) { return View("Error", new Exception("No mobile app service was activated")); } else - if (model.SelectedProvider == Constants.SMSFactor) + if (model.SelectedProvider == YavscConstants.SMSFactor) { return View("Error", new Exception("No SMS service was activated")); // await _smsSender.SendSmsAsync(_twilioSettings, await _userManager.GetPhoneNumberAsync(user), message); diff --git a/src/Yavsc.Org/Controllers/Administration/AdministrationController.cs b/src/Yavsc.Org/Controllers/Administration/AdministrationController.cs index e2944e9e..7104e178 100644 --- a/src/Yavsc.Org/Controllers/Administration/AdministrationController.cs +++ b/src/Yavsc.Org/Controllers/Administration/AdministrationController.cs @@ -50,12 +50,12 @@ namespace Yavsc.Controllers { // ensure all roles existence foreach (string roleName in new string[] { - Constants.AdminGroupName, - Constants.StarGroupName, - Constants.PerformerGroupName, - Constants.FrontOfficeGroupName, - Constants.StarHunterGroupName, - Constants.BlogModeratorGroupName + YavscConstants.AdminGroupName, + YavscConstants.StarGroupName, + YavscConstants.PerformerGroupName, + YavscConstants.FrontOfficeGroupName, + YavscConstants.StarHunterGroupName, + YavscConstants.BlogModeratorGroupName }) if (!await _roleManager.RoleExistsAsync(roleName)) { @@ -80,11 +80,11 @@ namespace Yavsc.Controllers public async Task Take() { // If some amdin already exists, make this method disapear - var admins = await _userManager.GetUsersInRoleAsync(Constants.AdminGroupName); + var admins = await _userManager.GetUsersInRoleAsync(YavscConstants.AdminGroupName); if (admins != null && admins.Count > 0) { // All is ok, nothing to do here. - if (User.IsInMsRole(Constants.AdminGroupName)) + if (User.IsInMsRole(YavscConstants.AdminGroupName)) { return Ok(new { message = "you already got it." }); @@ -100,7 +100,7 @@ namespace Yavsc.Controllers return new BadRequestObjectResult(ModelState); } - var addToRoleResult = await _userManager.AddToRoleAsync(user, Constants.AdminGroupName); + var addToRoleResult = await _userManager.AddToRoleAsync(user, YavscConstants.AdminGroupName); if (!addToRoleResult.Succeeded) { AddErrors(addToRoleResult); @@ -114,11 +114,11 @@ namespace Yavsc.Controllers public async Task Index() { var adminCount = await _userManager.GetUsersInRoleAsync( - Constants.AdminGroupName); + YavscConstants.AdminGroupName); var userCount = await _dbContext.Users.CountAsync(); var youAreAdmin = await _userManager.IsInRoleAsync( await _userManager.FindByIdAsync(User.GetUserId()), - Constants.AdminGroupName); + YavscConstants.AdminGroupName); var roles = await _roleManager.Roles.Select(x => new RoleInfo { diff --git a/src/Yavsc.Org/Controllers/Communicating/AnnouncesController.cs b/src/Yavsc.Org/Controllers/Communicating/AnnouncesController.cs index a6dcb061..e5002168 100644 --- a/src/Yavsc.Org/Controllers/Communicating/AnnouncesController.cs +++ b/src/Yavsc.Org/Controllers/Communicating/AnnouncesController.cs @@ -59,8 +59,8 @@ namespace Yavsc.Controllers } private async Task SetupView(Announce announce) { - ViewBag.IsAdmin = User.IsInMsRole(Constants.AdminGroupName); - ViewBag.IsPerformer = User.IsInMsRole(Constants.PerformerGroupName); + ViewBag.IsAdmin = User.IsInMsRole(YavscConstants.AdminGroupName); + ViewBag.IsPerformer = User.IsInMsRole(YavscConstants.PerformerGroupName); ViewBag.AllowEdit = announce==null || announce.Id<=0 || !_authorizationService.AuthorizeAsync(User,announce,new EditPermission()).IsFaulted; List dl = new List(); var rnames = System.Enum.GetNames(typeof(Reason)); @@ -82,14 +82,14 @@ namespace Yavsc.Controllers if (ModelState.IsValid) { // Only allow admin to create corporate annonces - if (announce.For == Reason.Corporate && ! User.IsInMsRole(Constants.AdminGroupName)) + if (announce.For == Reason.Corporate && ! User.IsInMsRole(YavscConstants.AdminGroupName)) { ModelState.AddModelError("For", _localizer["YourNotAdmin"]); return View(announce); } // Only allow performers to create ServiceProposal - if (announce.For == Reason.ServiceProposal && ! User.IsInMsRole(Constants.PerformerGroupName)) + if (announce.For == Reason.ServiceProposal && ! User.IsInMsRole(YavscConstants.PerformerGroupName)) { ModelState.AddModelError("For", _localizer["YourNotAPerformer"]); return View(announce); diff --git a/src/Yavsc.Org/Controllers/Communicating/BlogspotController.cs b/src/Yavsc.Org/Controllers/Communicating/BlogspotController.cs index ec1e2dd4..4d4e3977 100644 --- a/src/Yavsc.Org/Controllers/Communicating/BlogspotController.cs +++ b/src/Yavsc.Org/Controllers/Communicating/BlogspotController.cs @@ -71,7 +71,7 @@ namespace Yavsc.Controllers { var blog = await blogSpotService.Details(User, id.Value); ViewData["apicmtctlr"] = "/api/blogcomments"; - ViewData["moderatoFlag"] = User.IsInMsRole(Constants.BlogModeratorGroupName); + ViewData["moderatoFlag"] = User.IsInMsRole(YavscConstants.BlogModeratorGroupName); return View(blog); diff --git a/src/Yavsc.Org/Controllers/Contracting/ActivityController.cs b/src/Yavsc.Org/Controllers/Contracting/ActivityController.cs index ac205d7c..0a7a143d 100644 --- a/src/Yavsc.Org/Controllers/Contracting/ActivityController.cs +++ b/src/Yavsc.Org/Controllers/Contracting/ActivityController.cs @@ -43,7 +43,7 @@ namespace Yavsc.Controllers Value = pt.FullName, Selected = currentCode == pt.FullName }).ToList(); - items.Add(new SelectListItem { Text = SR[Constants.NoneCode], Value = Constants.NoneCode, Selected = currentCode == null}); + items.Add(new SelectListItem { Text = SR[YavscConstants.NoneCode], Value = YavscConstants.NoneCode, Selected = currentCode == null}); ViewBag.SettingsClassName = items; } @@ -59,7 +59,7 @@ namespace Yavsc.Controllers Text = a.Name, Value = a.Code }).ToList(); - var nullItem = new SelectListItem { Text = SR[Constants.NoneCode], Value = Constants.NoneCode }; + var nullItem = new SelectListItem { Text = SR[YavscConstants.NoneCode], Value = YavscConstants.NoneCode }; acts.Add(nullItem); if (code == null) return acts; var existing = _context.Activities.Include(a => a.Children).FirstOrDefault(a => a.Code == code); @@ -124,9 +124,9 @@ namespace Yavsc.Controllers [ValidateAntiForgeryToken] public IActionResult Create(Activity activity) { - if (activity.ParentCode==Constants.NoneCode) + if (activity.ParentCode==YavscConstants.NoneCode) activity.ParentCode=null; - if (activity.SettingsClassName==Constants.NoneCode) + if (activity.SettingsClassName==YavscConstants.NoneCode) activity.SettingsClassName=null; if (ModelState.IsValid) @@ -162,9 +162,9 @@ namespace Yavsc.Controllers [ValidateAntiForgeryToken] public IActionResult Edit(Activity activity) { - if (activity.ParentCode==Constants.NoneCode) + if (activity.ParentCode==YavscConstants.NoneCode) activity.ParentCode=null; - if (activity.SettingsClassName==Constants.NoneCode) + if (activity.SettingsClassName==YavscConstants.NoneCode) activity.SettingsClassName=null; if (ModelState.IsValid) { diff --git a/src/Yavsc.Org/Controllers/HomeController.cs b/src/Yavsc.Org/Controllers/HomeController.cs index 5e2c2307..2602a1a3 100644 --- a/src/Yavsc.Org/Controllers/HomeController.cs +++ b/src/Yavsc.Org/Controllers/HomeController.cs @@ -31,9 +31,9 @@ namespace Yavsc.Controllers public async Task Index(string id) { - ViewBag.IsFromSecureProx = Request.Headers.ContainsKey(Constants.SshHeaderKey) && Request.Headers[Constants.SshHeaderKey] == "on"; + ViewBag.IsFromSecureProx = Request.Headers.ContainsKey(YavscConstants.SshHeaderKey) && Request.Headers[YavscConstants.SshHeaderKey] == "on"; ViewBag.SecureHomeUrl = "https://" + Request.Headers["X-Forwarded-Host"]; - ViewBag.SshHeaderKey = Request.Headers[Constants.SshHeaderKey]; + ViewBag.SshHeaderKey = Request.Headers[YavscConstants.SshHeaderKey]; var uid = User.GetUserId(); long[] clicked = null; if (uid == null) diff --git a/src/Yavsc.Org/Controllers/Musical/InstrumentationController.cs b/src/Yavsc.Org/Controllers/Musical/InstrumentationController.cs index 4ebcb269..dc905d08 100644 --- a/src/Yavsc.Org/Controllers/Musical/InstrumentationController.cs +++ b/src/Yavsc.Org/Controllers/Musical/InstrumentationController.cs @@ -64,7 +64,7 @@ namespace Yavsc.Controllers var uid = User.FindFirstValue(ClaimTypes.NameIdentifier); if (ModelState.IsValid) { - if (model.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName)) + if (model.UserId != uid) if (!User.IsInMsRole(YavscConstants.AdminGroupName)) return new ChallengeResult(); _context.Instrumentation.Add(model); @@ -82,7 +82,7 @@ namespace Yavsc.Controllers { return NotFound(); } - if (id != uid) if (!User.IsInMsRole(Constants.AdminGroupName)) + if (id != uid) if (!User.IsInMsRole(YavscConstants.AdminGroupName)) return new ChallengeResult(); Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id); if (musicianSettings == null) @@ -98,7 +98,7 @@ namespace Yavsc.Controllers public async Task Edit(Instrumentation musicianSettings) { var uid = User.FindFirstValue(ClaimTypes.NameIdentifier); - if (musicianSettings.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName)) + if (musicianSettings.UserId != uid) if (!User.IsInMsRole(YavscConstants.AdminGroupName)) return new ChallengeResult(); if (ModelState.IsValid) { @@ -124,7 +124,7 @@ namespace Yavsc.Controllers return NotFound(); } var uid = User.FindFirstValue(ClaimTypes.NameIdentifier); - if (musicianSettings.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName)) + if (musicianSettings.UserId != uid) if (!User.IsInMsRole(YavscConstants.AdminGroupName)) return new ChallengeResult(); return View(musicianSettings); } @@ -137,7 +137,7 @@ namespace Yavsc.Controllers Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id); var uid = User.FindFirstValue(ClaimTypes.NameIdentifier); - if (musicianSettings.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName)) + if (musicianSettings.UserId != uid) if (!User.IsInMsRole(YavscConstants.AdminGroupName)) return new ChallengeResult(); diff --git a/src/Yavsc.Org/Extensions/HostingExtensions.cs b/src/Yavsc.Org/Extensions/HostingExtensions.cs index fe218612..44392fd2 100644 --- a/src/Yavsc.Org/Extensions/HostingExtensions.cs +++ b/src/Yavsc.Org/Extensions/HostingExtensions.cs @@ -126,7 +126,7 @@ public static class HostingExtensions new() { ValidateAudience = false, - RoleClaimType = Constants.RoleClaimType + RoleClaimType = YavscConstants.RoleClaimType }; options.MapInboundClaims = true; }); @@ -141,7 +141,7 @@ public static class HostingExtensions public static IdentityBuilder AddIdentityDBAndStores(this WebApplicationBuilder builder) { IServiceCollection services = builder.Services; - var connectionString = builder.Configuration.GetConnectionString(Constants.YavscConnectionStringName); + var connectionString = builder.Configuration.GetConnectionString(YavscConstants.YavscConnectionStringName); services.AddDbContext(options => { @@ -162,7 +162,7 @@ public static class HostingExtensions options.SignIn.RequireConfirmedAccount = builder.Environment.IsEnvironment( builder.Environment.EnvironmentName); options.ClaimsIdentity.UserNameClaimType = JwtClaimTypes.PreferredUserName; - options.ClaimsIdentity.RoleClaimType = Constants.RoleClaimType; + options.ClaimsIdentity.RoleClaimType = YavscConstants.RoleClaimType; } ) .AddEntityFrameworkStores(); @@ -186,18 +186,18 @@ public static class HostingExtensions { policy .RequireAuthenticatedUser() - .RequireClaim(Constants.RoleClaimType, - new string[] { Constants.PerformerGroupName, Constants.AdminGroupName }) + .RequireClaim(YavscConstants.RoleClaimType, + new string[] { YavscConstants.PerformerGroupName, YavscConstants.AdminGroupName }) ; }); options.AddPolicy("AdministratorOnly", policy => { _ = policy .RequireAuthenticatedUser() - .RequireClaim(Constants.RoleClaimType, Constants.AdminGroupName); + .RequireClaim(YavscConstants.RoleClaimType, YavscConstants.AdminGroupName); }); - options.AddPolicy("FrontOffice", policy => policy.RequireRole(Constants.FrontOfficeGroupName)); + options.AddPolicy("FrontOffice", policy => policy.RequireRole(YavscConstants.FrontOfficeGroupName)); // options.AddPolicy("EmployeeId", policy => policy.RequireClaim("EmployeeId", "123", "456")); // options.AddPolicy("BuildingEntry", policy => policy.Requirements.Add(new OfficeEntryRequirement())); @@ -269,10 +269,10 @@ public static class HostingExtensions { options.ClaimsIdentity.UserIdClaimType = JwtClaimTypes.Subject; options.ClaimsIdentity.UserNameClaimType = JwtClaimTypes.Name; - options.ClaimsIdentity.RoleClaimType = Constants.RoleClaimType; + options.ClaimsIdentity.RoleClaimType = YavscConstants.RoleClaimType; }); var migrationsAssembly = typeof(Program).GetTypeInfo().Assembly.GetName().Name; - var connectionString = builder.Configuration.GetConnectionString(Constants.YavscConnectionStringName); + var connectionString = builder.Configuration.GetConnectionString(YavscConstants.YavscConnectionStringName); string sqliteConnectionString = $"Data Source={Path.Combine(Path.GetTempPath(), "yavsc_test.db")}"; @@ -503,7 +503,7 @@ public static class HostingExtensions Config.UserFilesOptions = new FileServerOptions() { FileProvider = new PhysicalFileProvider(AbstractFileSystemHelpers.UserFilesDirName), - RequestPath = PathString.FromUriComponent(Constants.UserFilesPath), + RequestPath = PathString.FromUriComponent(YavscConstants.UserFilesPath), EnableDirectoryBrowsing = enableDirectoryBrowsing, }; Config.UserFilesOptions.EnableDefaultFiles = true; @@ -516,7 +516,7 @@ public static class HostingExtensions Config.AvatarsOptions = new FileServerOptions() { FileProvider = new PhysicalFileProvider(Config.AvatarsDirName), - RequestPath = PathString.FromUriComponent(Constants.AvatarsPath), + RequestPath = PathString.FromUriComponent(YavscConstants.AvatarsPath), EnableDirectoryBrowsing = enableDirectoryBrowsing }; @@ -527,7 +527,7 @@ public static class HostingExtensions Config.GitOptions = new FileServerOptions() { FileProvider = new PhysicalFileProvider(Config.GitDirName), - RequestPath = PathString.FromUriComponent(Constants.GitPath), + RequestPath = PathString.FromUriComponent(YavscConstants.GitPath), EnableDirectoryBrowsing = enableDirectoryBrowsing, }; Config.GitOptions.DefaultFilesOptions.DefaultFileNames.Add("index.md"); diff --git a/src/Yavsc.Org/Program.cs b/src/Yavsc.Org/Program.cs index 2803dbad..cb81ecdb 100644 --- a/src/Yavsc.Org/Program.cs +++ b/src/Yavsc.Org/Program.cs @@ -28,12 +28,14 @@ namespace Yavsc else builder.Services.AddScoped(); - builder.Configuration + var rootConfig = builder.Configuration .AddJsonFile("appsettings.json") .AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true) .AddEnvironmentVariables() .Build(); + rootConfig.GetConnectionString(YavscConstants.YavscConnectionStringName); + var app = await builder.ConfigureWebAppServices().ConfigurePipeline(); app.Run(); } diff --git a/src/Yavsc.Org/ViewModels/Manage/SetUserNameViewModel.cs b/src/Yavsc.Org/ViewModels/Manage/SetUserNameViewModel.cs index 61cf0727..69507b92 100644 --- a/src/Yavsc.Org/ViewModels/Manage/SetUserNameViewModel.cs +++ b/src/Yavsc.Org/ViewModels/Manage/SetUserNameViewModel.cs @@ -7,7 +7,7 @@ namespace Yavsc.ViewModels.Manage public class SetUserNameViewModel { [Required] - [Display(Name = "User name"),RegularExpression(Constants.UserNameRegExp)] + [Display(Name = "User name"),RegularExpression(YavscConstants.UserNameRegExp)] public string UserName { get; set; } } diff --git a/src/Yavsc.Org/Views/Shared/_LoginPartial.cshtml b/src/Yavsc.Org/Views/Shared/_LoginPartial.cshtml index 193ce34f..c3267c5d 100644 --- a/src/Yavsc.Org/Views/Shared/_LoginPartial.cshtml +++ b/src/Yavsc.Org/Views/Shared/_LoginPartial.cshtml @@ -14,7 +14,7 @@
  • Features
  • - @if (User.IsInMsRole(Constants.AdminGroupName)) { + @if (User.IsInMsRole(YavscConstants.AdminGroupName)) {