diff --git a/src/Api/Controllers/Blogspot/BlogApiController.cs b/src/Api/Controllers/Blogspot/BlogApiController.cs index 481e9994..b08ff9cc 100644 --- a/src/Api/Controllers/Blogspot/BlogApiController.cs +++ b/src/Api/Controllers/Blogspot/BlogApiController.cs @@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Blog; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Api/Controllers/Blogspot/CommentsApiController.cs b/src/Api/Controllers/Blogspot/CommentsApiController.cs index 41cdd95c..567d6a14 100644 --- a/src/Api/Controllers/Blogspot/CommentsApiController.cs +++ b/src/Api/Controllers/Blogspot/CommentsApiController.cs @@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Blog; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Api/Controllers/Blogspot/PostTagsApiController.cs b/src/Api/Controllers/Blogspot/PostTagsApiController.cs index 58bd53e5..bd2a9e2a 100644 --- a/src/Api/Controllers/Blogspot/PostTagsApiController.cs +++ b/src/Api/Controllers/Blogspot/PostTagsApiController.cs @@ -10,6 +10,7 @@ namespace Yavsc.Controllers using Models; using Yavsc.Helpers; using Yavsc.Models.Blog; + using Yavsc.Server.Helpers; [Produces("application/json")] [Route("~/api/PostTagsApi")] diff --git a/src/Api/Controllers/Blogspot/TagsApiController.cs b/src/Api/Controllers/Blogspot/TagsApiController.cs index 5a86e24c..de305733 100644 --- a/src/Api/Controllers/Blogspot/TagsApiController.cs +++ b/src/Api/Controllers/Blogspot/TagsApiController.cs @@ -8,6 +8,7 @@ namespace Yavsc.Controllers using Microsoft.EntityFrameworkCore; using Models.Relationship; using Yavsc.Helpers; + using Yavsc.Server.Helpers; [Produces("application/json")] [Route("api/TagsApi")] diff --git a/src/Api/Controllers/Business/ActivityApiController.cs b/src/Api/Controllers/Business/ActivityApiController.cs index 709fab7a..f6b215e7 100644 --- a/src/Api/Controllers/Business/ActivityApiController.cs +++ b/src/Api/Controllers/Business/ActivityApiController.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Yavsc.Api.Helpers; +using Yavsc.Server.Helpers; using Yavsc.Models; using Yavsc.Models.Workflow; diff --git a/src/Api/Controllers/Business/BookQueryApiController.cs b/src/Api/Controllers/Business/BookQueryApiController.cs index f8e9282f..6603d65b 100644 --- a/src/Api/Controllers/Business/BookQueryApiController.cs +++ b/src/Api/Controllers/Business/BookQueryApiController.cs @@ -15,6 +15,7 @@ namespace Yavsc.Controllers using Yavsc.Abstract.Identity; using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; + using Yavsc.Server.Helpers; [Produces("application/json")] [Route("api/bookquery"), Authorize(Roles = "Performer,Administrator")] diff --git a/src/Api/Controllers/Business/EstimateApiController.cs b/src/Api/Controllers/Business/EstimateApiController.cs index 79b103e4..f7cb1e6c 100644 --- a/src/Api/Controllers/Business/EstimateApiController.cs +++ b/src/Api/Controllers/Business/EstimateApiController.cs @@ -10,6 +10,7 @@ using Newtonsoft.Json; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Billing; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Api/Controllers/Business/EstimateTemplatesApiController.cs b/src/Api/Controllers/Business/EstimateTemplatesApiController.cs index a960b9d1..073cb7ce 100644 --- a/src/Api/Controllers/Business/EstimateTemplatesApiController.cs +++ b/src/Api/Controllers/Business/EstimateTemplatesApiController.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Billing; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Api/Controllers/Business/ProductApiController.cs b/src/Api/Controllers/Business/ProductApiController.cs index 10382138..211104c9 100644 --- a/src/Api/Controllers/Business/ProductApiController.cs +++ b/src/Api/Controllers/Business/ProductApiController.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Market; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Api/Controllers/DimissClicksApiController.cs b/src/Api/Controllers/DimissClicksApiController.cs index d3b31afc..bc1c10b6 100644 --- a/src/Api/Controllers/DimissClicksApiController.cs +++ b/src/Api/Controllers/DimissClicksApiController.cs @@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Messaging; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Api/Controllers/HairCut/BursherProfilesApiController.cs b/src/Api/Controllers/HairCut/BursherProfilesApiController.cs index a29ae74a..22fdf1e9 100644 --- a/src/Api/Controllers/HairCut/BursherProfilesApiController.cs +++ b/src/Api/Controllers/HairCut/BursherProfilesApiController.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Haircut; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Api/Controllers/HairCut/HairCutController.cs b/src/Api/Controllers/HairCut/HairCutController.cs index 569efcdb..12a93758 100644 --- a/src/Api/Controllers/HairCut/HairCutController.cs +++ b/src/Api/Controllers/HairCut/HairCutController.cs @@ -22,6 +22,7 @@ namespace Yavsc.ApiControllers using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Authorization; + using Yavsc.Server.Helpers; [Route("api/haircut")][Authorize] public class HairCutController : Controller diff --git a/src/Api/Controllers/Musical/MusicalPreferencesApiController.cs b/src/Api/Controllers/Musical/MusicalPreferencesApiController.cs index a2d8c5bf..944b335b 100644 --- a/src/Api/Controllers/Musical/MusicalPreferencesApiController.cs +++ b/src/Api/Controllers/Musical/MusicalPreferencesApiController.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Musical; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Api/Controllers/Musical/MusicalTendenciesApiController.cs b/src/Api/Controllers/Musical/MusicalTendenciesApiController.cs index d9aedd14..eacccb0a 100644 --- a/src/Api/Controllers/Musical/MusicalTendenciesApiController.cs +++ b/src/Api/Controllers/Musical/MusicalTendenciesApiController.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Musical; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Api/Controllers/NativeConfidentialController.cs b/src/Api/Controllers/NativeConfidentialController.cs index 8986c5fb..c8784cbc 100644 --- a/src/Api/Controllers/NativeConfidentialController.cs +++ b/src/Api/Controllers/NativeConfidentialController.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Identity; +using Yavsc.Server.Helpers; [Authorize, Route("~/api/gcm")] public class NativeConfidentialController : Controller diff --git a/src/Api/Controllers/PostRateApiController.cs b/src/Api/Controllers/PostRateApiController.cs index a989587d..50d6d2e9 100644 --- a/src/Api/Controllers/PostRateApiController.cs +++ b/src/Api/Controllers/PostRateApiController.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Yavsc.Helpers; using Yavsc.Models; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Api/Controllers/Relationship/BlackListApiController.cs b/src/Api/Controllers/Relationship/BlackListApiController.cs index ced46b21..a8c00d40 100644 --- a/src/Api/Controllers/Relationship/BlackListApiController.cs +++ b/src/Api/Controllers/Relationship/BlackListApiController.cs @@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Access; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Api/Controllers/Relationship/BlogAclApiController.cs b/src/Api/Controllers/Relationship/BlogAclApiController.cs index cf3f4150..6e8b905c 100644 --- a/src/Api/Controllers/Relationship/BlogAclApiController.cs +++ b/src/Api/Controllers/Relationship/BlogAclApiController.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Access; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Api/Controllers/Relationship/ChatRoomApiController.cs b/src/Api/Controllers/Relationship/ChatRoomApiController.cs index 9eee40ff..a9e0e405 100644 --- a/src/Api/Controllers/Relationship/ChatRoomApiController.cs +++ b/src/Api/Controllers/Relationship/ChatRoomApiController.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Chat; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Api/Controllers/Relationship/CircleApiController.cs b/src/Api/Controllers/Relationship/CircleApiController.cs index 7c3a85a0..7a8b4deb 100644 --- a/src/Api/Controllers/Relationship/CircleApiController.cs +++ b/src/Api/Controllers/Relationship/CircleApiController.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Relationship; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Api/Controllers/Relationship/ContactsApiController.cs b/src/Api/Controllers/Relationship/ContactsApiController.cs index 2da02e46..ffd6eb0b 100644 --- a/src/Api/Controllers/Relationship/ContactsApiController.cs +++ b/src/Api/Controllers/Relationship/ContactsApiController.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Abstract.Identity; using Yavsc.Helpers; using Yavsc.Models; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Api/Controllers/ServiceApiController.cs b/src/Api/Controllers/ServiceApiController.cs index cb612b34..63528335 100644 --- a/src/Api/Controllers/ServiceApiController.cs +++ b/src/Api/Controllers/ServiceApiController.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Market; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Api/Controllers/accounting/ApplicationUserApiController.cs b/src/Api/Controllers/accounting/ApplicationUserApiController.cs index ac9de3b1..b7c47221 100644 --- a/src/Api/Controllers/accounting/ApplicationUserApiController.cs +++ b/src/Api/Controllers/accounting/ApplicationUserApiController.cs @@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Abstract.Identity; using Yavsc.Helpers; using Yavsc.Models; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Api/Controllers/accounting/ProfileApiController.cs b/src/Api/Controllers/accounting/ProfileApiController.cs index 16e1425f..4f9d316d 100644 --- a/src/Api/Controllers/accounting/ProfileApiController.cs +++ b/src/Api/Controllers/accounting/ProfileApiController.cs @@ -6,6 +6,7 @@ using System.Linq; using Yavsc.Models; using Yavsc.Abstract.Identity; using Yavsc.Helpers; +using Yavsc.Server.Helpers; namespace Yavsc.ApiControllers.accounting { diff --git a/src/Api/Helpers/UserHelpers.cs b/src/Api/Helpers/UserHelpers.cs deleted file mode 100644 index ee895600..00000000 --- a/src/Api/Helpers/UserHelpers.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Security.Claims; -using System.Collections.Generic; -using System.Linq; -using Microsoft.EntityFrameworkCore; -using Yavsc.Models; -using Yavsc.Models.Blog; - -namespace Yavsc.Api.Helpers -{ - public static class UserHelpers - { - public static string? GetUserId(this ClaimsPrincipal user) - { - return user.FindFirstValue("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"); - } - } -} diff --git a/src/Yavsc.Server/Helpers/UserHelpers.cs b/src/Yavsc.Server/Helpers/UserHelpers.cs index d5b57a29..3a1a100e 100644 --- a/src/Yavsc.Server/Helpers/UserHelpers.cs +++ b/src/Yavsc.Server/Helpers/UserHelpers.cs @@ -1,11 +1,6 @@ using System.Security.Claims; -using System.Collections.Generic; -using System.Linq; -using Microsoft.EntityFrameworkCore; -using Yavsc.Models; -using Yavsc.Models.Blog; -namespace Yavsc.Helpers +namespace Yavsc.Server.Helpers { public static class UserHelpers { @@ -24,30 +19,5 @@ namespace Yavsc.Helpers return user.Identity.IsAuthenticated; } - public static IEnumerable UserPosts(this ApplicationDbContext dbContext, string posterId, string? readerId) - { - if (readerId == null) - { - var userPosts = dbContext.blogSpotPublications.Include( - b => b.BlogPost - ).Where(x => x.BlogPost.AuthorId == posterId) - .Select(x=>x.BlogPost).ToArray(); - return userPosts; - } - else - { - long[] readerCirclesMemberships = - dbContext.Circle.Include(c => c.Members) - .Where(c => c.Members.Any(m => m.MemberId == readerId)) - .Select(c => c.Id).ToArray(); - return dbContext.BlogSpot.Include( - b => b.Author - ).Include(p => p.ACL).Where(x => x.Author.Id == posterId && - (x.ACL.Count == 0 || x.ACL.Any(a => readerCirclesMemberships.Contains(a.CircleId)))); - - - } - - } } } diff --git a/src/Yavsc.Server/Hubs/ChatHub.cs b/src/Yavsc.Server/Hubs/ChatHub.cs index 518575d9..313af6a2 100644 --- a/src/Yavsc.Server/Hubs/ChatHub.cs +++ b/src/Yavsc.Server/Hubs/ChatHub.cs @@ -36,6 +36,7 @@ namespace Yavsc using Models.Chat; using Yavsc.Abstract.Chat; using Yavsc.Helpers; + using Yavsc.Server.Helpers; using Yavsc.Services; public partial class ChatHub : Hub, IDisposable { diff --git a/src/Yavsc.Server/Makefile b/src/Yavsc.Server/Makefile index 0e010a72..991ad411 100644 --- a/src/Yavsc.Server/Makefile +++ b/src/Yavsc.Server/Makefile @@ -1,26 +1,2 @@ -SOURCE_DIR=../.. -MAKEFILE_DIR=$(SOURCE_DIR)/scripts/make -BASERESX=Resources/Yavsc.Models.Relationship.HyperLink.resx \ - Resources/Yavsc.Models.Streaming.LiveFlow.resx -BASERESXGEN=$(BASERESX:.resx=.Designer.cs) - -include $(MAKEFILE_DIR)/dnx.mk -include $(MAKEFILE_DIR)/versioning.mk - -default: all - -$(BINTARGETPATH): ../OAuth.AspNet.AuthServer/bin/$(CONFIGURATION)/OAuth.AspNet.AuthServer.dll \ - ../Yavsc.Abstract/bin/$(CONFIGURATION)/Yavsc.Abstract.dll prepare_code - -../OAuth.AspNet.AuthServer/bin/$(CONFIGURATION)/OAuth.AspNet.AuthServer.dll: - make -C ../OAuth.AspNet.AuthServer - -../Yavsc.Abstract/bin/$(CONFIGURATION)/Yavsc.Abstract.dll: - make -C ../Yavsc.Abstract - -%.Designer.cs: %.resx - strongresbuildercli -l -p -t -r "Yavsc.Server.Resources." $^ - -prepare_code: $(BASERESXGEN) - -all: $(BINTARGETPATH) +listConnections: + dotnet ef migrations list --connection "$(YAVSC_CONNECTION_STRING)" diff --git a/src/Yavsc.Server/Models/ApplicationDbContext.cs b/src/Yavsc.Server/Models/ApplicationDbContext.cs index 8a057638..2b68ed6a 100644 --- a/src/Yavsc.Server/Models/ApplicationDbContext.cs +++ b/src/Yavsc.Server/Models/ApplicationDbContext.cs @@ -36,6 +36,10 @@ namespace Yavsc.Models public class ApplicationDbContext : IdentityDbContext { + public ApplicationDbContext() + { + + } public ApplicationDbContext(DbContextOptions options) : base(options) { } diff --git a/src/Yavsc.Server/Services/FileSystemAuthManager.cs b/src/Yavsc.Server/Services/FileSystemAuthManager.cs index 25ca399f..dd18d964 100644 --- a/src/Yavsc.Server/Services/FileSystemAuthManager.cs +++ b/src/Yavsc.Server/Services/FileSystemAuthManager.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.Options; using rules; using Yavsc.Helpers; using Yavsc.Models; +using Yavsc.Server.Helpers; namespace Yavsc.Services { diff --git a/src/Yavsc.Server/Services/YavscClientStore.cs b/src/Yavsc.Server/Services/YavscClientStore.cs deleted file mode 100644 index 46576662..00000000 --- a/src/Yavsc.Server/Services/YavscClientStore.cs +++ /dev/null @@ -1,66 +0,0 @@ - -using IdentityServer8.Models; -using IdentityServer8.Stores; -using Microsoft.EntityFrameworkCore; -using Yavsc.Models; - -namespace Yavsc.Services; - -public class YavscClientStore : IClientStore -{ - ApplicationDbContext _context=null; - public YavscClientStore(ApplicationDbContext context) - { - _context = context; - } - - - async Task IClientStore.FindClientByIdAsync(string clientId) - { - var app = await _context.Applications.FirstOrDefaultAsync(c=>c.Id == clientId); - - if (app == null) return null; - - Client client = new() - { - ClientId = app.Id, - ClientName = app.DisplayName, - AbsoluteRefreshTokenLifetime = app.RefreshTokenLifeTime, - AccessTokenLifetime = app.AccessTokenLifetime, - AllowedGrantTypes = - [ - GrantType.AuthorizationCode, - GrantType.DeviceFlow, - GrantType.ClientCredentials - ], - ClientSecrets = [ - new Secret(app.Secret), - ] - }; - - - switch(app.Type) - { - case Models.Auth.ApplicationTypes.NativeConfidential: - client.AccessTokenType = AccessTokenType.Reference; - client.AllowedGrantTypes = - [ - GrantType.DeviceFlow - ]; - client.AllowedScopes = [] ; - break; - case Models.Auth.ApplicationTypes.JavaScript: - default: - client.AccessTokenType = AccessTokenType.Jwt; - client.AllowedGrantTypes = - [ - GrantType.AuthorizationCode, - GrantType.ClientCredentials - ]; - client.AllowedScopes = ["openid", "profile"]; - break; - - } - return client; - } -} diff --git a/src/Yavsc/Controllers/Accounting/AccountController.cs b/src/Yavsc/Controllers/Accounting/AccountController.cs index 12f56967..e5f0ec78 100644 --- a/src/Yavsc/Controllers/Accounting/AccountController.cs +++ b/src/Yavsc/Controllers/Accounting/AccountController.cs @@ -27,6 +27,7 @@ using IdentityModel; using System.Security.Cryptography; using System.Text.Unicode; using System.Text; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Yavsc/Controllers/Accounting/ManageController.cs b/src/Yavsc/Controllers/Accounting/ManageController.cs index d0f9dc01..7f9df3fb 100644 --- a/src/Yavsc/Controllers/Accounting/ManageController.cs +++ b/src/Yavsc/Controllers/Accounting/ManageController.cs @@ -16,6 +16,7 @@ using Yavsc.Services; using Yavsc.ViewModels.Manage; using Microsoft.AspNetCore.Identity.UI.Services; using Microsoft.AspNetCore.Authorization; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { @@ -709,7 +710,8 @@ namespace Yavsc.Controllers private async Task GetCurrentUserAsync() { - return await _dbContext.Users.Include(u => u.PostalAddress).FirstOrDefaultAsync(u => u.Id == User.GetUserId()); + return await _dbContext.Users.Include(u => u.PostalAddress) + .FirstOrDefaultAsync(u => u.Id == User.GetUserId()); } #endregion diff --git a/src/Yavsc/Controllers/Administration/AdministrationController.cs b/src/Yavsc/Controllers/Administration/AdministrationController.cs index 41770082..76cde6e4 100644 --- a/src/Yavsc/Controllers/Administration/AdministrationController.cs +++ b/src/Yavsc/Controllers/Administration/AdministrationController.cs @@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Abstract.Identity; using Yavsc.Helpers; using Yavsc.Models; +using Yavsc.Server.Helpers; using Yavsc.ViewModels; using Yavsc.ViewModels.Administration; diff --git a/src/Yavsc/Controllers/Administration/MailingTemplateController.cs b/src/Yavsc/Controllers/Administration/MailingTemplateController.cs index 25b57a14..caaebc11 100644 --- a/src/Yavsc/Controllers/Administration/MailingTemplateController.cs +++ b/src/Yavsc/Controllers/Administration/MailingTemplateController.cs @@ -9,6 +9,7 @@ using Yavsc.Server.Settings; using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Server.Models.Calendar; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Yavsc/Controllers/Communicating/BlogspotController.cs b/src/Yavsc/Controllers/Communicating/BlogspotController.cs index 8ca8220f..b29e2487 100644 --- a/src/Yavsc/Controllers/Communicating/BlogspotController.cs +++ b/src/Yavsc/Controllers/Communicating/BlogspotController.cs @@ -10,6 +10,7 @@ using Microsoft.Extensions.Options; using Microsoft.EntityFrameworkCore; using Yavsc.ViewModels.Blog; using Yavsc.Server.Exceptions; +using Yavsc.Server.Helpers; // For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860 diff --git a/src/Yavsc/Controllers/Communicating/CircleController.cs b/src/Yavsc/Controllers/Communicating/CircleController.cs index c0e44754..8a19ba6b 100644 --- a/src/Yavsc/Controllers/Communicating/CircleController.cs +++ b/src/Yavsc/Controllers/Communicating/CircleController.cs @@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Relationship; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Yavsc/Controllers/Communicating/CircleMembersController.cs b/src/Yavsc/Controllers/Communicating/CircleMembersController.cs index d532456b..8a8786bd 100644 --- a/src/Yavsc/Controllers/Communicating/CircleMembersController.cs +++ b/src/Yavsc/Controllers/Communicating/CircleMembersController.cs @@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Relationship; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Yavsc/Controllers/Communicating/CommentsController.cs b/src/Yavsc/Controllers/Communicating/CommentsController.cs index 6c535fe8..0f9d50bc 100644 --- a/src/Yavsc/Controllers/Communicating/CommentsController.cs +++ b/src/Yavsc/Controllers/Communicating/CommentsController.cs @@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Blog; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Yavsc/Controllers/Communicating/NotificationsController.cs b/src/Yavsc/Controllers/Communicating/NotificationsController.cs index f9f86187..5a3c25de 100644 --- a/src/Yavsc/Controllers/Communicating/NotificationsController.cs +++ b/src/Yavsc/Controllers/Communicating/NotificationsController.cs @@ -4,6 +4,7 @@ using Yavsc.Abstract.Models.Messaging; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Messaging; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Yavsc/Controllers/Contracting/ActivityController.cs b/src/Yavsc/Controllers/Contracting/ActivityController.cs index a593fa8d..a147b5a5 100644 --- a/src/Yavsc/Controllers/Contracting/ActivityController.cs +++ b/src/Yavsc/Controllers/Contracting/ActivityController.cs @@ -9,6 +9,7 @@ namespace Yavsc.Controllers using Models; using Models.Workflow; using Yavsc.Helpers; + using Yavsc.Server.Helpers; [Authorize("AdministratorOnly")] public class ActivityController : Controller diff --git a/src/Yavsc/Controllers/Contracting/ClientController.cs b/src/Yavsc/Controllers/Contracting/ClientController.cs index 10702f11..7cf5e2f8 100644 --- a/src/Yavsc/Controllers/Contracting/ClientController.cs +++ b/src/Yavsc/Controllers/Contracting/ClientController.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Auth; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Yavsc/Controllers/Contracting/CoWorkingController.cs b/src/Yavsc/Controllers/Contracting/CoWorkingController.cs index 3e0eeeb5..97287ca6 100644 --- a/src/Yavsc/Controllers/Contracting/CoWorkingController.cs +++ b/src/Yavsc/Controllers/Contracting/CoWorkingController.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Workflow; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Yavsc/Controllers/Contracting/CommandController.cs b/src/Yavsc/Controllers/Contracting/CommandController.cs index 5332a64e..c9d1979b 100644 --- a/src/Yavsc/Controllers/Contracting/CommandController.cs +++ b/src/Yavsc/Controllers/Contracting/CommandController.cs @@ -16,6 +16,7 @@ namespace Yavsc.Controllers using Models.Workflow; using Services; using Yavsc.Interface; + using Yavsc.Server.Helpers; using Yavsc.Settings; public class CommandController : Controller diff --git a/src/Yavsc/Controllers/Contracting/CommandFormsController.cs b/src/Yavsc/Controllers/Contracting/CommandFormsController.cs index 44d8efc6..4428105e 100644 --- a/src/Yavsc/Controllers/Contracting/CommandFormsController.cs +++ b/src/Yavsc/Controllers/Contracting/CommandFormsController.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Workflow; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Yavsc/Controllers/Contracting/DoController.cs b/src/Yavsc/Controllers/Contracting/DoController.cs index 359cb89a..c69cc411 100644 --- a/src/Yavsc/Controllers/Contracting/DoController.cs +++ b/src/Yavsc/Controllers/Contracting/DoController.cs @@ -13,6 +13,7 @@ namespace Yavsc.Controllers using System.Threading.Tasks; using Yavsc.Helpers; using Microsoft.EntityFrameworkCore; + using Yavsc.Server.Helpers; [Authorize] public class DoController : Controller diff --git a/src/Yavsc/Controllers/Contracting/FormsController.cs b/src/Yavsc/Controllers/Contracting/FormsController.cs index 6aff0418..e7243022 100644 --- a/src/Yavsc/Controllers/Contracting/FormsController.cs +++ b/src/Yavsc/Controllers/Contracting/FormsController.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Forms; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Yavsc/Controllers/Contracting/MusicalTendenciesController.cs b/src/Yavsc/Controllers/Contracting/MusicalTendenciesController.cs index 198e3177..ca7996a3 100644 --- a/src/Yavsc/Controllers/Contracting/MusicalTendenciesController.cs +++ b/src/Yavsc/Controllers/Contracting/MusicalTendenciesController.cs @@ -5,6 +5,7 @@ namespace Yavsc.Controllers using Models; using Models.Musical; using Yavsc.Helpers; + using Yavsc.Server.Helpers; public class MusicalTendenciesController : Controller { diff --git a/src/Yavsc/Controllers/Contracting/SIRENExceptionsController.cs b/src/Yavsc/Controllers/Contracting/SIRENExceptionsController.cs index 64338f9a..4d485558 100644 --- a/src/Yavsc/Controllers/Contracting/SIRENExceptionsController.cs +++ b/src/Yavsc/Controllers/Contracting/SIRENExceptionsController.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Billing; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Yavsc/Controllers/Generic/SettingsController.cs b/src/Yavsc/Controllers/Generic/SettingsController.cs index 96002836..8c490a1c 100644 --- a/src/Yavsc/Controllers/Generic/SettingsController.cs +++ b/src/Yavsc/Controllers/Generic/SettingsController.cs @@ -7,6 +7,7 @@ namespace Yavsc.Controllers.Generic using Microsoft.EntityFrameworkCore; using Models; using Yavsc.Helpers; + using Yavsc.Server.Helpers; using Yavsc.Services; [Authorize] diff --git a/src/Yavsc/Controllers/Haircut/ColorsController.cs b/src/Yavsc/Controllers/Haircut/ColorsController.cs index 06ff3ba8..ef390f84 100644 --- a/src/Yavsc/Controllers/Haircut/ColorsController.cs +++ b/src/Yavsc/Controllers/Haircut/ColorsController.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Drawing; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Yavsc/Controllers/Haircut/HairCutCommandController.cs b/src/Yavsc/Controllers/Haircut/HairCutCommandController.cs index 182e0cf0..340a0776 100644 --- a/src/Yavsc/Controllers/Haircut/HairCutCommandController.cs +++ b/src/Yavsc/Controllers/Haircut/HairCutCommandController.cs @@ -26,6 +26,7 @@ namespace Yavsc.Controllers using Yavsc.Interface; using Yavsc.Settings; using Yavsc.Abstract.Models.Messaging; + using Yavsc.Server.Helpers; public class HairCutCommandController : CommandController { diff --git a/src/Yavsc/Controllers/Haircut/HairTaintsController.cs b/src/Yavsc/Controllers/Haircut/HairTaintsController.cs index c3662f69..a0a25246 100644 --- a/src/Yavsc/Controllers/Haircut/HairTaintsController.cs +++ b/src/Yavsc/Controllers/Haircut/HairTaintsController.cs @@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Haircut; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Yavsc/Controllers/HomeController.cs b/src/Yavsc/Controllers/HomeController.cs index 7f53eeda..fb040b73 100644 --- a/src/Yavsc/Controllers/HomeController.cs +++ b/src/Yavsc/Controllers/HomeController.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc.Localization; using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Diagnostics; using Microsoft.Extensions.Options; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Yavsc/Controllers/IT/GitController.cs b/src/Yavsc/Controllers/IT/GitController.cs index 2e83bfe4..f093934c 100644 --- a/src/Yavsc/Controllers/IT/GitController.cs +++ b/src/Yavsc/Controllers/IT/GitController.cs @@ -5,6 +5,7 @@ using Yavsc.Models; using Yavsc.Server.Models.IT.SourceCode; using Yavsc.Helpers; using Microsoft.EntityFrameworkCore; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Yavsc/Controllers/Musical/InstrumentationController.cs b/src/Yavsc/Controllers/Musical/InstrumentationController.cs index d84cf31c..256637c4 100644 --- a/src/Yavsc/Controllers/Musical/InstrumentationController.cs +++ b/src/Yavsc/Controllers/Musical/InstrumentationController.cs @@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Musical.Profiles; +using Yavsc.Server.Helpers; namespace Yavsc.Controllers { diff --git a/src/Yavsc/Controllers/Musical/InstrumentsController.cs b/src/Yavsc/Controllers/Musical/InstrumentsController.cs index 4f6e457c..7c0d6cb3 100644 --- a/src/Yavsc/Controllers/Musical/InstrumentsController.cs +++ b/src/Yavsc/Controllers/Musical/InstrumentsController.cs @@ -7,6 +7,7 @@ namespace Yavsc.Controllers using Models; using Models.Musical; using Yavsc.Helpers; + using Yavsc.Server.Helpers; public class InstrumentsController : Controller { diff --git a/src/Yavsc/Extensions/PermissionHandler.cs b/src/Yavsc/Extensions/PermissionHandler.cs index 4bee4f4c..b97832ff 100644 --- a/src/Yavsc/Extensions/PermissionHandler.cs +++ b/src/Yavsc/Extensions/PermissionHandler.cs @@ -6,6 +6,7 @@ using Yavsc.Helpers; using Yavsc.Migrations; using Yavsc.Models; using Yavsc.Models.Blog; +using Yavsc.Server.Helpers; using Yavsc.ViewModels.Auth; namespace Yavsc.Extensions; diff --git a/src/Yavsc/Helpers/UserHelpers.cs b/src/Yavsc/Helpers/UserHelpers.cs index ade8cac0..ca3d9ec3 100644 --- a/src/Yavsc/Helpers/UserHelpers.cs +++ b/src/Yavsc/Helpers/UserHelpers.cs @@ -1,10 +1,32 @@ -using System.Security.Claims; +using Microsoft.EntityFrameworkCore; +using Yavsc.Models; +using Yavsc.Models.Blog; namespace Yavsc.Helpers { public static class UserHelpers { - - + public static IEnumerable UserPosts(this ApplicationDbContext dbContext, string posterId, string? readerId) + { + if (readerId == null) + { + var userPosts = dbContext.blogSpotPublications.Include( + b => b.BlogPost + ).Where(x => x.BlogPost.AuthorId == posterId) + .Select(x => x.BlogPost).ToArray(); + return userPosts; + } + else + { + long[] readerCirclesMemberships = + dbContext.Circle.Include(c => c.Members) + .Where(c => c.Members.Any(m => m.MemberId == readerId)) + .Select(c => c.Id).ToArray(); + return dbContext.BlogSpot.Include( + b => b.Author + ).Include(p => p.ACL).Where(x => x.Author.Id == posterId && + (x.ACL.Count == 0 || x.ACL.Any(a => readerCirclesMemberships.Contains(a.CircleId)))); + } + } } } diff --git a/src/Yavsc.Server/Services/BlogSpotService.cs b/src/Yavsc/Services/BlogSpotService.cs similarity index 99% rename from src/Yavsc.Server/Services/BlogSpotService.cs rename to src/Yavsc/Services/BlogSpotService.cs index 78d6932a..ceebdaa7 100644 --- a/src/Yavsc.Server/Services/BlogSpotService.cs +++ b/src/Yavsc/Services/BlogSpotService.cs @@ -9,6 +9,7 @@ using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Blog; using Yavsc.Server.Exceptions; +using Yavsc.Server.Helpers; using Yavsc.ViewModels.Auth; using Yavsc.ViewModels.Blog; diff --git a/src/Yavsc.Server/Services/ChatHubConnexionManager.cs b/src/Yavsc/Services/ChatHubConnexionManager.cs similarity index 99% rename from src/Yavsc.Server/Services/ChatHubConnexionManager.cs rename to src/Yavsc/Services/ChatHubConnexionManager.cs index d47c7af8..a17abed9 100644 --- a/src/Yavsc.Server/Services/ChatHubConnexionManager.cs +++ b/src/Yavsc/Services/ChatHubConnexionManager.cs @@ -49,10 +49,8 @@ namespace Yavsc.Services public static ConcurrentDictionary Channels = new ConcurrentDictionary(); readonly ApplicationDbContext _dbContext; readonly IStringLocalizer _localizer; - public HubConnectionManager(IServiceScopeFactory ssf ) { - var scope = ssf.CreateScope(); _dbContext = scope.ServiceProvider.GetService(); var loggerFactory = scope.ServiceProvider.GetService(); diff --git a/src/Yavsc/Services/ClientStore.cs b/src/Yavsc/Services/ClientStore.cs index f54d07d5..a9ef06ee 100644 --- a/src/Yavsc/Services/ClientStore.cs +++ b/src/Yavsc/Services/ClientStore.cs @@ -23,8 +23,15 @@ public class ClientStore : IClientStore ClientId = clientFromDb.Id, ClientName = clientFromDb.DisplayName, ClientSecrets = { new Secret(clientFromDb.Secret.Sha256()) }, - AllowedGrantTypes =[ GrantType.ClientCredentials, GrantType.DeviceFlow], - AllowedScopes = ["openid", "profile", "scope1"] + AllowedGrantTypes = + [ + GrantType.AuthorizationCode, + GrantType.DeviceFlow, + GrantType.ClientCredentials + ], + AllowedScopes = ["openid", "profile", "scope1"], + AbsoluteRefreshTokenLifetime = clientFromDb.RefreshTokenLifeTime, + AccessTokenLifetime = clientFromDb.AccessTokenLifetime }; } } diff --git a/src/Yavsc.Server/Services/DiskUsageTracker.cs b/src/Yavsc/Services/DiskUsageTracker.cs similarity index 100% rename from src/Yavsc.Server/Services/DiskUsageTracker.cs rename to src/Yavsc/Services/DiskUsageTracker.cs diff --git a/src/Yavsc.Server/Services/YavscTemplateEngine.cs b/src/Yavsc/Services/YavscTemplateEngine.cs similarity index 100% rename from src/Yavsc.Server/Services/YavscTemplateEngine.cs rename to src/Yavsc/Services/YavscTemplateEngine.cs diff --git a/src/Yavsc/Views/_ViewImports.cshtml b/src/Yavsc/Views/_ViewImports.cshtml index 64f07170..d6e55ca8 100755 --- a/src/Yavsc/Views/_ViewImports.cshtml +++ b/src/Yavsc/Views/_ViewImports.cshtml @@ -29,6 +29,7 @@ @using Microsoft.AspNetCore.Html; @using Microsoft.AspNetCore.Identity; @using Yavsc.Helpers; +@using Yavsc.Server.Helpers; @using PayPal.PayPalAPIInterfaceService.Model; @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/test/yavscTests/Mandatory/Remoting.cs b/test/yavscTests/Mandatory/Remoting.cs index 1d87879c..2199785a 100644 --- a/test/yavscTests/Mandatory/Remoting.cs +++ b/test/yavscTests/Mandatory/Remoting.cs @@ -30,10 +30,13 @@ namespace yavscTests { try { + var serverUrl = _serverFixture.Addresses.FirstOrDefault(); + String auth = _serverFixture.SiteSettings.Authority; - var oauthor = new OAuthenticator(clientId, clientSecret, scope, - new Uri(authorizeUrl), new Uri(redirectUrl), new Uri(accessTokenUrl)); + var oauthor = new OAuthenticator(_serverFixture.TestClientId, _serverFixture.TestClientSecret, + "profile", + new Uri(serverUrl), new Uri(serverUrl), new Uri(serverUrl+"/connect/token")); var query = new Dictionary { ["Username"] = userName, diff --git a/test/yavscTests/WebServerFixture.cs b/test/yavscTests/WebServerFixture.cs index f1dd87e9..f43ae25e 100644 --- a/test/yavscTests/WebServerFixture.cs +++ b/test/yavscTests/WebServerFixture.cs @@ -17,6 +17,7 @@ using yavscTests.Settings; using Yavsc.Extensions; using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Mvc.ModelBinding.Binders; +using Yavsc.Models.Auth; namespace isnd.tests { @@ -32,6 +33,7 @@ namespace isnd.tests public IConfigurationRoot Configuration { get; private set; } private WebApplication app; + public string TestClientId { get; private set; } public IServiceProvider Services { get; private set; } public string TestingUserName { get; private set; } @@ -41,6 +43,7 @@ namespace isnd.tests public SiteSettings SiteSettings { get => siteSettings; set => siteSettings = value; } public MailSender MailSender { get; internal set; } public TestingSetup? TestingSetup { get; internal set; } + public string TestClientSecret { get; private set; } = "TestClientSecret"; public WebServerFixture() { @@ -56,14 +59,14 @@ namespace isnd.tests public async Task SetupHost() { var builder = WebApplication.CreateBuilder(); - + Configuration = builder.Configuration .AddJsonFile("appsettings.json") .AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true) .AddEnvironmentVariables() .Build(); - this.app = builder.ConfigureWebAppServices(); + this.app = builder.ConfigureWebAppServices(); Services = app.Services; using (var migrationScope = app.Services.CreateScope()) { @@ -73,8 +76,8 @@ namespace isnd.tests await app.ConfigurePipeline(); app.UseSession(); await app.StartAsync(); - - + + var logFactory = app.Services.GetRequiredService(); Logger = logFactory.CreateLogger(); @@ -94,14 +97,28 @@ namespace isnd.tests scope.ServiceProvider.GetRequiredService(); //dbContext.Database.EnsureCreated(); dbContext.Database.Migrate(); - - TestingUserName = "Tester"; - TestingUser = dbContext.Users.FirstOrDefault(u => u.UserName == TestingUserName); - EnsureUser(TestingUserName); - - ServicePointManager.ServerCertificateValidationCallback = - (sender, cert, chain, sslPolicyErrors) => true; + TestingUserName = "Tester"; + TestClientId = "testClientId"; + TestingUser = await dbContext.Users.FirstOrDefaultAsync(u => u.UserName == TestingUserName); + EnsureUser(TestingUserName); + // ensure a client + var testClient = await dbContext.Client.FirstOrDefaultAsync((c) => c.Id == TestClientId); + if (testClient == null) + { + testClient = new Yavsc.Models.Auth.Client + { + Id = TestClientId, + DisplayName = "Testing Client", + Secret = TestClientSecret, + Active = true, + Type = ApplicationTypes.NativeConfidential, + AccessTokenLifetime = 900, + RefreshTokenLifeTime = 15000 + }; + dbContext.Client.Add(testClient); + dbContext.SaveChanges(); + } } public void EnsureUser(string testingUserName) @@ -113,7 +130,6 @@ namespace isnd.tests var userManager = scope.ServiceProvider.GetRequiredService>(); - TestingUser = new ApplicationUser { UserName = testingUserName, @@ -130,7 +146,5 @@ namespace isnd.tests TestingUser = dbContext.Users.FirstOrDefault(u => u.UserName == testingUserName); } } - - } }