mirror of https://github.com/Squidex/squidex.git
21 changed files with 214 additions and 39 deletions
@ -0,0 +1,50 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Squidex.Domain.Apps.Entities.Apps.Commands; |
||||
|
using Squidex.Infrastructure; |
||||
|
using Squidex.Infrastructure.Commands; |
||||
|
using Squidex.Shared.Users; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Apps |
||||
|
{ |
||||
|
public sealed class InviteCommandMiddleware : ICommandMiddleware |
||||
|
{ |
||||
|
private readonly IUserResolver userResolver; |
||||
|
|
||||
|
public InviteCommandMiddleware(IUserResolver userResolver) |
||||
|
{ |
||||
|
Guard.NotNull(userResolver, nameof(userResolver)); |
||||
|
|
||||
|
this.userResolver = userResolver; |
||||
|
} |
||||
|
|
||||
|
public async Task HandleAsync(CommandContext context, Func<Task> next) |
||||
|
{ |
||||
|
if (context.Command is AssignContributor assignContributor) |
||||
|
{ |
||||
|
if (assignContributor.IsInviting && assignContributor.ContributorId.IsEmail()) |
||||
|
{ |
||||
|
var isInvited = await userResolver.CreateUserIfNotExists(assignContributor.ContributorId); |
||||
|
|
||||
|
await next(); |
||||
|
|
||||
|
if (isInvited && context.Result<object>() is EntityCreatedResult<string> id) |
||||
|
{ |
||||
|
context.Complete(new InvitedResult { Id = id }); |
||||
|
} |
||||
|
|
||||
|
return; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
await next(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Squidex.Infrastructure.Commands; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Apps |
||||
|
{ |
||||
|
public sealed class InvitedResult |
||||
|
{ |
||||
|
public EntityCreatedResult<string> Id { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Apps.Templates |
||||
|
{ |
||||
|
public static class Scripts |
||||
|
{ |
||||
|
public const string Slug = |
||||
|
@"var data = ctx.data;
|
||||
|
|
||||
|
if (data.title && data.title.iv) { |
||||
|
data.slug = { iv: slugify(data.title.iv) }; |
||||
|
|
||||
|
replace(data); |
||||
|
} |
||||
|
";
|
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue