mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-24 22:58:28 +01:00
* 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
98 lines
4 KiB
C#
98 lines
4 KiB
C#
using BTCPayServer.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using Newtonsoft.Json;
|
|
|
|
#nullable disable
|
|
|
|
namespace BTCPayServer.Migrations
|
|
{
|
|
[DbContext(typeof(ApplicationDbContext))]
|
|
[Migration("20240229092905_AddManagerAndEmployeeToStoreRoles")]
|
|
public partial class AddManagerAndEmployeeToStoreRoles : Migration
|
|
{
|
|
object GetPermissionsData(MigrationBuilder migrationBuilder, string[] permissions)
|
|
{
|
|
return migrationBuilder.IsNpgsql()
|
|
? permissions
|
|
: JsonConvert.SerializeObject(permissions);
|
|
}
|
|
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
var permissionsType = migrationBuilder.IsNpgsql() ? "TEXT[]" : "TEXT";
|
|
migrationBuilder.InsertData(
|
|
"StoreRoles",
|
|
columns: new[] { "Id", "Role", "Permissions" },
|
|
columnTypes: new[] { "TEXT", "TEXT", permissionsType },
|
|
values: new object[,]
|
|
{
|
|
{
|
|
"Manager", "Manager", GetPermissionsData(migrationBuilder, new[]
|
|
{
|
|
"btcpay.store.canviewstoresettings",
|
|
"btcpay.store.canmodifyinvoices",
|
|
"btcpay.store.webhooks.canmodifywebhooks",
|
|
"btcpay.store.canmodifypaymentrequests",
|
|
"btcpay.store.canmanagepullpayments",
|
|
"btcpay.store.canmanagepayouts"
|
|
})
|
|
},
|
|
{
|
|
"Employee", "Employee", GetPermissionsData(migrationBuilder, new[]
|
|
{
|
|
"btcpay.store.canmodifyinvoices",
|
|
"btcpay.store.canmodifypaymentrequests",
|
|
"btcpay.store.cancreatenonapprovedpullpayments",
|
|
"btcpay.store.canviewpayouts",
|
|
"btcpay.store.canviewpullpayments"
|
|
})
|
|
}
|
|
});
|
|
|
|
migrationBuilder.UpdateData(
|
|
"StoreRoles",
|
|
keyColumns: new[] { "Id" },
|
|
keyColumnTypes: new[] { "TEXT" },
|
|
keyValues: new[] { "Guest" },
|
|
columns: new[] { "Permissions" },
|
|
columnTypes: new[] { permissionsType },
|
|
values: new object[]
|
|
{
|
|
GetPermissionsData(migrationBuilder, new[]
|
|
{
|
|
"btcpay.store.canmodifyinvoices",
|
|
"btcpay.store.canviewpaymentrequests",
|
|
"btcpay.store.canviewpullpayments",
|
|
"btcpay.store.canviewpayouts"
|
|
})
|
|
});
|
|
}
|
|
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DeleteData("StoreRoles", "Id", "Manager");
|
|
migrationBuilder.DeleteData("StoreRoles", "Id", "Employee");
|
|
|
|
var permissionsType = migrationBuilder.IsNpgsql() ? "TEXT[]" : "TEXT";
|
|
migrationBuilder.UpdateData(
|
|
"StoreRoles",
|
|
keyColumns: new[] { "Id" },
|
|
keyColumnTypes: new[] { "TEXT" },
|
|
keyValues: new[] { "Guest" },
|
|
columns: new[] { "Permissions" },
|
|
columnTypes: new[] { permissionsType },
|
|
values: new object[]
|
|
{
|
|
GetPermissionsData(migrationBuilder, new[]
|
|
{
|
|
"btcpay.store.canviewstoresettings",
|
|
"btcpay.store.canmodifyinvoices",
|
|
"btcpay.store.canviewcustodianaccounts",
|
|
"btcpay.store.candeposittocustodianaccount"
|
|
})
|
|
});
|
|
}
|
|
}
|
|
}
|