mirror of https://github.com/Squidex/squidex.git
39 changed files with 346 additions and 83 deletions
@ -0,0 +1,17 @@ |
|||||
|
// ==========================================================================
|
||||
|
// PermissionLevel.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
namespace Squidex.Core.Apps |
||||
|
{ |
||||
|
public enum PermissionLevel |
||||
|
{ |
||||
|
Owner, |
||||
|
Developer, |
||||
|
Editor |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
// ==========================================================================
|
||||
|
// AppContributorAssigned.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Squidex.Core.Apps; |
||||
|
using Squidex.Infrastructure; |
||||
|
using Squidex.Infrastructure.CQRS.Events; |
||||
|
|
||||
|
namespace Squidex.Events.Apps |
||||
|
{ |
||||
|
[TypeName("AppContributorAssigned")] |
||||
|
public class AppContributorAssigned : IEvent |
||||
|
{ |
||||
|
public string SubjectId { get; set; } |
||||
|
|
||||
|
public PermissionLevel Permission { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
// ==========================================================================
|
||||
|
// ISubjectCommand.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
namespace Squidex.Infrastructure.CQRS.Commands |
||||
|
{ |
||||
|
public interface ISubjectCommand : ICommand |
||||
|
{ |
||||
|
string SubjectId { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
// ==========================================================================
|
||||
|
// IAppContributorEntity.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Squidex.Core.Apps; |
||||
|
|
||||
|
namespace Squidex.Read.Apps |
||||
|
{ |
||||
|
public interface IAppContributorEntity |
||||
|
{ |
||||
|
string SubjectId { get; } |
||||
|
|
||||
|
PermissionLevel Permission { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
// ==========================================================================
|
||||
|
// MongoAppContributorEntity.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using MongoDB.Bson.Serialization.Attributes; |
||||
|
using Squidex.Core.Apps; |
||||
|
using Squidex.Read.Apps; |
||||
|
|
||||
|
namespace Squidex.Store.MongoDb.Apps |
||||
|
{ |
||||
|
public sealed class MongoAppContributorEntity : IAppContributorEntity |
||||
|
{ |
||||
|
[BsonRequired] |
||||
|
[BsonElement] |
||||
|
public string SubjectId { get; set; } |
||||
|
|
||||
|
[BsonRequired] |
||||
|
[BsonElement] |
||||
|
public PermissionLevel Permission { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,42 @@ |
|||||
|
{ |
||||
|
"version": "0.2.0", |
||||
|
"configurations": [ |
||||
|
{ |
||||
|
"name": ".NET Core Launch (web)", |
||||
|
"type": "coreclr", |
||||
|
"request": "launch", |
||||
|
"preLaunchTask": "build", |
||||
|
"program": "${workspaceRoot}\\bin\\Debug\\netcoreapp1.0\\Squidex.dll", |
||||
|
"args": [], |
||||
|
"cwd": "${workspaceRoot}", |
||||
|
"stopAtEntry": false, |
||||
|
"internalConsoleOptions": "openOnSessionStart", |
||||
|
"launchBrowser": { |
||||
|
"enabled": true, |
||||
|
"args": "${auto-detect-url}", |
||||
|
"windows": { |
||||
|
"command": "cmd.exe", |
||||
|
"args": "/C start ${auto-detect-url}" |
||||
|
}, |
||||
|
"osx": { |
||||
|
"command": "open" |
||||
|
}, |
||||
|
"linux": { |
||||
|
"command": "xdg-open" |
||||
|
} |
||||
|
}, |
||||
|
"env": { |
||||
|
"ASPNETCORE_ENVIRONMENT": "Development" |
||||
|
}, |
||||
|
"sourceFileMap": { |
||||
|
"/Views": "${workspaceRoot}/Views" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
"name": ".NET Core Attach", |
||||
|
"type": "coreclr", |
||||
|
"request": "attach", |
||||
|
"processId": "${command.pickProcess}" |
||||
|
} |
||||
|
] |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
{ |
||||
|
"version": "0.1.0", |
||||
|
"command": "dotnet", |
||||
|
"isShellCommand": true, |
||||
|
"args": [], |
||||
|
"tasks": [ |
||||
|
{ |
||||
|
"taskName": "build", |
||||
|
"args": [ |
||||
|
"${workspaceRoot}\\project.json" |
||||
|
], |
||||
|
"isBuildCommand": true, |
||||
|
"problemMatcher": "$msCompile" |
||||
|
} |
||||
|
] |
||||
|
} |
||||
@ -0,0 +1,46 @@ |
|||||
|
// ==========================================================================
|
||||
|
// EnrichWithSubjectHandler.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Security; |
||||
|
using System.Security.Claims; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Squidex.Infrastructure.CQRS.Commands; |
||||
|
// ReSharper disable InvertIf
|
||||
|
|
||||
|
namespace Squidex.Pipeline.CommandHandlers |
||||
|
{ |
||||
|
public class EnrichWithSubjectHandler : ICommandHandler |
||||
|
{ |
||||
|
private readonly IHttpContextAccessor httpContextAccessor; |
||||
|
|
||||
|
public EnrichWithSubjectHandler(IHttpContextAccessor httpContextAccessor) |
||||
|
{ |
||||
|
this.httpContextAccessor = httpContextAccessor; |
||||
|
} |
||||
|
|
||||
|
public Task<bool> HandleAsync(CommandContext context) |
||||
|
{ |
||||
|
var subjectCommand = context.Command as ISubjectCommand; |
||||
|
|
||||
|
if (subjectCommand != null) |
||||
|
{ |
||||
|
var user = httpContextAccessor.HttpContext.User; |
||||
|
|
||||
|
if (user?.FindFirst(ClaimTypes.NameIdentifier) == null) |
||||
|
{ |
||||
|
throw new SecurityException("No user available"); |
||||
|
} |
||||
|
|
||||
|
subjectCommand.SubjectId = user.FindFirst(ClaimTypes.NameIdentifier).Value; |
||||
|
} |
||||
|
|
||||
|
return Task.FromResult(false); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
After Width: | Height: | Size: 26 KiB |
Loading…
Reference in new issue