mirror of https://github.com/Squidex/squidex.git
47 changed files with 418 additions and 266 deletions
@ -0,0 +1,89 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Squidex.Infrastructure; |
||||
|
using Squidex.Infrastructure.Security; |
||||
|
using System.Collections.Generic; |
||||
|
using P = Squidex.Shared.Permissions; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core.Apps |
||||
|
{ |
||||
|
public sealed class Role |
||||
|
{ |
||||
|
public const string Editor = "Editor"; |
||||
|
public const string Developer = "Developer"; |
||||
|
public const string Owner = "Owner"; |
||||
|
public const string Reader = "Reader"; |
||||
|
|
||||
|
private static readonly HashSet<string> DefaultRolesSet = new HashSet<string> |
||||
|
{ |
||||
|
Editor, |
||||
|
Developer, |
||||
|
Owner, |
||||
|
Reader |
||||
|
}; |
||||
|
|
||||
|
public string Name { get; } |
||||
|
|
||||
|
public PermissionSet Permissions { get; } |
||||
|
|
||||
|
public Role(string name, PermissionSet permissions) |
||||
|
{ |
||||
|
Guard.NotNullOrEmpty(name, nameof(name)); |
||||
|
Guard.NotNull(permissions, nameof(permissions)); |
||||
|
|
||||
|
Name = name; |
||||
|
|
||||
|
Permissions = permissions; |
||||
|
} |
||||
|
|
||||
|
public Role(string name, params Permission[] permissions) |
||||
|
: this(name, new PermissionSet(permissions)) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public static bool IsDefaultRole(string role) |
||||
|
{ |
||||
|
return role != null && DefaultRolesSet.Contains(role); |
||||
|
} |
||||
|
|
||||
|
public static Role CreateOwner(string app) |
||||
|
{ |
||||
|
return new Role(Owner, |
||||
|
P.ForApp(P.App, app)); |
||||
|
} |
||||
|
|
||||
|
public static Role CreateEditor(string app) |
||||
|
{ |
||||
|
return new Role(Editor, |
||||
|
P.ForApp(P.AppCommon, app), |
||||
|
P.ForApp(P.AppContents, app), |
||||
|
P.ForApp(P.AppAssets, app)); |
||||
|
} |
||||
|
|
||||
|
public static Role CreateReader(string app) |
||||
|
{ |
||||
|
return new Role(Reader, |
||||
|
P.ForApp(P.AppAssetsRead, app), |
||||
|
P.ForApp(P.AppCommon, app), |
||||
|
P.ForApp(P.AppContentsRead, app), |
||||
|
P.ForApp(P.AppContentsGraphQL, app)); |
||||
|
} |
||||
|
|
||||
|
public static Role CreateDeveloper(string app) |
||||
|
{ |
||||
|
return new Role(Developer, |
||||
|
P.ForApp(P.AppApi, app), |
||||
|
P.ForApp(P.AppAssets, app), |
||||
|
P.ForApp(P.AppCommon, app), |
||||
|
P.ForApp(P.AppContents, app), |
||||
|
P.ForApp(P.AppPatterns, app), |
||||
|
P.ForApp(P.AppRules, app), |
||||
|
P.ForApp(P.AppSchemas, app)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,77 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using Squidex.Infrastructure; |
|
||||
using Squidex.Infrastructure.Security; |
|
||||
using Squidex.Shared; |
|
||||
using System.Linq; |
|
||||
|
|
||||
namespace Squidex.Domain.Apps.Core.Apps |
|
||||
{ |
|
||||
public static class RoleExtension |
|
||||
{ |
|
||||
public static string[] ToPermissionIds(this AppClientPermission clientPermission, string app) |
|
||||
{ |
|
||||
return clientPermission.ToPermissions(app).ToIds().ToArray(); |
|
||||
} |
|
||||
|
|
||||
public static string[] ToPermissionIds(this AppContributorPermission contributorPermission, string app) |
|
||||
{ |
|
||||
return contributorPermission.ToPermissions(app).ToIds().ToArray(); |
|
||||
} |
|
||||
|
|
||||
public static PermissionSet ToPermissions(this AppClientPermission clientPermission, string app) |
|
||||
{ |
|
||||
Guard.Enum(clientPermission, nameof(clientPermission)); |
|
||||
Guard.NotNullOrEmpty(app, nameof(app)); |
|
||||
|
|
||||
switch (clientPermission) |
|
||||
{ |
|
||||
case AppClientPermission.Developer: |
|
||||
return ToPermissions(AppContributorPermission.Developer, app); |
|
||||
case AppClientPermission.Editor: |
|
||||
return ToPermissions(AppContributorPermission.Editor, app); |
|
||||
case AppClientPermission.Reader: |
|
||||
return new PermissionSet( |
|
||||
Permissions.ForApp(Permissions.AppCommon, app), |
|
||||
Permissions.ForApp(Permissions.AppContentsRead, app), |
|
||||
Permissions.ForApp(Permissions.AppContentsGraphQL, app)); |
|
||||
} |
|
||||
|
|
||||
return PermissionSet.Empty; |
|
||||
} |
|
||||
|
|
||||
public static PermissionSet ToPermissions(this AppContributorPermission contributorPermission, string app) |
|
||||
{ |
|
||||
Guard.Enum(contributorPermission, nameof(contributorPermission)); |
|
||||
Guard.NotNullOrEmpty(app, nameof(app)); |
|
||||
|
|
||||
switch (contributorPermission) |
|
||||
{ |
|
||||
case AppContributorPermission.Owner: |
|
||||
return new PermissionSet( |
|
||||
Permissions.ForApp(Permissions.App, app)); |
|
||||
case AppContributorPermission.Developer: |
|
||||
return new PermissionSet( |
|
||||
Permissions.ForApp(Permissions.AppApi, app), |
|
||||
Permissions.ForApp(Permissions.AppAssets, app), |
|
||||
Permissions.ForApp(Permissions.AppCommon, app), |
|
||||
Permissions.ForApp(Permissions.AppContents, app), |
|
||||
Permissions.ForApp(Permissions.AppPatterns, app), |
|
||||
Permissions.ForApp(Permissions.AppRules, app), |
|
||||
Permissions.ForApp(Permissions.AppSchemas, app)); |
|
||||
case AppContributorPermission.Editor: |
|
||||
return new PermissionSet( |
|
||||
Permissions.ForApp(Permissions.AppCommon, app), |
|
||||
Permissions.ForApp(Permissions.AppContents, app), |
|
||||
Permissions.ForApp(Permissions.AppAssets, app)); |
|
||||
} |
|
||||
|
|
||||
return PermissionSet.Empty; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,39 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using System.Collections.Immutable; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core.Apps |
||||
|
{ |
||||
|
public sealed class Roles : DictionaryWrapper<string, Role> |
||||
|
{ |
||||
|
public static readonly Roles Empty = new Roles(); |
||||
|
|
||||
|
private Roles() |
||||
|
: base(ImmutableDictionary<string, Role>.Empty) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public Roles(ImmutableDictionary<string, Role> inner) |
||||
|
: base(inner) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public static Roles CreateDefaults(string app) |
||||
|
{ |
||||
|
return new Roles( |
||||
|
new Dictionary<string, Role> |
||||
|
{ |
||||
|
[Role.Developer] = Role.CreateDeveloper(app), |
||||
|
[Role.Editor] = Role.CreateEditor(app), |
||||
|
[Role.Owner] = Role.CreateOwner(app), |
||||
|
[Role.Reader] = Role.CreateReader(app) |
||||
|
}.ToImmutableDictionary()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,6 +0,0 @@ |
|||||
namespace Squidex.Domain.Apps.Core |
|
||||
{ |
|
||||
public sealed class DefaultPermissions |
|
||||
{ |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,45 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using Squidex.Domain.Apps.Core.Apps; |
||||
|
using Squidex.Domain.Apps.Events; |
||||
|
using Squidex.Infrastructure.EventSourcing; |
||||
|
using Squidex.Infrastructure.Reflection; |
||||
|
using AppClientUpdatedV2 = Squidex.Domain.Apps.Events.Apps.AppClientUpdated; |
||||
|
|
||||
|
namespace Migrate_01.OldEvents |
||||
|
{ |
||||
|
[EventType(nameof(AppClientUpdated))] |
||||
|
[Obsolete] |
||||
|
public sealed class AppClientUpdated : AppEvent, IMigratedEvent |
||||
|
{ |
||||
|
public string Id { get; set; } |
||||
|
|
||||
|
public AppClientPermission Permission { get; set; } |
||||
|
|
||||
|
public IEvent Migrate() |
||||
|
{ |
||||
|
var result = SimpleMapper.Map(this, new AppClientUpdatedV2()); |
||||
|
|
||||
|
switch (Permission) |
||||
|
{ |
||||
|
case AppClientPermission.Developer: |
||||
|
result.Role = Role.Developer; |
||||
|
break; |
||||
|
case AppClientPermission.Editor: |
||||
|
result.Role = Role.Editor; |
||||
|
break; |
||||
|
case AppClientPermission.Reader: |
||||
|
result.Role = Role.Reader; |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,45 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using Squidex.Domain.Apps.Core.Apps; |
||||
|
using Squidex.Domain.Apps.Events; |
||||
|
using Squidex.Infrastructure.EventSourcing; |
||||
|
using Squidex.Infrastructure.Reflection; |
||||
|
using AppContributorAssignedV2 = Squidex.Domain.Apps.Events.Apps.AppContributorAssigned; |
||||
|
|
||||
|
namespace Migrate_01.OldEvents |
||||
|
{ |
||||
|
[EventType(nameof(AppContributorAssigned))] |
||||
|
[Obsolete] |
||||
|
public sealed class AppContributorAssigned : AppEvent, IMigratedEvent |
||||
|
{ |
||||
|
public string ContributorId { get; set; } |
||||
|
|
||||
|
public AppContributorPermission Permission { get; set; } |
||||
|
|
||||
|
public IEvent Migrate() |
||||
|
{ |
||||
|
var result = SimpleMapper.Map(this, new AppContributorAssignedV2()); |
||||
|
|
||||
|
switch (Permission) |
||||
|
{ |
||||
|
case AppContributorPermission.Owner: |
||||
|
result.Role = Role.Owner; |
||||
|
break; |
||||
|
case AppContributorPermission.Developer: |
||||
|
result.Role = Role.Developer; |
||||
|
break; |
||||
|
case AppContributorPermission.Editor: |
||||
|
result.Role = Role.Editor; |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue