Refactoring
The main server owns the migrations, it's the server part, it's simpler. It's Yavsc, not one of its lib.main
parent
f43fd76baa
commit
a9b809f5e5
@ -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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,26 +1,2 @@
|
|||||||
SOURCE_DIR=../..
|
listConnections:
|
||||||
MAKEFILE_DIR=$(SOURCE_DIR)/scripts/make
|
dotnet ef migrations list --connection "$(YAVSC_CONNECTION_STRING)"
|
||||||
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)
|
|
||||||
|
|||||||
@ -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<Client> 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,10 +1,32 @@
|
|||||||
using System.Security.Claims;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Yavsc.Models;
|
||||||
|
using Yavsc.Models.Blog;
|
||||||
|
|
||||||
namespace Yavsc.Helpers
|
namespace Yavsc.Helpers
|
||||||
{
|
{
|
||||||
public static class UserHelpers
|
public static class UserHelpers
|
||||||
{
|
{
|
||||||
|
public static IEnumerable<BlogPost> 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))));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue