mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
36 changed files with 421 additions and 290 deletions
@ -1,61 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Linq; |
|||
using Squidex.Infrastructure.Security; |
|||
using Squidex.Shared; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Apps |
|||
{ |
|||
public static class RoleExtensions |
|||
{ |
|||
public static string[] Prefix(this string[] permissions, string name) |
|||
{ |
|||
var result = new string[permissions.Length + 1]; |
|||
|
|||
result[0] = Permissions.ForApp(Permissions.AppCommon, name).Id; |
|||
|
|||
if (permissions.Length > 0) |
|||
{ |
|||
var prefix = Permissions.ForApp(Permissions.App, name).Id; |
|||
|
|||
for (var i = 0; i < permissions.Length; i++) |
|||
{ |
|||
result[i + 1] = string.Concat(prefix, ".", permissions[i]); |
|||
} |
|||
} |
|||
|
|||
permissions = result.Distinct().ToArray(); |
|||
|
|||
return permissions; |
|||
} |
|||
|
|||
public static PermissionSet WithoutApp(this PermissionSet set, string name) |
|||
{ |
|||
var prefix = Permissions.ForApp(Permissions.App, name).Id; |
|||
|
|||
return new PermissionSet(set.Select(x => |
|||
{ |
|||
var id = x.Id; |
|||
|
|||
if (string.Equals(id, prefix, StringComparison.OrdinalIgnoreCase)) |
|||
{ |
|||
return Permission.Any; |
|||
} |
|||
else if (id.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) |
|||
{ |
|||
return id.Substring(prefix.Length + 1); |
|||
} |
|||
else |
|||
{ |
|||
return id; |
|||
} |
|||
}).Where(x => x != "common")); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|||
*/ |
|||
|
|||
import { Location } from '@angular/common'; |
|||
import { Component } from '@angular/core'; |
|||
|
|||
@Component({ |
|||
selector: 'sqx-forbidden-page', |
|||
template: ` |
|||
<sqx-title message="Not Found"></sqx-title> |
|||
|
|||
<div class="landing-page"> |
|||
<img class="splash-image" src="~/../squid.svg?title=FORBIDDEN&text=You%20are%20not%20allowed%20to%20view%20this%20page&background=white&small" /> |
|||
|
|||
<a href="#" (click)="back()">Back to previous page.</a> |
|||
</div> |
|||
` |
|||
}) |
|||
export class ForbiddenPageComponent { |
|||
constructor( |
|||
private readonly location: Location |
|||
) { |
|||
} |
|||
|
|||
public back() { |
|||
this.location.back(); |
|||
} |
|||
} |
|||
@ -1,13 +0,0 @@ |
|||
<sqx-title message="Not Found"></sqx-title> |
|||
|
|||
<div class="landing-page"> |
|||
<img class="splash-image" src="~/../squid.svg?title=OH%20DAMN&text=This%20is%20not%20the%20page%20you%20are%20looking%20for!&background=white&small" /> |
|||
|
|||
<h1>Not Found</h1> |
|||
|
|||
<p> |
|||
Sorry, the page or resource you are looking for does not exist. |
|||
</p> |
|||
|
|||
<a href="#" (click)="back()">Back to previous page.</a> |
|||
</div> |
|||
@ -1,2 +0,0 @@ |
|||
@import '_mixins'; |
|||
@import '_vars'; |
|||
@ -0,0 +1,79 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Linq; |
|||
using Squidex.Domain.Apps.Core.Apps; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Core.Model.Apps |
|||
{ |
|||
public class RoleTests |
|||
{ |
|||
[Fact] |
|||
public void Should_be_default_role() |
|||
{ |
|||
var role = new Role("Owner"); |
|||
|
|||
Assert.True(role.IsDefault); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_not_be_default_role() |
|||
{ |
|||
var role = new Role("Custom"); |
|||
|
|||
Assert.False(role.IsDefault); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_add_common_permission() |
|||
{ |
|||
var role = new Role("Name"); |
|||
|
|||
var result = role.ForApp("my-app").Permissions.ToIds(); |
|||
|
|||
Assert.Equal(new[] { "squidex.apps.my-app.common" }, result); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_not_have_duplicate_permission() |
|||
{ |
|||
var role = new Role("Name", "common", "common", "common"); |
|||
|
|||
var result = role.ForApp("my-app").Permissions.ToIds(); |
|||
|
|||
Assert.Single(result); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_ForApp_permission() |
|||
{ |
|||
var role = new Role("Name", "clients.read"); |
|||
|
|||
var result = role.ForApp("my-app").Permissions.ToIds(); |
|||
|
|||
Assert.Equal("squidex.apps.my-app.clients.read", result.ElementAt(1)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_check_for_name() |
|||
{ |
|||
var role = new Role("Custom"); |
|||
|
|||
Assert.True(role.Equals("Custom")); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_check_for_null_name() |
|||
{ |
|||
var role = new Role("Custom"); |
|||
|
|||
Assert.False(role.Equals(null)); |
|||
Assert.False(role.Equals("Other")); |
|||
} |
|||
} |
|||
} |
|||
@ -1,80 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Linq; |
|||
using Squidex.Infrastructure.Security; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Apps |
|||
{ |
|||
public class RoleExtensionsTests |
|||
{ |
|||
[Fact] |
|||
public void Should_add_common_permission() |
|||
{ |
|||
var source = Array.Empty<string>(); |
|||
var result = source.Prefix("my-app"); |
|||
|
|||
Assert.Equal(new[] { "squidex.apps.my-app.common" }, result); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_not_have_duplicate_permission() |
|||
{ |
|||
var source = new[] { "common", "common", "common" }; |
|||
var result = source.Prefix("my-app"); |
|||
|
|||
Assert.Single(result); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_prefix_permission() |
|||
{ |
|||
var source = new[] { "clients.read" }; |
|||
var result = source.Prefix("my-app"); |
|||
|
|||
Assert.Equal("squidex.apps.my-app.clients.read", result[1]); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_remove_app_prefix() |
|||
{ |
|||
var source = new PermissionSet("squidex.apps.my-app.clients"); |
|||
var result = source.WithoutApp("my-app"); |
|||
|
|||
Assert.Equal("clients", result.First().Id); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_not_remove_app_prefix_when_other_app() |
|||
{ |
|||
var source = new PermissionSet("squidex.apps.other-app.clients"); |
|||
var result = source.WithoutApp("my-app"); |
|||
|
|||
Assert.Equal("squidex.apps.other-app.clients", result.First().Id); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_set_to_wildcard_when_app_root_permission() |
|||
{ |
|||
var source = new PermissionSet("squidex.apps.my-app"); |
|||
var result = source.WithoutApp("my-app"); |
|||
|
|||
Assert.Equal(Permission.Any, result.First().Id); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_remove_common_permission() |
|||
{ |
|||
var source = new PermissionSet("squidex.apps.my-app.common"); |
|||
var result = source.WithoutApp("my-app"); |
|||
|
|||
Assert.Empty(result); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue