btcpayserver/BTCPayServer/Services/Notifications/Blobs/InviteAcceptedNotification.cs
d11n 09dbe44bca
Onboarding: Invite new users on store level (#5719)
* Onboarding: Invite new users

- Separates the user self-registration and invite cases
- Adds invitation email for users created by the admin
- Adds invitation tokens to verify user was invited
- Adds handler action for invite links
- Refactors `UserEventHostedService`
- Fixes #5726.

* Add permissioned form tag helper

* Better way of changing a user's role

* Test fixes
2024-03-19 14:58:33 +01:00

53 lines
1.8 KiB
C#

using BTCPayServer.Abstractions.Contracts;
using BTCPayServer.Configuration;
using BTCPayServer.Controllers;
using BTCPayServer.Data;
using Microsoft.AspNetCore.Routing;
namespace BTCPayServer.Services.Notifications.Blobs;
internal class InviteAcceptedNotification : BaseNotification
{
private const string TYPE = "inviteaccepted";
public string UserId { get; set; }
public string UserEmail { get; set; }
public string StoreId { get; set; }
public string StoreName { get; set; }
public override string Identifier => TYPE;
public override string NotificationType => TYPE;
public InviteAcceptedNotification()
{
}
public InviteAcceptedNotification(ApplicationUser user, StoreData store)
{
UserId = user.Id;
UserEmail = user.Email;
StoreId = store.Id;
StoreName = store.StoreName;
}
internal class Handler(LinkGenerator linkGenerator, BTCPayServerOptions options)
: NotificationHandler<InviteAcceptedNotification>
{
public override string NotificationType => TYPE;
public override (string identifier, string name)[] Meta
{
get
{
return [(TYPE, "User accepted invitation")];
}
}
protected override void FillViewModel(InviteAcceptedNotification notification, NotificationViewModel vm)
{
vm.Identifier = notification.Identifier;
vm.Type = notification.NotificationType;
vm.Body = $"User {notification.UserEmail} accepted the invite to {notification.StoreName}.";
vm.ActionLink = linkGenerator.GetPathByAction(nameof(UIStoresController.StoreUsers),
"UIStores",
new { storeId = notification.StoreId }, options.RootPath);
}
}
}