From 023e64704d101ab08aeed72bf2feba682b5356ff Mon Sep 17 00:00:00 2001 From: Kukks Date: Tue, 18 Feb 2020 10:50:01 +0100 Subject: [PATCH 1/9] Add Swagger and Redoc Blocked by #1262 --- BTCPayServer/BTCPayServer.csproj | 1 + .../Controllers/ManageController.APIKeys.cs | 13 ++- .../Controllers/StoresController.BTCLike.cs | 2 +- BTCPayServer/Hosting/BTCPayServerServices.cs | 4 +- .../Hosting/OpenApi/IncludeInOpenApiDocs.cs | 9 ++ .../Hosting/OpenApi/OpenApiExtensions.cs | 96 +++++++++++++++++++ 6 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 BTCPayServer/Hosting/OpenApi/IncludeInOpenApiDocs.cs create mode 100644 BTCPayServer/Hosting/OpenApi/OpenApiExtensions.cs diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index 749d9db8f..ae972afda 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -48,6 +48,7 @@ + diff --git a/BTCPayServer/Controllers/ManageController.APIKeys.cs b/BTCPayServer/Controllers/ManageController.APIKeys.cs index 26ff2aeec..03c78defe 100644 --- a/BTCPayServer/Controllers/ManageController.APIKeys.cs +++ b/BTCPayServer/Controllers/ManageController.APIKeys.cs @@ -4,13 +4,16 @@ using System.Globalization; using System.Linq; using System.Threading.Tasks; using BTCPayServer.Data; +using BTCPayServer.Hosting.OpenApi; using BTCPayServer.Models; using BTCPayServer.Security; using BTCPayServer.Security.APIKeys; using ExchangeSharp; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; +using NSwag.Annotations; namespace BTCPayServer.Controllers { @@ -56,8 +59,16 @@ namespace BTCPayServer.Controllers return View("AddApiKey", await SetViewModelValues(new AddApiKeyViewModel())); } + /// The permissions to request. Current permissions available: ServerManagement, StoreManagement + /// The name of your application + /// If permissions are specified, and strict is set to false, it will allow the user to reject some of permissions the application is requesting. + /// If the application is requesting the CanModifyStoreSettings permission and selectiveStores is set to true, this allows the user to only grant permissions to selected stores under the user's control. [HttpGet("~/api-keys/authorize")] - public async Task AuthorizeAPIKey( string[] permissions, string applicationName = null, + [OpenApiTags("Authorization")] + [OpenApiOperation("Authorize User", + "Redirect the browser to this endpoint to request the user to generate an api-key with specific permissions")] + [IncludeInOpenApiDocs] + public async Task AuthorizeAPIKey(string[] permissions, string applicationName = null, bool strict = true, bool selectiveStores = false) { if (!_btcPayServerEnvironment.IsSecure) diff --git a/BTCPayServer/Controllers/StoresController.BTCLike.cs b/BTCPayServer/Controllers/StoresController.BTCLike.cs index 8b01c240f..d1da40d96 100644 --- a/BTCPayServer/Controllers/StoresController.BTCLike.cs +++ b/BTCPayServer/Controllers/StoresController.BTCLike.cs @@ -142,7 +142,7 @@ namespace BTCPayServer.Controllers [HttpPost] [Route("{storeId}/derivations/{cryptoCode}")] - public async Task AddDerivationScheme(string storeId, DerivationSchemeViewModel vm, + public async Task AddDerivationScheme(string storeId, [FromBody] DerivationSchemeViewModel vm, string cryptoCode) { vm.CryptoCode = cryptoCode; diff --git a/BTCPayServer/Hosting/BTCPayServerServices.cs b/BTCPayServer/Hosting/BTCPayServerServices.cs index 7072b63e9..d455efd65 100644 --- a/BTCPayServer/Hosting/BTCPayServerServices.cs +++ b/BTCPayServer/Hosting/BTCPayServerServices.cs @@ -26,6 +26,7 @@ using System.Threading; using BTCPayServer.Services.Wallets; using BTCPayServer.Logging; using BTCPayServer.HostedServices; +using BTCPayServer.Hosting.OpenApi; using BTCPayServer.PaymentRequest; using BTCPayServer.Payments; using BTCPayServer.Payments.Bitcoin; @@ -262,7 +263,7 @@ namespace BTCPayServer.Hosting } return rateLimits; }); - + services.AddBTCPayOpenApi(); services.AddLogging(logBuilder => { @@ -291,6 +292,7 @@ namespace BTCPayServer.Hosting public static IApplicationBuilder UsePayServer(this IApplicationBuilder app) { app.UseMiddleware(); + app.UseBTCPayOpenApi(); return app; } public static IApplicationBuilder UseHeadersOverride(this IApplicationBuilder app) diff --git a/BTCPayServer/Hosting/OpenApi/IncludeInOpenApiDocs.cs b/BTCPayServer/Hosting/OpenApi/IncludeInOpenApiDocs.cs new file mode 100644 index 000000000..5921efdaf --- /dev/null +++ b/BTCPayServer/Hosting/OpenApi/IncludeInOpenApiDocs.cs @@ -0,0 +1,9 @@ +using System; + + +namespace BTCPayServer.Hosting.OpenApi +{ + public class IncludeInOpenApiDocs : Attribute + { + } +} diff --git a/BTCPayServer/Hosting/OpenApi/OpenApiExtensions.cs b/BTCPayServer/Hosting/OpenApi/OpenApiExtensions.cs new file mode 100644 index 000000000..60c05330d --- /dev/null +++ b/BTCPayServer/Hosting/OpenApi/OpenApiExtensions.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using BTCPayServer.Payments; +using BTCPayServer.Security; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using NJsonSchema; +using NJsonSchema.Generation.TypeMappers; +using NSwag; +using NSwag.Generation.Processors.Security; + +namespace BTCPayServer.Hosting.OpenApi +{ + public static class OpenApiExtensions + { + public static IServiceCollection AddBTCPayOpenApi(this IServiceCollection serviceCollection) + { + + return serviceCollection.AddOpenApiDocument(config => + { + config.PostProcess = document => + { + document.Info.Version = "v1"; + document.Info.Title = "BTCPay Greenfield API"; + document.Info.Description = "A full API to use your BTCPay Server"; + document.Info.TermsOfService = null; + document.Info.Contact = new NSwag.OpenApiContact + { + Name = "BTCPay Server", Email = string.Empty, Url = "https://btcpayserver.org" + }; + }; + config.AddOperationFilter(context => + { + var methodInfo = context.MethodInfo; + if (methodInfo != null) + { + return methodInfo.CustomAttributes.Any(data => + data.AttributeType == typeof(IncludeInOpenApiDocs)) || + methodInfo.DeclaringType.CustomAttributes.Any(data => + data.AttributeType == typeof(IncludeInOpenApiDocs)); + } + + return false; + }); + + config.AddSecurity("APIKey", Enumerable.Empty(), + new OpenApiSecurityScheme + { + Type = OpenApiSecuritySchemeType.ApiKey, + Name = "Authorization", + In = OpenApiSecurityApiKeyLocation.Header, + Description = + "BTCPay Server supports authenticating and authorizing users through an API Key that is generated by them. Send the API Key as a header value to Authorization with the format: token {token}. For a smoother experience, you can generate a url that redirects users to an API key creation screen." + }); + + config.OperationProcessors.Add( + new BTCPayPolicyOperationProcessor("APIKey", AuthenticationSchemes.ApiKey)); + + config.TypeMappers.Add( + new PrimitiveTypeMapper(typeof(PaymentType), s => s.Type = JsonObjectType.String)); + config.TypeMappers.Add(new PrimitiveTypeMapper(typeof(PaymentMethodId), + s => s.Type = JsonObjectType.String)); + }); + } + + public static IApplicationBuilder UseBTCPayOpenApi(this IApplicationBuilder builder) + { + return builder.UseOpenApi() + .UseReDoc(settings => settings.Path = "/docs"); + } + + + class BTCPayPolicyOperationProcessor : AspNetCoreOperationSecurityScopeProcessor + { + private readonly string _authScheme; + + public BTCPayPolicyOperationProcessor(string x, string authScheme) : base(x) + { + _authScheme = authScheme; + } + + protected override IEnumerable GetScopes(IEnumerable authorizeAttributes) + { + var result = authorizeAttributes + .Where(attribute => attribute?.AuthenticationSchemes != null && attribute.Policy != null && + attribute.AuthenticationSchemes.Equals(_authScheme, + StringComparison.InvariantCultureIgnoreCase)) + .Select(attribute => attribute.Policy); + + return result; + } + } + } +} From 0a8b303c11837f03a808f3c3b1f8306b7ddb8f9e Mon Sep 17 00:00:00 2001 From: Kukks Date: Tue, 25 Feb 2020 14:43:53 +0100 Subject: [PATCH 2/9] add label for api keys, make api keys without -, fix null exception on authorize --- BTCPayServer.Data/Data/APIKeyData.cs | 1 + .../20200225133433_AddApiKeyLabel.Designer.cs | 849 ++++++++++++++++++ .../20200225133433_AddApiKeyLabel.cs | 22 + .../ApplicationDbContextModelSnapshot.cs | 3 + .../Controllers/ManageController.APIKeys.cs | 9 +- BTCPayServer/Views/Manage/APIKeys.cshtml | 6 +- BTCPayServer/Views/Manage/AddApiKey.cshtml | 8 + .../Views/Manage/AuthorizeAPIKey.cshtml | 8 + 8 files changed, 902 insertions(+), 4 deletions(-) create mode 100644 BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.Designer.cs create mode 100644 BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.cs diff --git a/BTCPayServer.Data/Data/APIKeyData.cs b/BTCPayServer.Data/Data/APIKeyData.cs index 715d3f2ec..c538a9bd9 100644 --- a/BTCPayServer.Data/Data/APIKeyData.cs +++ b/BTCPayServer.Data/Data/APIKeyData.cs @@ -26,6 +26,7 @@ namespace BTCPayServer.Data public StoreData StoreData { get; set; } public ApplicationUser User { get; set; } + public string Label { get; set; } public string[] GetPermissions() { return Permissions?.Split(';') ?? new string[0]; } public void SetPermissions(IEnumerable permissions) diff --git a/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.Designer.cs b/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.Designer.cs new file mode 100644 index 000000000..a73d3f0bc --- /dev/null +++ b/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.Designer.cs @@ -0,0 +1,849 @@ +// +using System; +using BTCPayServer.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace BTCPayServer.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20200225133433_AddApiKeyLabel")] + partial class AddApiKeyLabel + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.1"); + + modelBuilder.Entity("BTCPayServer.Data.APIKeyData", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasMaxLength(50); + + b.Property("Label") + .HasColumnType("TEXT"); + + b.Property("Permissions") + .HasColumnType("TEXT"); + + b.Property("StoreId") + .HasColumnType("TEXT") + .HasMaxLength(50); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.Property("UserId") + .HasColumnType("TEXT") + .HasMaxLength(50); + + b.HasKey("Id"); + + b.HasIndex("StoreId"); + + b.HasIndex("UserId"); + + b.ToTable("ApiKeys"); + }); + + modelBuilder.Entity("BTCPayServer.Data.AddressInvoiceData", b => + { + b.Property("Address") + .HasColumnType("TEXT"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("InvoiceDataId") + .HasColumnType("TEXT"); + + b.HasKey("Address"); + + b.HasIndex("InvoiceDataId"); + + b.ToTable("AddressInvoices"); + }); + + modelBuilder.Entity("BTCPayServer.Data.AppData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("AppType") + .HasColumnType("TEXT"); + + b.Property("Created") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Settings") + .HasColumnType("TEXT"); + + b.Property("StoreDataId") + .HasColumnType("TEXT"); + + b.Property("TagAllInvoices") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("StoreDataId"); + + b.ToTable("Apps"); + }); + + modelBuilder.Entity("BTCPayServer.Data.ApplicationUser", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("AccessFailedCount") + .HasColumnType("INTEGER"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("TEXT"); + + b.Property("Email") + .HasColumnType("TEXT") + .HasMaxLength(256); + + b.Property("EmailConfirmed") + .HasColumnType("INTEGER"); + + b.Property("LockoutEnabled") + .HasColumnType("INTEGER"); + + b.Property("LockoutEnd") + .HasColumnType("TEXT"); + + b.Property("NormalizedEmail") + .HasColumnType("TEXT") + .HasMaxLength(256); + + b.Property("NormalizedUserName") + .HasColumnType("TEXT") + .HasMaxLength(256); + + b.Property("PasswordHash") + .HasColumnType("TEXT"); + + b.Property("PhoneNumber") + .HasColumnType("TEXT"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("INTEGER"); + + b.Property("RequiresEmailConfirmation") + .HasColumnType("INTEGER"); + + b.Property("SecurityStamp") + .HasColumnType("TEXT"); + + b.Property("TwoFactorEnabled") + .HasColumnType("INTEGER"); + + b.Property("UserName") + .HasColumnType("TEXT") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasName("UserNameIndex"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("BTCPayServer.Data.HistoricalAddressInvoiceData", b => + { + b.Property("InvoiceDataId") + .HasColumnType("TEXT"); + + b.Property("Address") + .HasColumnType("TEXT"); + + b.Property("Assigned") + .HasColumnType("TEXT"); + + b.Property("CryptoCode") + .HasColumnType("TEXT"); + + b.Property("UnAssigned") + .HasColumnType("TEXT"); + + b.HasKey("InvoiceDataId", "Address"); + + b.ToTable("HistoricalAddressInvoices"); + }); + + modelBuilder.Entity("BTCPayServer.Data.InvoiceData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Blob") + .HasColumnType("BLOB"); + + b.Property("Created") + .HasColumnType("TEXT"); + + b.Property("CustomerEmail") + .HasColumnType("TEXT"); + + b.Property("ExceptionStatus") + .HasColumnType("TEXT"); + + b.Property("ItemCode") + .HasColumnType("TEXT"); + + b.Property("OrderId") + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("TEXT"); + + b.Property("StoreDataId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("StoreDataId"); + + b.ToTable("Invoices"); + }); + + modelBuilder.Entity("BTCPayServer.Data.InvoiceEventData", b => + { + b.Property("InvoiceDataId") + .HasColumnType("TEXT"); + + b.Property("UniqueId") + .HasColumnType("TEXT"); + + b.Property("Message") + .HasColumnType("TEXT"); + + b.Property("Timestamp") + .HasColumnType("TEXT"); + + b.HasKey("InvoiceDataId", "UniqueId"); + + b.ToTable("InvoiceEvents"); + }); + + modelBuilder.Entity("BTCPayServer.Data.PairedSINData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Label") + .HasColumnType("TEXT"); + + b.Property("PairingTime") + .HasColumnType("TEXT"); + + b.Property("SIN") + .HasColumnType("TEXT"); + + b.Property("StoreDataId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("SIN"); + + b.HasIndex("StoreDataId"); + + b.ToTable("PairedSINData"); + }); + + modelBuilder.Entity("BTCPayServer.Data.PairingCodeData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("DateCreated") + .HasColumnType("TEXT"); + + b.Property("Expiration") + .HasColumnType("TEXT"); + + b.Property("Facade") + .HasColumnType("TEXT"); + + b.Property("Label") + .HasColumnType("TEXT"); + + b.Property("SIN") + .HasColumnType("TEXT"); + + b.Property("StoreDataId") + .HasColumnType("TEXT"); + + b.Property("TokenValue") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("PairingCodes"); + }); + + modelBuilder.Entity("BTCPayServer.Data.PaymentData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Accounted") + .HasColumnType("INTEGER"); + + b.Property("Blob") + .HasColumnType("BLOB"); + + b.Property("InvoiceDataId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("InvoiceDataId"); + + b.ToTable("Payments"); + }); + + modelBuilder.Entity("BTCPayServer.Data.PaymentRequestData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Blob") + .HasColumnType("BLOB"); + + b.Property("Created") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT") + .HasDefaultValue(new DateTimeOffset(new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0))); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.Property("StoreDataId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Status"); + + b.HasIndex("StoreDataId"); + + b.ToTable("PaymentRequests"); + }); + + modelBuilder.Entity("BTCPayServer.Data.PendingInvoiceData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("PendingInvoices"); + }); + + modelBuilder.Entity("BTCPayServer.Data.RefundAddressesData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Blob") + .HasColumnType("BLOB"); + + b.Property("InvoiceDataId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("InvoiceDataId"); + + b.ToTable("RefundAddresses"); + }); + + modelBuilder.Entity("BTCPayServer.Data.SettingData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Value") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Settings"); + }); + + modelBuilder.Entity("BTCPayServer.Data.StoreData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("DefaultCrypto") + .HasColumnType("TEXT"); + + b.Property("DerivationStrategies") + .HasColumnType("TEXT"); + + b.Property("DerivationStrategy") + .HasColumnType("TEXT"); + + b.Property("SpeedPolicy") + .HasColumnType("INTEGER"); + + b.Property("StoreBlob") + .HasColumnType("BLOB"); + + b.Property("StoreCertificate") + .HasColumnType("BLOB"); + + b.Property("StoreName") + .HasColumnType("TEXT"); + + b.Property("StoreWebsite") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Stores"); + }); + + modelBuilder.Entity("BTCPayServer.Data.StoredFile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("ApplicationUserId") + .HasColumnType("TEXT"); + + b.Property("FileName") + .HasColumnType("TEXT"); + + b.Property("StorageFileName") + .HasColumnType("TEXT"); + + b.Property("Timestamp") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationUserId"); + + b.ToTable("Files"); + }); + + modelBuilder.Entity("BTCPayServer.Data.U2FDevice", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ApplicationUserId") + .HasColumnType("TEXT"); + + b.Property("AttestationCert") + .IsRequired() + .HasColumnType("BLOB"); + + b.Property("Counter") + .HasColumnType("INTEGER"); + + b.Property("KeyHandle") + .IsRequired() + .HasColumnType("BLOB"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("PublicKey") + .IsRequired() + .HasColumnType("BLOB"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationUserId"); + + b.ToTable("U2FDevices"); + }); + + modelBuilder.Entity("BTCPayServer.Data.UserStore", b => + { + b.Property("ApplicationUserId") + .HasColumnType("TEXT"); + + b.Property("StoreDataId") + .HasColumnType("TEXT"); + + b.Property("Role") + .HasColumnType("TEXT"); + + b.HasKey("ApplicationUserId", "StoreDataId"); + + b.HasIndex("StoreDataId"); + + b.ToTable("UserStore"); + }); + + modelBuilder.Entity("BTCPayServer.Data.WalletData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Blob") + .HasColumnType("BLOB"); + + b.HasKey("Id"); + + b.ToTable("Wallets"); + }); + + modelBuilder.Entity("BTCPayServer.Data.WalletTransactionData", b => + { + b.Property("WalletDataId") + .HasColumnType("TEXT"); + + b.Property("TransactionId") + .HasColumnType("TEXT"); + + b.Property("Blob") + .HasColumnType("BLOB"); + + b.Property("Labels") + .HasColumnType("TEXT"); + + b.HasKey("WalletDataId", "TransactionId"); + + b.ToTable("WalletTransactions"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT") + .HasMaxLength(256); + + b.Property("NormalizedName") + .HasColumnType("TEXT") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ClaimType") + .HasColumnType("TEXT"); + + b.Property("ClaimValue") + .HasColumnType("TEXT"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ClaimType") + .HasColumnType("TEXT"); + + b.Property("ClaimValue") + .HasColumnType("TEXT"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("TEXT"); + + b.Property("ProviderKey") + .HasColumnType("TEXT"); + + b.Property("ProviderDisplayName") + .HasColumnType("TEXT"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("TEXT"); + + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("TEXT"); + + b.Property("LoginProvider") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Value") + .HasColumnType("TEXT"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("BTCPayServer.Data.APIKeyData", b => + { + b.HasOne("BTCPayServer.Data.StoreData", "StoreData") + .WithMany("APIKeys") + .HasForeignKey("StoreId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("BTCPayServer.Data.ApplicationUser", "User") + .WithMany("APIKeys") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BTCPayServer.Data.AddressInvoiceData", b => + { + b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") + .WithMany("AddressInvoices") + .HasForeignKey("InvoiceDataId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BTCPayServer.Data.AppData", b => + { + b.HasOne("BTCPayServer.Data.StoreData", "StoreData") + .WithMany("Apps") + .HasForeignKey("StoreDataId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BTCPayServer.Data.HistoricalAddressInvoiceData", b => + { + b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") + .WithMany("HistoricalAddressInvoices") + .HasForeignKey("InvoiceDataId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BTCPayServer.Data.InvoiceData", b => + { + b.HasOne("BTCPayServer.Data.StoreData", "StoreData") + .WithMany("Invoices") + .HasForeignKey("StoreDataId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BTCPayServer.Data.InvoiceEventData", b => + { + b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") + .WithMany("Events") + .HasForeignKey("InvoiceDataId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BTCPayServer.Data.PairedSINData", b => + { + b.HasOne("BTCPayServer.Data.StoreData", "StoreData") + .WithMany("PairedSINs") + .HasForeignKey("StoreDataId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BTCPayServer.Data.PaymentData", b => + { + b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") + .WithMany("Payments") + .HasForeignKey("InvoiceDataId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BTCPayServer.Data.PaymentRequestData", b => + { + b.HasOne("BTCPayServer.Data.StoreData", "StoreData") + .WithMany("PaymentRequests") + .HasForeignKey("StoreDataId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BTCPayServer.Data.PendingInvoiceData", b => + { + b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") + .WithMany("PendingInvoices") + .HasForeignKey("Id") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BTCPayServer.Data.RefundAddressesData", b => + { + b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") + .WithMany("RefundAddresses") + .HasForeignKey("InvoiceDataId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BTCPayServer.Data.StoredFile", b => + { + b.HasOne("BTCPayServer.Data.ApplicationUser", "ApplicationUser") + .WithMany("StoredFiles") + .HasForeignKey("ApplicationUserId"); + }); + + modelBuilder.Entity("BTCPayServer.Data.U2FDevice", b => + { + b.HasOne("BTCPayServer.Data.ApplicationUser", "ApplicationUser") + .WithMany("U2FDevices") + .HasForeignKey("ApplicationUserId"); + }); + + modelBuilder.Entity("BTCPayServer.Data.UserStore", b => + { + b.HasOne("BTCPayServer.Data.ApplicationUser", "ApplicationUser") + .WithMany("UserStores") + .HasForeignKey("ApplicationUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BTCPayServer.Data.StoreData", "StoreData") + .WithMany("UserStores") + .HasForeignKey("StoreDataId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BTCPayServer.Data.WalletTransactionData", b => + { + b.HasOne("BTCPayServer.Data.WalletData", "WalletData") + .WithMany("WalletTransactions") + .HasForeignKey("WalletDataId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("BTCPayServer.Data.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("BTCPayServer.Data.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BTCPayServer.Data.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("BTCPayServer.Data.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.cs b/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.cs new file mode 100644 index 000000000..6db60f5c0 --- /dev/null +++ b/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace BTCPayServer.Migrations +{ + public partial class AddApiKeyLabel : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Label", + table: "ApiKeys", + nullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Label", + table: "ApiKeys"); + } + } +} diff --git a/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs b/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs index b2a26241a..3ee8f2a07 100644 --- a/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -22,6 +22,9 @@ namespace BTCPayServer.Migrations .HasColumnType("TEXT") .HasMaxLength(50); + b.Property("Label") + .HasColumnType("TEXT"); + b.Property("Permissions") .HasColumnType("TEXT"); diff --git a/BTCPayServer/Controllers/ManageController.APIKeys.cs b/BTCPayServer/Controllers/ManageController.APIKeys.cs index 03c78defe..9be2bec0d 100644 --- a/BTCPayServer/Controllers/ManageController.APIKeys.cs +++ b/BTCPayServer/Controllers/ManageController.APIKeys.cs @@ -85,6 +85,7 @@ namespace BTCPayServer.Controllers var vm = await SetViewModelValues(new AuthorizeApiKeysViewModel() { + Label = applicationName, ServerManagementPermission = permissions.Contains(APIKeyConstants.Permissions.ServerManagement), StoreManagementPermission = permissions.Contains(APIKeyConstants.Permissions.StoreManagement), PermissionsFormatted = permissions, @@ -225,7 +226,10 @@ namespace BTCPayServer.Controllers { var key = new APIKeyData() { - Id = Guid.NewGuid().ToString(), Type = APIKeyType.Permanent, UserId = _userManager.GetUserId(User) + Id = Guid.NewGuid().ToString().Replace("-", string.Empty), + Type = APIKeyType.Permanent, + UserId = _userManager.GetUserId(User), + Label = viewModel.Label }; key.SetPermissions(GetPermissionsFromViewModel(viewModel)); await _apiKeyRepository.CreateKey(key); @@ -262,6 +266,7 @@ namespace BTCPayServer.Controllers public class AddApiKeyViewModel { + public string Label { get; set; } public StoreData[] Stores { get; set; } public ApiKeyStoreMode StoreMode { get; set; } public List SpecificStores { get; set; } = new List(); @@ -288,7 +293,7 @@ namespace BTCPayServer.Controllers { get { - return Permissions?.Split(";", StringSplitOptions.RemoveEmptyEntries); + return Permissions?.Split(";", StringSplitOptions.RemoveEmptyEntries)?? Array.Empty(); } set { diff --git a/BTCPayServer/Views/Manage/APIKeys.cshtml b/BTCPayServer/Views/Manage/APIKeys.cshtml index 23db9ac73..5c6656ef5 100644 --- a/BTCPayServer/Views/Manage/APIKeys.cshtml +++ b/BTCPayServer/Views/Manage/APIKeys.cshtml @@ -8,8 +8,9 @@ - - + + + @@ -17,6 +18,7 @@ @foreach (var keyData in Model.ApiKeyDatas) { + - } - From 95b9884af7c249307773f8f0bf2ffde9cbed4e34 Mon Sep 17 00:00:00 2001 From: Kukks Date: Wed, 26 Feb 2020 09:41:24 +0100 Subject: [PATCH 7/9] Revert "consolidate migrations" This reverts commit 501c3241b543c5941ec9e5d7ecc14cf1edf9661f. --- .../20200119130108_ExtendApiKeys.cs | 10 - .../20200225133433_AddApiKeyLabel.Designer.cs | 849 ++++++++++++++++++ .../20200225133433_AddApiKeyLabel.cs | 22 + 3 files changed, 871 insertions(+), 10 deletions(-) create mode 100644 BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.Designer.cs create mode 100644 BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.cs diff --git a/BTCPayServer.Data/Migrations/20200119130108_ExtendApiKeys.cs b/BTCPayServer.Data/Migrations/20200119130108_ExtendApiKeys.cs index 05fa236cf..9eeb5b83c 100644 --- a/BTCPayServer.Data/Migrations/20200119130108_ExtendApiKeys.cs +++ b/BTCPayServer.Data/Migrations/20200119130108_ExtendApiKeys.cs @@ -26,11 +26,6 @@ namespace BTCPayServer.Migrations table: "ApiKeys", maxLength: 50, nullable: true); - - migrationBuilder.AddColumn( - name: "Label", - table: "ApiKeys", - nullable: true); migrationBuilder.CreateIndex( name: "IX_ApiKeys_UserId", @@ -73,11 +68,6 @@ namespace BTCPayServer.Migrations migrationBuilder.DropColumn( name: "UserId", table: "ApiKeys"); - - migrationBuilder.DropColumn( - name: "Label", - table: "ApiKeys"); - } } } diff --git a/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.Designer.cs b/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.Designer.cs new file mode 100644 index 000000000..a73d3f0bc --- /dev/null +++ b/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.Designer.cs @@ -0,0 +1,849 @@ +// +using System; +using BTCPayServer.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace BTCPayServer.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20200225133433_AddApiKeyLabel")] + partial class AddApiKeyLabel + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.1"); + + modelBuilder.Entity("BTCPayServer.Data.APIKeyData", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasMaxLength(50); + + b.Property("Label") + .HasColumnType("TEXT"); + + b.Property("Permissions") + .HasColumnType("TEXT"); + + b.Property("StoreId") + .HasColumnType("TEXT") + .HasMaxLength(50); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.Property("UserId") + .HasColumnType("TEXT") + .HasMaxLength(50); + + b.HasKey("Id"); + + b.HasIndex("StoreId"); + + b.HasIndex("UserId"); + + b.ToTable("ApiKeys"); + }); + + modelBuilder.Entity("BTCPayServer.Data.AddressInvoiceData", b => + { + b.Property("Address") + .HasColumnType("TEXT"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("InvoiceDataId") + .HasColumnType("TEXT"); + + b.HasKey("Address"); + + b.HasIndex("InvoiceDataId"); + + b.ToTable("AddressInvoices"); + }); + + modelBuilder.Entity("BTCPayServer.Data.AppData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("AppType") + .HasColumnType("TEXT"); + + b.Property("Created") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Settings") + .HasColumnType("TEXT"); + + b.Property("StoreDataId") + .HasColumnType("TEXT"); + + b.Property("TagAllInvoices") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("StoreDataId"); + + b.ToTable("Apps"); + }); + + modelBuilder.Entity("BTCPayServer.Data.ApplicationUser", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("AccessFailedCount") + .HasColumnType("INTEGER"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("TEXT"); + + b.Property("Email") + .HasColumnType("TEXT") + .HasMaxLength(256); + + b.Property("EmailConfirmed") + .HasColumnType("INTEGER"); + + b.Property("LockoutEnabled") + .HasColumnType("INTEGER"); + + b.Property("LockoutEnd") + .HasColumnType("TEXT"); + + b.Property("NormalizedEmail") + .HasColumnType("TEXT") + .HasMaxLength(256); + + b.Property("NormalizedUserName") + .HasColumnType("TEXT") + .HasMaxLength(256); + + b.Property("PasswordHash") + .HasColumnType("TEXT"); + + b.Property("PhoneNumber") + .HasColumnType("TEXT"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("INTEGER"); + + b.Property("RequiresEmailConfirmation") + .HasColumnType("INTEGER"); + + b.Property("SecurityStamp") + .HasColumnType("TEXT"); + + b.Property("TwoFactorEnabled") + .HasColumnType("INTEGER"); + + b.Property("UserName") + .HasColumnType("TEXT") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasName("UserNameIndex"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("BTCPayServer.Data.HistoricalAddressInvoiceData", b => + { + b.Property("InvoiceDataId") + .HasColumnType("TEXT"); + + b.Property("Address") + .HasColumnType("TEXT"); + + b.Property("Assigned") + .HasColumnType("TEXT"); + + b.Property("CryptoCode") + .HasColumnType("TEXT"); + + b.Property("UnAssigned") + .HasColumnType("TEXT"); + + b.HasKey("InvoiceDataId", "Address"); + + b.ToTable("HistoricalAddressInvoices"); + }); + + modelBuilder.Entity("BTCPayServer.Data.InvoiceData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Blob") + .HasColumnType("BLOB"); + + b.Property("Created") + .HasColumnType("TEXT"); + + b.Property("CustomerEmail") + .HasColumnType("TEXT"); + + b.Property("ExceptionStatus") + .HasColumnType("TEXT"); + + b.Property("ItemCode") + .HasColumnType("TEXT"); + + b.Property("OrderId") + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("TEXT"); + + b.Property("StoreDataId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("StoreDataId"); + + b.ToTable("Invoices"); + }); + + modelBuilder.Entity("BTCPayServer.Data.InvoiceEventData", b => + { + b.Property("InvoiceDataId") + .HasColumnType("TEXT"); + + b.Property("UniqueId") + .HasColumnType("TEXT"); + + b.Property("Message") + .HasColumnType("TEXT"); + + b.Property("Timestamp") + .HasColumnType("TEXT"); + + b.HasKey("InvoiceDataId", "UniqueId"); + + b.ToTable("InvoiceEvents"); + }); + + modelBuilder.Entity("BTCPayServer.Data.PairedSINData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Label") + .HasColumnType("TEXT"); + + b.Property("PairingTime") + .HasColumnType("TEXT"); + + b.Property("SIN") + .HasColumnType("TEXT"); + + b.Property("StoreDataId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("SIN"); + + b.HasIndex("StoreDataId"); + + b.ToTable("PairedSINData"); + }); + + modelBuilder.Entity("BTCPayServer.Data.PairingCodeData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("DateCreated") + .HasColumnType("TEXT"); + + b.Property("Expiration") + .HasColumnType("TEXT"); + + b.Property("Facade") + .HasColumnType("TEXT"); + + b.Property("Label") + .HasColumnType("TEXT"); + + b.Property("SIN") + .HasColumnType("TEXT"); + + b.Property("StoreDataId") + .HasColumnType("TEXT"); + + b.Property("TokenValue") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("PairingCodes"); + }); + + modelBuilder.Entity("BTCPayServer.Data.PaymentData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Accounted") + .HasColumnType("INTEGER"); + + b.Property("Blob") + .HasColumnType("BLOB"); + + b.Property("InvoiceDataId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("InvoiceDataId"); + + b.ToTable("Payments"); + }); + + modelBuilder.Entity("BTCPayServer.Data.PaymentRequestData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Blob") + .HasColumnType("BLOB"); + + b.Property("Created") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT") + .HasDefaultValue(new DateTimeOffset(new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0))); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.Property("StoreDataId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Status"); + + b.HasIndex("StoreDataId"); + + b.ToTable("PaymentRequests"); + }); + + modelBuilder.Entity("BTCPayServer.Data.PendingInvoiceData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("PendingInvoices"); + }); + + modelBuilder.Entity("BTCPayServer.Data.RefundAddressesData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Blob") + .HasColumnType("BLOB"); + + b.Property("InvoiceDataId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("InvoiceDataId"); + + b.ToTable("RefundAddresses"); + }); + + modelBuilder.Entity("BTCPayServer.Data.SettingData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Value") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Settings"); + }); + + modelBuilder.Entity("BTCPayServer.Data.StoreData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("DefaultCrypto") + .HasColumnType("TEXT"); + + b.Property("DerivationStrategies") + .HasColumnType("TEXT"); + + b.Property("DerivationStrategy") + .HasColumnType("TEXT"); + + b.Property("SpeedPolicy") + .HasColumnType("INTEGER"); + + b.Property("StoreBlob") + .HasColumnType("BLOB"); + + b.Property("StoreCertificate") + .HasColumnType("BLOB"); + + b.Property("StoreName") + .HasColumnType("TEXT"); + + b.Property("StoreWebsite") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Stores"); + }); + + modelBuilder.Entity("BTCPayServer.Data.StoredFile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("ApplicationUserId") + .HasColumnType("TEXT"); + + b.Property("FileName") + .HasColumnType("TEXT"); + + b.Property("StorageFileName") + .HasColumnType("TEXT"); + + b.Property("Timestamp") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationUserId"); + + b.ToTable("Files"); + }); + + modelBuilder.Entity("BTCPayServer.Data.U2FDevice", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ApplicationUserId") + .HasColumnType("TEXT"); + + b.Property("AttestationCert") + .IsRequired() + .HasColumnType("BLOB"); + + b.Property("Counter") + .HasColumnType("INTEGER"); + + b.Property("KeyHandle") + .IsRequired() + .HasColumnType("BLOB"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("PublicKey") + .IsRequired() + .HasColumnType("BLOB"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationUserId"); + + b.ToTable("U2FDevices"); + }); + + modelBuilder.Entity("BTCPayServer.Data.UserStore", b => + { + b.Property("ApplicationUserId") + .HasColumnType("TEXT"); + + b.Property("StoreDataId") + .HasColumnType("TEXT"); + + b.Property("Role") + .HasColumnType("TEXT"); + + b.HasKey("ApplicationUserId", "StoreDataId"); + + b.HasIndex("StoreDataId"); + + b.ToTable("UserStore"); + }); + + modelBuilder.Entity("BTCPayServer.Data.WalletData", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Blob") + .HasColumnType("BLOB"); + + b.HasKey("Id"); + + b.ToTable("Wallets"); + }); + + modelBuilder.Entity("BTCPayServer.Data.WalletTransactionData", b => + { + b.Property("WalletDataId") + .HasColumnType("TEXT"); + + b.Property("TransactionId") + .HasColumnType("TEXT"); + + b.Property("Blob") + .HasColumnType("BLOB"); + + b.Property("Labels") + .HasColumnType("TEXT"); + + b.HasKey("WalletDataId", "TransactionId"); + + b.ToTable("WalletTransactions"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT") + .HasMaxLength(256); + + b.Property("NormalizedName") + .HasColumnType("TEXT") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ClaimType") + .HasColumnType("TEXT"); + + b.Property("ClaimValue") + .HasColumnType("TEXT"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ClaimType") + .HasColumnType("TEXT"); + + b.Property("ClaimValue") + .HasColumnType("TEXT"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("TEXT"); + + b.Property("ProviderKey") + .HasColumnType("TEXT"); + + b.Property("ProviderDisplayName") + .HasColumnType("TEXT"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("TEXT"); + + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("TEXT"); + + b.Property("LoginProvider") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Value") + .HasColumnType("TEXT"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("BTCPayServer.Data.APIKeyData", b => + { + b.HasOne("BTCPayServer.Data.StoreData", "StoreData") + .WithMany("APIKeys") + .HasForeignKey("StoreId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("BTCPayServer.Data.ApplicationUser", "User") + .WithMany("APIKeys") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BTCPayServer.Data.AddressInvoiceData", b => + { + b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") + .WithMany("AddressInvoices") + .HasForeignKey("InvoiceDataId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BTCPayServer.Data.AppData", b => + { + b.HasOne("BTCPayServer.Data.StoreData", "StoreData") + .WithMany("Apps") + .HasForeignKey("StoreDataId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BTCPayServer.Data.HistoricalAddressInvoiceData", b => + { + b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") + .WithMany("HistoricalAddressInvoices") + .HasForeignKey("InvoiceDataId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BTCPayServer.Data.InvoiceData", b => + { + b.HasOne("BTCPayServer.Data.StoreData", "StoreData") + .WithMany("Invoices") + .HasForeignKey("StoreDataId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BTCPayServer.Data.InvoiceEventData", b => + { + b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") + .WithMany("Events") + .HasForeignKey("InvoiceDataId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BTCPayServer.Data.PairedSINData", b => + { + b.HasOne("BTCPayServer.Data.StoreData", "StoreData") + .WithMany("PairedSINs") + .HasForeignKey("StoreDataId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BTCPayServer.Data.PaymentData", b => + { + b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") + .WithMany("Payments") + .HasForeignKey("InvoiceDataId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BTCPayServer.Data.PaymentRequestData", b => + { + b.HasOne("BTCPayServer.Data.StoreData", "StoreData") + .WithMany("PaymentRequests") + .HasForeignKey("StoreDataId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BTCPayServer.Data.PendingInvoiceData", b => + { + b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") + .WithMany("PendingInvoices") + .HasForeignKey("Id") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BTCPayServer.Data.RefundAddressesData", b => + { + b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") + .WithMany("RefundAddresses") + .HasForeignKey("InvoiceDataId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BTCPayServer.Data.StoredFile", b => + { + b.HasOne("BTCPayServer.Data.ApplicationUser", "ApplicationUser") + .WithMany("StoredFiles") + .HasForeignKey("ApplicationUserId"); + }); + + modelBuilder.Entity("BTCPayServer.Data.U2FDevice", b => + { + b.HasOne("BTCPayServer.Data.ApplicationUser", "ApplicationUser") + .WithMany("U2FDevices") + .HasForeignKey("ApplicationUserId"); + }); + + modelBuilder.Entity("BTCPayServer.Data.UserStore", b => + { + b.HasOne("BTCPayServer.Data.ApplicationUser", "ApplicationUser") + .WithMany("UserStores") + .HasForeignKey("ApplicationUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BTCPayServer.Data.StoreData", "StoreData") + .WithMany("UserStores") + .HasForeignKey("StoreDataId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BTCPayServer.Data.WalletTransactionData", b => + { + b.HasOne("BTCPayServer.Data.WalletData", "WalletData") + .WithMany("WalletTransactions") + .HasForeignKey("WalletDataId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("BTCPayServer.Data.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("BTCPayServer.Data.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BTCPayServer.Data.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("BTCPayServer.Data.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.cs b/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.cs new file mode 100644 index 000000000..6db60f5c0 --- /dev/null +++ b/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace BTCPayServer.Migrations +{ + public partial class AddApiKeyLabel : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Label", + table: "ApiKeys", + nullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Label", + table: "ApiKeys"); + } + } +} From 48c21baee59aaeaa7e5083d5794b9acb6d57ba3b Mon Sep 17 00:00:00 2001 From: Kukks Date: Wed, 26 Feb 2020 09:53:58 +0100 Subject: [PATCH 8/9] add migration attributes and remove designer --- .../20200224134444_Remove_OpenIddict.cs | 4 + .../20200225133433_AddApiKeyLabel.Designer.cs | 849 ------------------ .../20200225133433_AddApiKeyLabel.cs | 7 +- 3 files changed, 10 insertions(+), 850 deletions(-) delete mode 100644 BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.Designer.cs diff --git a/BTCPayServer.Data/Migrations/20200224134444_Remove_OpenIddict.cs b/BTCPayServer.Data/Migrations/20200224134444_Remove_OpenIddict.cs index 78f323529..d356af760 100644 --- a/BTCPayServer.Data/Migrations/20200224134444_Remove_OpenIddict.cs +++ b/BTCPayServer.Data/Migrations/20200224134444_Remove_OpenIddict.cs @@ -1,8 +1,12 @@ using System; +using BTCPayServer.Data; +using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; namespace BTCPayServer.Migrations { + [DbContext(typeof(ApplicationDbContext))] + [Migration("20200224134444_Remove_OpenIddict")] public partial class Remove_OpenIddict : Migration { protected override void Up(MigrationBuilder migrationBuilder) diff --git a/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.Designer.cs b/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.Designer.cs deleted file mode 100644 index a73d3f0bc..000000000 --- a/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.Designer.cs +++ /dev/null @@ -1,849 +0,0 @@ -// -using System; -using BTCPayServer.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -namespace BTCPayServer.Migrations -{ - [DbContext(typeof(ApplicationDbContext))] - [Migration("20200225133433_AddApiKeyLabel")] - partial class AddApiKeyLabel - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "3.1.1"); - - modelBuilder.Entity("BTCPayServer.Data.APIKeyData", b => - { - b.Property("Id") - .HasColumnType("TEXT") - .HasMaxLength(50); - - b.Property("Label") - .HasColumnType("TEXT"); - - b.Property("Permissions") - .HasColumnType("TEXT"); - - b.Property("StoreId") - .HasColumnType("TEXT") - .HasMaxLength(50); - - b.Property("Type") - .HasColumnType("INTEGER"); - - b.Property("UserId") - .HasColumnType("TEXT") - .HasMaxLength(50); - - b.HasKey("Id"); - - b.HasIndex("StoreId"); - - b.HasIndex("UserId"); - - b.ToTable("ApiKeys"); - }); - - modelBuilder.Entity("BTCPayServer.Data.AddressInvoiceData", b => - { - b.Property("Address") - .HasColumnType("TEXT"); - - b.Property("CreatedTime") - .HasColumnType("TEXT"); - - b.Property("InvoiceDataId") - .HasColumnType("TEXT"); - - b.HasKey("Address"); - - b.HasIndex("InvoiceDataId"); - - b.ToTable("AddressInvoices"); - }); - - modelBuilder.Entity("BTCPayServer.Data.AppData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("AppType") - .HasColumnType("TEXT"); - - b.Property("Created") - .HasColumnType("TEXT"); - - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("Settings") - .HasColumnType("TEXT"); - - b.Property("StoreDataId") - .HasColumnType("TEXT"); - - b.Property("TagAllInvoices") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.HasIndex("StoreDataId"); - - b.ToTable("Apps"); - }); - - modelBuilder.Entity("BTCPayServer.Data.ApplicationUser", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("AccessFailedCount") - .HasColumnType("INTEGER"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("TEXT"); - - b.Property("Email") - .HasColumnType("TEXT") - .HasMaxLength(256); - - b.Property("EmailConfirmed") - .HasColumnType("INTEGER"); - - b.Property("LockoutEnabled") - .HasColumnType("INTEGER"); - - b.Property("LockoutEnd") - .HasColumnType("TEXT"); - - b.Property("NormalizedEmail") - .HasColumnType("TEXT") - .HasMaxLength(256); - - b.Property("NormalizedUserName") - .HasColumnType("TEXT") - .HasMaxLength(256); - - b.Property("PasswordHash") - .HasColumnType("TEXT"); - - b.Property("PhoneNumber") - .HasColumnType("TEXT"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("INTEGER"); - - b.Property("RequiresEmailConfirmation") - .HasColumnType("INTEGER"); - - b.Property("SecurityStamp") - .HasColumnType("TEXT"); - - b.Property("TwoFactorEnabled") - .HasColumnType("INTEGER"); - - b.Property("UserName") - .HasColumnType("TEXT") - .HasMaxLength(256); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasName("UserNameIndex"); - - b.ToTable("AspNetUsers"); - }); - - modelBuilder.Entity("BTCPayServer.Data.HistoricalAddressInvoiceData", b => - { - b.Property("InvoiceDataId") - .HasColumnType("TEXT"); - - b.Property("Address") - .HasColumnType("TEXT"); - - b.Property("Assigned") - .HasColumnType("TEXT"); - - b.Property("CryptoCode") - .HasColumnType("TEXT"); - - b.Property("UnAssigned") - .HasColumnType("TEXT"); - - b.HasKey("InvoiceDataId", "Address"); - - b.ToTable("HistoricalAddressInvoices"); - }); - - modelBuilder.Entity("BTCPayServer.Data.InvoiceData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Blob") - .HasColumnType("BLOB"); - - b.Property("Created") - .HasColumnType("TEXT"); - - b.Property("CustomerEmail") - .HasColumnType("TEXT"); - - b.Property("ExceptionStatus") - .HasColumnType("TEXT"); - - b.Property("ItemCode") - .HasColumnType("TEXT"); - - b.Property("OrderId") - .HasColumnType("TEXT"); - - b.Property("Status") - .HasColumnType("TEXT"); - - b.Property("StoreDataId") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("StoreDataId"); - - b.ToTable("Invoices"); - }); - - modelBuilder.Entity("BTCPayServer.Data.InvoiceEventData", b => - { - b.Property("InvoiceDataId") - .HasColumnType("TEXT"); - - b.Property("UniqueId") - .HasColumnType("TEXT"); - - b.Property("Message") - .HasColumnType("TEXT"); - - b.Property("Timestamp") - .HasColumnType("TEXT"); - - b.HasKey("InvoiceDataId", "UniqueId"); - - b.ToTable("InvoiceEvents"); - }); - - modelBuilder.Entity("BTCPayServer.Data.PairedSINData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Label") - .HasColumnType("TEXT"); - - b.Property("PairingTime") - .HasColumnType("TEXT"); - - b.Property("SIN") - .HasColumnType("TEXT"); - - b.Property("StoreDataId") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("SIN"); - - b.HasIndex("StoreDataId"); - - b.ToTable("PairedSINData"); - }); - - modelBuilder.Entity("BTCPayServer.Data.PairingCodeData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("DateCreated") - .HasColumnType("TEXT"); - - b.Property("Expiration") - .HasColumnType("TEXT"); - - b.Property("Facade") - .HasColumnType("TEXT"); - - b.Property("Label") - .HasColumnType("TEXT"); - - b.Property("SIN") - .HasColumnType("TEXT"); - - b.Property("StoreDataId") - .HasColumnType("TEXT"); - - b.Property("TokenValue") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("PairingCodes"); - }); - - modelBuilder.Entity("BTCPayServer.Data.PaymentData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Accounted") - .HasColumnType("INTEGER"); - - b.Property("Blob") - .HasColumnType("BLOB"); - - b.Property("InvoiceDataId") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("InvoiceDataId"); - - b.ToTable("Payments"); - }); - - modelBuilder.Entity("BTCPayServer.Data.PaymentRequestData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Blob") - .HasColumnType("BLOB"); - - b.Property("Created") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT") - .HasDefaultValue(new DateTimeOffset(new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0))); - - b.Property("Status") - .HasColumnType("INTEGER"); - - b.Property("StoreDataId") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("Status"); - - b.HasIndex("StoreDataId"); - - b.ToTable("PaymentRequests"); - }); - - modelBuilder.Entity("BTCPayServer.Data.PendingInvoiceData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("PendingInvoices"); - }); - - modelBuilder.Entity("BTCPayServer.Data.RefundAddressesData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Blob") - .HasColumnType("BLOB"); - - b.Property("InvoiceDataId") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("InvoiceDataId"); - - b.ToTable("RefundAddresses"); - }); - - modelBuilder.Entity("BTCPayServer.Data.SettingData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Value") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Settings"); - }); - - modelBuilder.Entity("BTCPayServer.Data.StoreData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("DefaultCrypto") - .HasColumnType("TEXT"); - - b.Property("DerivationStrategies") - .HasColumnType("TEXT"); - - b.Property("DerivationStrategy") - .HasColumnType("TEXT"); - - b.Property("SpeedPolicy") - .HasColumnType("INTEGER"); - - b.Property("StoreBlob") - .HasColumnType("BLOB"); - - b.Property("StoreCertificate") - .HasColumnType("BLOB"); - - b.Property("StoreName") - .HasColumnType("TEXT"); - - b.Property("StoreWebsite") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Stores"); - }); - - modelBuilder.Entity("BTCPayServer.Data.StoredFile", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("ApplicationUserId") - .HasColumnType("TEXT"); - - b.Property("FileName") - .HasColumnType("TEXT"); - - b.Property("StorageFileName") - .HasColumnType("TEXT"); - - b.Property("Timestamp") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("ApplicationUserId"); - - b.ToTable("Files"); - }); - - modelBuilder.Entity("BTCPayServer.Data.U2FDevice", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("ApplicationUserId") - .HasColumnType("TEXT"); - - b.Property("AttestationCert") - .IsRequired() - .HasColumnType("BLOB"); - - b.Property("Counter") - .HasColumnType("INTEGER"); - - b.Property("KeyHandle") - .IsRequired() - .HasColumnType("BLOB"); - - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("PublicKey") - .IsRequired() - .HasColumnType("BLOB"); - - b.HasKey("Id"); - - b.HasIndex("ApplicationUserId"); - - b.ToTable("U2FDevices"); - }); - - modelBuilder.Entity("BTCPayServer.Data.UserStore", b => - { - b.Property("ApplicationUserId") - .HasColumnType("TEXT"); - - b.Property("StoreDataId") - .HasColumnType("TEXT"); - - b.Property("Role") - .HasColumnType("TEXT"); - - b.HasKey("ApplicationUserId", "StoreDataId"); - - b.HasIndex("StoreDataId"); - - b.ToTable("UserStore"); - }); - - modelBuilder.Entity("BTCPayServer.Data.WalletData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Blob") - .HasColumnType("BLOB"); - - b.HasKey("Id"); - - b.ToTable("Wallets"); - }); - - modelBuilder.Entity("BTCPayServer.Data.WalletTransactionData", b => - { - b.Property("WalletDataId") - .HasColumnType("TEXT"); - - b.Property("TransactionId") - .HasColumnType("TEXT"); - - b.Property("Blob") - .HasColumnType("BLOB"); - - b.Property("Labels") - .HasColumnType("TEXT"); - - b.HasKey("WalletDataId", "TransactionId"); - - b.ToTable("WalletTransactions"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("TEXT"); - - b.Property("Name") - .HasColumnType("TEXT") - .HasMaxLength(256); - - b.Property("NormalizedName") - .HasColumnType("TEXT") - .HasMaxLength(256); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasName("RoleNameIndex"); - - b.ToTable("AspNetRoles"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("ClaimType") - .HasColumnType("TEXT"); - - b.Property("ClaimValue") - .HasColumnType("TEXT"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("ClaimType") - .HasColumnType("TEXT"); - - b.Property("ClaimValue") - .HasColumnType("TEXT"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("TEXT"); - - b.Property("ProviderKey") - .HasColumnType("TEXT"); - - b.Property("ProviderDisplayName") - .HasColumnType("TEXT"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("TEXT"); - - b.Property("RoleId") - .HasColumnType("TEXT"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("TEXT"); - - b.Property("LoginProvider") - .HasColumnType("TEXT"); - - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("Value") - .HasColumnType("TEXT"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens"); - }); - - modelBuilder.Entity("BTCPayServer.Data.APIKeyData", b => - { - b.HasOne("BTCPayServer.Data.StoreData", "StoreData") - .WithMany("APIKeys") - .HasForeignKey("StoreId") - .OnDelete(DeleteBehavior.Cascade); - - b.HasOne("BTCPayServer.Data.ApplicationUser", "User") - .WithMany("APIKeys") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("BTCPayServer.Data.AddressInvoiceData", b => - { - b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") - .WithMany("AddressInvoices") - .HasForeignKey("InvoiceDataId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("BTCPayServer.Data.AppData", b => - { - b.HasOne("BTCPayServer.Data.StoreData", "StoreData") - .WithMany("Apps") - .HasForeignKey("StoreDataId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("BTCPayServer.Data.HistoricalAddressInvoiceData", b => - { - b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") - .WithMany("HistoricalAddressInvoices") - .HasForeignKey("InvoiceDataId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("BTCPayServer.Data.InvoiceData", b => - { - b.HasOne("BTCPayServer.Data.StoreData", "StoreData") - .WithMany("Invoices") - .HasForeignKey("StoreDataId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("BTCPayServer.Data.InvoiceEventData", b => - { - b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") - .WithMany("Events") - .HasForeignKey("InvoiceDataId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("BTCPayServer.Data.PairedSINData", b => - { - b.HasOne("BTCPayServer.Data.StoreData", "StoreData") - .WithMany("PairedSINs") - .HasForeignKey("StoreDataId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("BTCPayServer.Data.PaymentData", b => - { - b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") - .WithMany("Payments") - .HasForeignKey("InvoiceDataId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("BTCPayServer.Data.PaymentRequestData", b => - { - b.HasOne("BTCPayServer.Data.StoreData", "StoreData") - .WithMany("PaymentRequests") - .HasForeignKey("StoreDataId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("BTCPayServer.Data.PendingInvoiceData", b => - { - b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") - .WithMany("PendingInvoices") - .HasForeignKey("Id") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("BTCPayServer.Data.RefundAddressesData", b => - { - b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") - .WithMany("RefundAddresses") - .HasForeignKey("InvoiceDataId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("BTCPayServer.Data.StoredFile", b => - { - b.HasOne("BTCPayServer.Data.ApplicationUser", "ApplicationUser") - .WithMany("StoredFiles") - .HasForeignKey("ApplicationUserId"); - }); - - modelBuilder.Entity("BTCPayServer.Data.U2FDevice", b => - { - b.HasOne("BTCPayServer.Data.ApplicationUser", "ApplicationUser") - .WithMany("U2FDevices") - .HasForeignKey("ApplicationUserId"); - }); - - modelBuilder.Entity("BTCPayServer.Data.UserStore", b => - { - b.HasOne("BTCPayServer.Data.ApplicationUser", "ApplicationUser") - .WithMany("UserStores") - .HasForeignKey("ApplicationUserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BTCPayServer.Data.StoreData", "StoreData") - .WithMany("UserStores") - .HasForeignKey("StoreDataId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("BTCPayServer.Data.WalletTransactionData", b => - { - b.HasOne("BTCPayServer.Data.WalletData", "WalletData") - .WithMany("WalletTransactions") - .HasForeignKey("WalletDataId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("BTCPayServer.Data.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("BTCPayServer.Data.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BTCPayServer.Data.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("BTCPayServer.Data.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.cs b/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.cs index 6db60f5c0..332c7a48f 100644 --- a/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.cs +++ b/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.cs @@ -1,9 +1,14 @@ -using Microsoft.EntityFrameworkCore.Migrations; +using BTCPayServer.Data; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; namespace BTCPayServer.Migrations { + [DbContext(typeof(ApplicationDbContext))] + [Migration("20200225133433_AddApiKeyLabel")] public partial class AddApiKeyLabel : Migration { + protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( From e7eea1036bf8ef36b4d7e39b72dac1d08b241971 Mon Sep 17 00:00:00 2001 From: Kukks Date: Wed, 26 Feb 2020 10:26:38 +0100 Subject: [PATCH 9/9] make api key delete use confirm page --- .../Controllers/ManageController.APIKeys.cs | 29 ++++++++++++++++--- BTCPayServer/Models/ConfirmModel.cs | 1 + BTCPayServer/Views/Manage/APIKeys.cshtml | 2 +- BTCPayServer/Views/Shared/Confirm.cshtml | 2 +- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/BTCPayServer/Controllers/ManageController.APIKeys.cs b/BTCPayServer/Controllers/ManageController.APIKeys.cs index 9be2bec0d..23052fe9b 100644 --- a/BTCPayServer/Controllers/ManageController.APIKeys.cs +++ b/BTCPayServer/Controllers/ManageController.APIKeys.cs @@ -8,11 +8,8 @@ using BTCPayServer.Hosting.OpenApi; using BTCPayServer.Models; using BTCPayServer.Security; using BTCPayServer.Security.APIKeys; -using ExchangeSharp; using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json; using NSwag.Annotations; namespace BTCPayServer.Controllers @@ -31,9 +28,33 @@ namespace BTCPayServer.Controllers }); } - [HttpGet] + + + [HttpGet("api-keys/{id}/delete")] public async Task RemoveAPIKey(string id) { + var key = await _apiKeyRepository.GetKey(id); + if (key == null || key.UserId != _userManager.GetUserId(User)) + { + return NotFound(); + } + return View("Confirm", new ConfirmModel() + { + Title = "Delete API Key "+ ( string.IsNullOrEmpty(key.Label)? string.Empty: key.Label) + "("+key.Id+")", + Description = "Any application using this api key will immediately lose access", + Action = "Delete", + ActionUrl = Request.GetCurrentUrl().Replace("RemoveAPIKey", "RemoveAPIKeyPost") + }); + } + + [HttpPost("api-keys/{id}/delete")] + public async Task RemoveAPIKeyPost(string id) + { + var key = await _apiKeyRepository.GetKey(id); + if (key == null || key.UserId != _userManager.GetUserId(User)) + { + return NotFound(); + } await _apiKeyRepository.Remove(id, _userManager.GetUserId(User)); TempData.SetStatusMessageModel(new StatusMessageModel() { diff --git a/BTCPayServer/Models/ConfirmModel.cs b/BTCPayServer/Models/ConfirmModel.cs index b56f4274a..65caf78f1 100644 --- a/BTCPayServer/Models/ConfirmModel.cs +++ b/BTCPayServer/Models/ConfirmModel.cs @@ -29,5 +29,6 @@ namespace BTCPayServer.Models get; set; } public string ButtonClass { get; set; } = "btn-danger"; + public string ActionUrl { get; set; } } } diff --git a/BTCPayServer/Views/Manage/APIKeys.cshtml b/BTCPayServer/Views/Manage/APIKeys.cshtml index 4e4a69cca..ac197f44d 100644 --- a/BTCPayServer/Views/Manage/APIKeys.cshtml +++ b/BTCPayServer/Views/Manage/APIKeys.cshtml @@ -31,7 +31,7 @@ } } diff --git a/BTCPayServer/Views/Shared/Confirm.cshtml b/BTCPayServer/Views/Shared/Confirm.cshtml index 22f2975cb..d44105ae3 100644 --- a/BTCPayServer/Views/Shared/Confirm.cshtml +++ b/BTCPayServer/Views/Shared/Confirm.cshtml @@ -26,7 +26,7 @@ {
-
+
KeyPermissionsLabelKeyPermissions Actions
@keyData.Label @keyData.Id @if (string.IsNullOrEmpty(keyData.Permissions)) diff --git a/BTCPayServer/Views/Manage/AddApiKey.cshtml b/BTCPayServer/Views/Manage/AddApiKey.cshtml index e992c0a38..f5316c545 100644 --- a/BTCPayServer/Views/Manage/AddApiKey.cshtml +++ b/BTCPayServer/Views/Manage/AddApiKey.cshtml @@ -27,6 +27,14 @@
+ +
+
+ + + +
+
@if (Model.IsServerAdmin) {
diff --git a/BTCPayServer/Views/Manage/AuthorizeAPIKey.cshtml b/BTCPayServer/Views/Manage/AuthorizeAPIKey.cshtml index 136d480a3..612d9e2f7 100644 --- a/BTCPayServer/Views/Manage/AuthorizeAPIKey.cshtml +++ b/BTCPayServer/Views/Manage/AuthorizeAPIKey.cshtml @@ -35,6 +35,14 @@
+
+
+ + + +
+
+ @if (Model.PermissionsFormatted.Contains(APIKeyConstants.Permissions.ServerManagement) && (Model.IsServerAdmin || Model.Strict)) {
From 501c3241b543c5941ec9e5d7ecc14cf1edf9661f Mon Sep 17 00:00:00 2001 From: Kukks Date: Tue, 25 Feb 2020 15:00:44 +0100 Subject: [PATCH 3/9] consolidate migrations --- .../20200119130108_ExtendApiKeys.cs | 10 + .../20200225133433_AddApiKeyLabel.Designer.cs | 849 ------------------ .../20200225133433_AddApiKeyLabel.cs | 22 - 3 files changed, 10 insertions(+), 871 deletions(-) delete mode 100644 BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.Designer.cs delete mode 100644 BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.cs diff --git a/BTCPayServer.Data/Migrations/20200119130108_ExtendApiKeys.cs b/BTCPayServer.Data/Migrations/20200119130108_ExtendApiKeys.cs index 9eeb5b83c..05fa236cf 100644 --- a/BTCPayServer.Data/Migrations/20200119130108_ExtendApiKeys.cs +++ b/BTCPayServer.Data/Migrations/20200119130108_ExtendApiKeys.cs @@ -26,6 +26,11 @@ namespace BTCPayServer.Migrations table: "ApiKeys", maxLength: 50, nullable: true); + + migrationBuilder.AddColumn( + name: "Label", + table: "ApiKeys", + nullable: true); migrationBuilder.CreateIndex( name: "IX_ApiKeys_UserId", @@ -68,6 +73,11 @@ namespace BTCPayServer.Migrations migrationBuilder.DropColumn( name: "UserId", table: "ApiKeys"); + + migrationBuilder.DropColumn( + name: "Label", + table: "ApiKeys"); + } } } diff --git a/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.Designer.cs b/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.Designer.cs deleted file mode 100644 index a73d3f0bc..000000000 --- a/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.Designer.cs +++ /dev/null @@ -1,849 +0,0 @@ -// -using System; -using BTCPayServer.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -namespace BTCPayServer.Migrations -{ - [DbContext(typeof(ApplicationDbContext))] - [Migration("20200225133433_AddApiKeyLabel")] - partial class AddApiKeyLabel - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "3.1.1"); - - modelBuilder.Entity("BTCPayServer.Data.APIKeyData", b => - { - b.Property("Id") - .HasColumnType("TEXT") - .HasMaxLength(50); - - b.Property("Label") - .HasColumnType("TEXT"); - - b.Property("Permissions") - .HasColumnType("TEXT"); - - b.Property("StoreId") - .HasColumnType("TEXT") - .HasMaxLength(50); - - b.Property("Type") - .HasColumnType("INTEGER"); - - b.Property("UserId") - .HasColumnType("TEXT") - .HasMaxLength(50); - - b.HasKey("Id"); - - b.HasIndex("StoreId"); - - b.HasIndex("UserId"); - - b.ToTable("ApiKeys"); - }); - - modelBuilder.Entity("BTCPayServer.Data.AddressInvoiceData", b => - { - b.Property("Address") - .HasColumnType("TEXT"); - - b.Property("CreatedTime") - .HasColumnType("TEXT"); - - b.Property("InvoiceDataId") - .HasColumnType("TEXT"); - - b.HasKey("Address"); - - b.HasIndex("InvoiceDataId"); - - b.ToTable("AddressInvoices"); - }); - - modelBuilder.Entity("BTCPayServer.Data.AppData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("AppType") - .HasColumnType("TEXT"); - - b.Property("Created") - .HasColumnType("TEXT"); - - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("Settings") - .HasColumnType("TEXT"); - - b.Property("StoreDataId") - .HasColumnType("TEXT"); - - b.Property("TagAllInvoices") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.HasIndex("StoreDataId"); - - b.ToTable("Apps"); - }); - - modelBuilder.Entity("BTCPayServer.Data.ApplicationUser", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("AccessFailedCount") - .HasColumnType("INTEGER"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("TEXT"); - - b.Property("Email") - .HasColumnType("TEXT") - .HasMaxLength(256); - - b.Property("EmailConfirmed") - .HasColumnType("INTEGER"); - - b.Property("LockoutEnabled") - .HasColumnType("INTEGER"); - - b.Property("LockoutEnd") - .HasColumnType("TEXT"); - - b.Property("NormalizedEmail") - .HasColumnType("TEXT") - .HasMaxLength(256); - - b.Property("NormalizedUserName") - .HasColumnType("TEXT") - .HasMaxLength(256); - - b.Property("PasswordHash") - .HasColumnType("TEXT"); - - b.Property("PhoneNumber") - .HasColumnType("TEXT"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("INTEGER"); - - b.Property("RequiresEmailConfirmation") - .HasColumnType("INTEGER"); - - b.Property("SecurityStamp") - .HasColumnType("TEXT"); - - b.Property("TwoFactorEnabled") - .HasColumnType("INTEGER"); - - b.Property("UserName") - .HasColumnType("TEXT") - .HasMaxLength(256); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasName("UserNameIndex"); - - b.ToTable("AspNetUsers"); - }); - - modelBuilder.Entity("BTCPayServer.Data.HistoricalAddressInvoiceData", b => - { - b.Property("InvoiceDataId") - .HasColumnType("TEXT"); - - b.Property("Address") - .HasColumnType("TEXT"); - - b.Property("Assigned") - .HasColumnType("TEXT"); - - b.Property("CryptoCode") - .HasColumnType("TEXT"); - - b.Property("UnAssigned") - .HasColumnType("TEXT"); - - b.HasKey("InvoiceDataId", "Address"); - - b.ToTable("HistoricalAddressInvoices"); - }); - - modelBuilder.Entity("BTCPayServer.Data.InvoiceData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Blob") - .HasColumnType("BLOB"); - - b.Property("Created") - .HasColumnType("TEXT"); - - b.Property("CustomerEmail") - .HasColumnType("TEXT"); - - b.Property("ExceptionStatus") - .HasColumnType("TEXT"); - - b.Property("ItemCode") - .HasColumnType("TEXT"); - - b.Property("OrderId") - .HasColumnType("TEXT"); - - b.Property("Status") - .HasColumnType("TEXT"); - - b.Property("StoreDataId") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("StoreDataId"); - - b.ToTable("Invoices"); - }); - - modelBuilder.Entity("BTCPayServer.Data.InvoiceEventData", b => - { - b.Property("InvoiceDataId") - .HasColumnType("TEXT"); - - b.Property("UniqueId") - .HasColumnType("TEXT"); - - b.Property("Message") - .HasColumnType("TEXT"); - - b.Property("Timestamp") - .HasColumnType("TEXT"); - - b.HasKey("InvoiceDataId", "UniqueId"); - - b.ToTable("InvoiceEvents"); - }); - - modelBuilder.Entity("BTCPayServer.Data.PairedSINData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Label") - .HasColumnType("TEXT"); - - b.Property("PairingTime") - .HasColumnType("TEXT"); - - b.Property("SIN") - .HasColumnType("TEXT"); - - b.Property("StoreDataId") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("SIN"); - - b.HasIndex("StoreDataId"); - - b.ToTable("PairedSINData"); - }); - - modelBuilder.Entity("BTCPayServer.Data.PairingCodeData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("DateCreated") - .HasColumnType("TEXT"); - - b.Property("Expiration") - .HasColumnType("TEXT"); - - b.Property("Facade") - .HasColumnType("TEXT"); - - b.Property("Label") - .HasColumnType("TEXT"); - - b.Property("SIN") - .HasColumnType("TEXT"); - - b.Property("StoreDataId") - .HasColumnType("TEXT"); - - b.Property("TokenValue") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("PairingCodes"); - }); - - modelBuilder.Entity("BTCPayServer.Data.PaymentData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Accounted") - .HasColumnType("INTEGER"); - - b.Property("Blob") - .HasColumnType("BLOB"); - - b.Property("InvoiceDataId") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("InvoiceDataId"); - - b.ToTable("Payments"); - }); - - modelBuilder.Entity("BTCPayServer.Data.PaymentRequestData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Blob") - .HasColumnType("BLOB"); - - b.Property("Created") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT") - .HasDefaultValue(new DateTimeOffset(new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0))); - - b.Property("Status") - .HasColumnType("INTEGER"); - - b.Property("StoreDataId") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("Status"); - - b.HasIndex("StoreDataId"); - - b.ToTable("PaymentRequests"); - }); - - modelBuilder.Entity("BTCPayServer.Data.PendingInvoiceData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("PendingInvoices"); - }); - - modelBuilder.Entity("BTCPayServer.Data.RefundAddressesData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Blob") - .HasColumnType("BLOB"); - - b.Property("InvoiceDataId") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("InvoiceDataId"); - - b.ToTable("RefundAddresses"); - }); - - modelBuilder.Entity("BTCPayServer.Data.SettingData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Value") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Settings"); - }); - - modelBuilder.Entity("BTCPayServer.Data.StoreData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("DefaultCrypto") - .HasColumnType("TEXT"); - - b.Property("DerivationStrategies") - .HasColumnType("TEXT"); - - b.Property("DerivationStrategy") - .HasColumnType("TEXT"); - - b.Property("SpeedPolicy") - .HasColumnType("INTEGER"); - - b.Property("StoreBlob") - .HasColumnType("BLOB"); - - b.Property("StoreCertificate") - .HasColumnType("BLOB"); - - b.Property("StoreName") - .HasColumnType("TEXT"); - - b.Property("StoreWebsite") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Stores"); - }); - - modelBuilder.Entity("BTCPayServer.Data.StoredFile", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("ApplicationUserId") - .HasColumnType("TEXT"); - - b.Property("FileName") - .HasColumnType("TEXT"); - - b.Property("StorageFileName") - .HasColumnType("TEXT"); - - b.Property("Timestamp") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("ApplicationUserId"); - - b.ToTable("Files"); - }); - - modelBuilder.Entity("BTCPayServer.Data.U2FDevice", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("ApplicationUserId") - .HasColumnType("TEXT"); - - b.Property("AttestationCert") - .IsRequired() - .HasColumnType("BLOB"); - - b.Property("Counter") - .HasColumnType("INTEGER"); - - b.Property("KeyHandle") - .IsRequired() - .HasColumnType("BLOB"); - - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("PublicKey") - .IsRequired() - .HasColumnType("BLOB"); - - b.HasKey("Id"); - - b.HasIndex("ApplicationUserId"); - - b.ToTable("U2FDevices"); - }); - - modelBuilder.Entity("BTCPayServer.Data.UserStore", b => - { - b.Property("ApplicationUserId") - .HasColumnType("TEXT"); - - b.Property("StoreDataId") - .HasColumnType("TEXT"); - - b.Property("Role") - .HasColumnType("TEXT"); - - b.HasKey("ApplicationUserId", "StoreDataId"); - - b.HasIndex("StoreDataId"); - - b.ToTable("UserStore"); - }); - - modelBuilder.Entity("BTCPayServer.Data.WalletData", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Blob") - .HasColumnType("BLOB"); - - b.HasKey("Id"); - - b.ToTable("Wallets"); - }); - - modelBuilder.Entity("BTCPayServer.Data.WalletTransactionData", b => - { - b.Property("WalletDataId") - .HasColumnType("TEXT"); - - b.Property("TransactionId") - .HasColumnType("TEXT"); - - b.Property("Blob") - .HasColumnType("BLOB"); - - b.Property("Labels") - .HasColumnType("TEXT"); - - b.HasKey("WalletDataId", "TransactionId"); - - b.ToTable("WalletTransactions"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("TEXT"); - - b.Property("Name") - .HasColumnType("TEXT") - .HasMaxLength(256); - - b.Property("NormalizedName") - .HasColumnType("TEXT") - .HasMaxLength(256); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasName("RoleNameIndex"); - - b.ToTable("AspNetRoles"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("ClaimType") - .HasColumnType("TEXT"); - - b.Property("ClaimValue") - .HasColumnType("TEXT"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("ClaimType") - .HasColumnType("TEXT"); - - b.Property("ClaimValue") - .HasColumnType("TEXT"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("TEXT"); - - b.Property("ProviderKey") - .HasColumnType("TEXT"); - - b.Property("ProviderDisplayName") - .HasColumnType("TEXT"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("TEXT"); - - b.Property("RoleId") - .HasColumnType("TEXT"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("TEXT"); - - b.Property("LoginProvider") - .HasColumnType("TEXT"); - - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("Value") - .HasColumnType("TEXT"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens"); - }); - - modelBuilder.Entity("BTCPayServer.Data.APIKeyData", b => - { - b.HasOne("BTCPayServer.Data.StoreData", "StoreData") - .WithMany("APIKeys") - .HasForeignKey("StoreId") - .OnDelete(DeleteBehavior.Cascade); - - b.HasOne("BTCPayServer.Data.ApplicationUser", "User") - .WithMany("APIKeys") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("BTCPayServer.Data.AddressInvoiceData", b => - { - b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") - .WithMany("AddressInvoices") - .HasForeignKey("InvoiceDataId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("BTCPayServer.Data.AppData", b => - { - b.HasOne("BTCPayServer.Data.StoreData", "StoreData") - .WithMany("Apps") - .HasForeignKey("StoreDataId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("BTCPayServer.Data.HistoricalAddressInvoiceData", b => - { - b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") - .WithMany("HistoricalAddressInvoices") - .HasForeignKey("InvoiceDataId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("BTCPayServer.Data.InvoiceData", b => - { - b.HasOne("BTCPayServer.Data.StoreData", "StoreData") - .WithMany("Invoices") - .HasForeignKey("StoreDataId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("BTCPayServer.Data.InvoiceEventData", b => - { - b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") - .WithMany("Events") - .HasForeignKey("InvoiceDataId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("BTCPayServer.Data.PairedSINData", b => - { - b.HasOne("BTCPayServer.Data.StoreData", "StoreData") - .WithMany("PairedSINs") - .HasForeignKey("StoreDataId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("BTCPayServer.Data.PaymentData", b => - { - b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") - .WithMany("Payments") - .HasForeignKey("InvoiceDataId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("BTCPayServer.Data.PaymentRequestData", b => - { - b.HasOne("BTCPayServer.Data.StoreData", "StoreData") - .WithMany("PaymentRequests") - .HasForeignKey("StoreDataId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("BTCPayServer.Data.PendingInvoiceData", b => - { - b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") - .WithMany("PendingInvoices") - .HasForeignKey("Id") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("BTCPayServer.Data.RefundAddressesData", b => - { - b.HasOne("BTCPayServer.Data.InvoiceData", "InvoiceData") - .WithMany("RefundAddresses") - .HasForeignKey("InvoiceDataId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("BTCPayServer.Data.StoredFile", b => - { - b.HasOne("BTCPayServer.Data.ApplicationUser", "ApplicationUser") - .WithMany("StoredFiles") - .HasForeignKey("ApplicationUserId"); - }); - - modelBuilder.Entity("BTCPayServer.Data.U2FDevice", b => - { - b.HasOne("BTCPayServer.Data.ApplicationUser", "ApplicationUser") - .WithMany("U2FDevices") - .HasForeignKey("ApplicationUserId"); - }); - - modelBuilder.Entity("BTCPayServer.Data.UserStore", b => - { - b.HasOne("BTCPayServer.Data.ApplicationUser", "ApplicationUser") - .WithMany("UserStores") - .HasForeignKey("ApplicationUserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BTCPayServer.Data.StoreData", "StoreData") - .WithMany("UserStores") - .HasForeignKey("StoreDataId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("BTCPayServer.Data.WalletTransactionData", b => - { - b.HasOne("BTCPayServer.Data.WalletData", "WalletData") - .WithMany("WalletTransactions") - .HasForeignKey("WalletDataId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("BTCPayServer.Data.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("BTCPayServer.Data.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BTCPayServer.Data.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("BTCPayServer.Data.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.cs b/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.cs deleted file mode 100644 index 6db60f5c0..000000000 --- a/BTCPayServer.Data/Migrations/20200225133433_AddApiKeyLabel.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -namespace BTCPayServer.Migrations -{ - public partial class AddApiKeyLabel : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "Label", - table: "ApiKeys", - nullable: true); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "Label", - table: "ApiKeys"); - } - } -} From ec80787120fc5f82e92ceb5b886cd45d1d40e9f5 Mon Sep 17 00:00:00 2001 From: Kukks Date: Tue, 25 Feb 2020 15:33:04 +0100 Subject: [PATCH 4/9] fix --- BTCPayServer/Controllers/StoresController.BTCLike.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BTCPayServer/Controllers/StoresController.BTCLike.cs b/BTCPayServer/Controllers/StoresController.BTCLike.cs index d1da40d96..e7e2bc966 100644 --- a/BTCPayServer/Controllers/StoresController.BTCLike.cs +++ b/BTCPayServer/Controllers/StoresController.BTCLike.cs @@ -142,7 +142,7 @@ namespace BTCPayServer.Controllers [HttpPost] [Route("{storeId}/derivations/{cryptoCode}")] - public async Task AddDerivationScheme(string storeId, [FromBody] DerivationSchemeViewModel vm, + public async Task AddDerivationScheme(string storeId, [FromForm] DerivationSchemeViewModel vm, string cryptoCode) { vm.CryptoCode = cryptoCode; From 0c7f35b0003678caee98fe179c2cbe9339bce649 Mon Sep 17 00:00:00 2001 From: Kukks Date: Wed, 26 Feb 2020 09:10:27 +0100 Subject: [PATCH 5/9] fix swagger gen --- BTCPayServer/Controllers/StoresController.BTCLike.cs | 3 ++- BTCPayServer/Views/Manage/AuthorizeAPIKey.cshtml | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/BTCPayServer/Controllers/StoresController.BTCLike.cs b/BTCPayServer/Controllers/StoresController.BTCLike.cs index e7e2bc966..1926cecb1 100644 --- a/BTCPayServer/Controllers/StoresController.BTCLike.cs +++ b/BTCPayServer/Controllers/StoresController.BTCLike.cs @@ -141,7 +141,8 @@ namespace BTCPayServer.Controllers } [HttpPost] - [Route("{storeId}/derivations/{cryptoCode}")] + [Route("{storeId}/derivations/{cryptoCode}")] + [ApiExplorerSettings(IgnoreApi = true)] public async Task AddDerivationScheme(string storeId, [FromForm] DerivationSchemeViewModel vm, string cryptoCode) { diff --git a/BTCPayServer/Views/Manage/AuthorizeAPIKey.cshtml b/BTCPayServer/Views/Manage/AuthorizeAPIKey.cshtml index 612d9e2f7..303e171aa 100644 --- a/BTCPayServer/Views/Manage/AuthorizeAPIKey.cshtml +++ b/BTCPayServer/Views/Manage/AuthorizeAPIKey.cshtml @@ -42,7 +42,12 @@
- + @if (!Model.PermissionsFormatted.Any()) + { +
+

There are no associated permissions to the API key being requested here. The application cannot do anything with your BTCPay account other than validating your account exists.

+
+ } @if (Model.PermissionsFormatted.Contains(APIKeyConstants.Permissions.ServerManagement) && (Model.IsServerAdmin || Model.Strict)) {
From d9ea9fbffd8d1817297b0a9d2a8a99b56156cf97 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Wed, 26 Feb 2020 17:34:32 +0900 Subject: [PATCH 6/9] Fix colspan --- BTCPayServer/Views/Manage/APIKeys.cshtml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BTCPayServer/Views/Manage/APIKeys.cshtml b/BTCPayServer/Views/Manage/APIKeys.cshtml index 5c6656ef5..4e4a69cca 100644 --- a/BTCPayServer/Views/Manage/APIKeys.cshtml +++ b/BTCPayServer/Views/Manage/APIKeys.cshtml @@ -38,13 +38,13 @@ @if (!Model.ApiKeyDatas.Any()) {
+ No API keys
+ Generate new key
- Remove + Remove