Skip to content

Commit

Permalink
Branding updates for 2.0 (#5947)
Browse files Browse the repository at this point in the history
* Remove deprecated CSS options

Closes #5945.

* Greenfield: Add brandColor to store APIs

Closes #5946.

* Migrate file IDs to URLs

Closes #5953.

* Greenfield: Add CSS and logo URL to store settings API

Closes #5945.

* Add migration test

* Store and Server branding can reference file's via fileid:ID

* Add PaymentSoundUrl to Store API

---------

Co-authored-by: nicolas.dorier <nicolas.dorier@gmail.com>
  • Loading branch information
dennisreimann and NicolasDorier committed May 9, 2024
1 parent eba3475 commit 4c303d3
Show file tree
Hide file tree
Showing 66 changed files with 526 additions and 605 deletions.
4 changes: 0 additions & 4 deletions BTCPayServer.Client/Models/CreateAppRequest.cs
Expand Up @@ -35,13 +35,11 @@ public class CreatePointOfSaleAppRequest : CreateAppRequest
public string CustomAmountPayButtonText { get; set; } = null;
public string FixedAmountPayButtonText { get; set; } = null;
public string TipText { get; set; } = null;
public string CustomCSSLink { get; set; } = null;
public string NotificationUrl { get; set; } = null;
public string RedirectUrl { get; set; } = null;
public bool? RedirectAutomatically { get; set; } = null;
public bool? Archived { get; set; } = null;
public string FormId { get; set; } = null;
public string EmbeddedCSS { get; set; } = null;
}

public enum CrowdfundResetEvery
Expand All @@ -65,9 +63,7 @@ public class CreateCrowdfundAppRequest : CreateAppRequest
[JsonConverter(typeof(NBitcoin.JsonConverters.DateTimeToUnixTimeConverter))]
public DateTimeOffset? EndDate { get; set; } = null;
public decimal? TargetAmount { get; set; } = null;
public string CustomCSSLink { get; set; } = null;
public string MainImageUrl { get; set; } = null;
public string EmbeddedCSS { get; set; } = null;
public string NotificationUrl { get; set; } = null;
public string Tagline { get; set; } = null;
public string PerksTemplate { get; set; } = null;
Expand Down
3 changes: 0 additions & 3 deletions BTCPayServer.Client/Models/PaymentRequestBaseData.cs
Expand Up @@ -17,9 +17,6 @@ public class PaymentRequestBaseData
public string Title { get; set; }
public string Description { get; set; }
public string Email { get; set; }

public string EmbeddedCSS { get; set; }
public string CustomCSSLink { get; set; }
public bool AllowCustomPaymentAmounts { get; set; }

[JsonExtensionData]
Expand Down
4 changes: 0 additions & 4 deletions BTCPayServer.Client/Models/PointOfSaleAppData.cs
Expand Up @@ -30,11 +30,9 @@ public class PointOfSaleAppData : AppDataBase
public string FixedAmountPayButtonText { get; set; }
public string CustomAmountPayButtonText { get; set; }
public string TipText { get; set; }
public string CustomCSSLink { get; set; }
public string NotificationUrl { get; set; }
public string RedirectUrl { get; set; }
public string Description { get; set; }
public string EmbeddedCSS { get; set; }
public bool? RedirectAutomatically { get; set; }
}

Expand All @@ -50,9 +48,7 @@ public class CrowdfundAppData : AppDataBase
[JsonConverter(typeof(NBitcoin.JsonConverters.DateTimeToUnixTimeConverter))]
public DateTimeOffset? EndDate { get; set; }
public decimal? TargetAmount { get; set; }
public string CustomCSSLink { get; set; }
public string MainImageUrl { get; set; }
public string EmbeddedCSS { get; set; }
public string NotificationUrl { get; set; }
public string Tagline { get; set; }
public object Perks { get; set; }
Expand Down
5 changes: 5 additions & 0 deletions BTCPayServer.Client/Models/StoreBaseData.cs
Expand Up @@ -16,6 +16,11 @@ public abstract class StoreBaseData

public string Website { get; set; }

public string BrandColor { get; set; }
public string LogoUrl { get; set; }
public string CssUrl { get; set; }
public string PaymentSoundUrl { get; set; }

public string SupportUrl { get; set; }

[JsonConverter(typeof(TimeSpanJsonConverter.Seconds))]
Expand Down
61 changes: 61 additions & 0 deletions BTCPayServer.Data/Migrations/20240508015052_fileid.cs
@@ -0,0 +1,61 @@
using BTCPayServer.Data;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace BTCPayServer.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20240508015052_fileid")]
public partial class fileid : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("""
UPDATE "Settings"
SET "Value" = jsonb_set(
"Value",
'{LogoUrl}',
to_jsonb('fileid:' || ("Value"->>'LogoFileId'))) - 'LogoFileId'
WHERE "Id" = 'BTCPayServer.Services.ThemeSettings'
AND "Value"->>'LogoFileId' IS NOT NULL;

UPDATE "Settings"
SET "Value" = jsonb_set(
"Value",
'{CustomThemeCssUrl}',
to_jsonb('fileid:' || ("Value"->>'CustomThemeFileId'))) - 'CustomThemeFileId'
WHERE "Id" = 'BTCPayServer.Services.ThemeSettings'
AND "Value"->>'CustomThemeFileId' IS NOT NULL;

UPDATE "Stores"
SET "StoreBlob" = jsonb_set(
"StoreBlob",
'{logoUrl}',
to_jsonb('fileid:' || ("StoreBlob"->>'logoFileId'))) - 'logoFileId'
WHERE "StoreBlob"->>'logoFileId' IS NOT NULL;

UPDATE "Stores"
SET "StoreBlob" = jsonb_set(
"StoreBlob",
'{cssUrl}',
to_jsonb('fileid:' || ("StoreBlob"->>'cssFileId'))) - 'cssFileId'
WHERE "StoreBlob"->>'cssFileId' IS NOT NULL;

UPDATE "Stores"
SET "StoreBlob" = jsonb_set(
"StoreBlob",
'{paymentSoundUrl}',
to_jsonb('fileid:' || ("StoreBlob"->>'soundFileId'))) - 'soundFileId'
WHERE "StoreBlob"->>'soundFileId' IS NOT NULL;
""");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}
6 changes: 6 additions & 0 deletions BTCPayServer.Tests/BTCPayServerTester.cs
Expand Up @@ -64,6 +64,11 @@ public Uri ServerUri
get;
set;
}
public Uri ServerUriWithIP
{
get;
set;
}

public string MySQL
{
Expand Down Expand Up @@ -164,6 +169,7 @@ public async Task StartAsync()
await File.WriteAllTextAsync(confPath, config.ToString());

ServerUri = new Uri("http://" + HostName + ":" + Port + "/");
ServerUriWithIP = new Uri("http://127.0.0.1:" + Port + "/");
HttpClient = new HttpClient();
HttpClient.BaseAddress = ServerUri;
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
Expand Down
15 changes: 15 additions & 0 deletions BTCPayServer.Tests/GreenfieldAPITests.cs
Expand Up @@ -1365,13 +1365,25 @@ public async Task StoresControllerTests()
//create store
var newStore = await client.CreateStore(new CreateStoreRequest { Name = "A" });
Assert.Equal("A", newStore.Name);

// validate
await AssertValidationError(["CssUrl", "LogoUrl", "BrandColor"], async () =>
await client.UpdateStore(newStore.Id, new UpdateStoreRequest
{
CssUrl = "style.css",
LogoUrl = "logo.svg",
BrandColor = "invalid"
}));

//update store
Assert.Empty(newStore.PaymentMethodCriteria);
await client.GenerateOnChainWallet(newStore.Id, "BTC", new GenerateOnChainWalletRequest());
var updatedStore = await client.UpdateStore(newStore.Id, new UpdateStoreRequest
{
Name = "B",
CssUrl = "https://example.org/style.css",
LogoUrl = "https://example.org/logo.svg",
BrandColor = "#003366",
PaymentMethodCriteria = new List<PaymentMethodCriteriaData>
{
new()
Expand All @@ -1384,6 +1396,9 @@ public async Task StoresControllerTests()
}
});
Assert.Equal("B", updatedStore.Name);
Assert.Equal("https://example.org/style.css", updatedStore.CssUrl);
Assert.Equal("https://example.org/logo.svg", updatedStore.LogoUrl);
Assert.Equal("#003366", updatedStore.BrandColor);
var s = (await client.GetStore(newStore.Id));
Assert.Equal("B", s.Name);
var pmc = Assert.Single(s.PaymentMethodCriteria);
Expand Down
2 changes: 1 addition & 1 deletion BTCPayServer.Tests/TestAccount.cs
Expand Up @@ -146,7 +146,7 @@ public async Task SetNetworkFeeMode(NetworkFeeMode mode)
public async Task ModifyPayment(Action<GeneralSettingsViewModel> modify)
{
var storeController = GetController<UIStoresController>();
var response = storeController.GeneralSettings();
var response = await storeController.GeneralSettings();
GeneralSettingsViewModel settings = (GeneralSettingsViewModel)((ViewResult)response).Model;
modify(settings);
await storeController.GeneralSettings(settings);
Expand Down
6 changes: 2 additions & 4 deletions BTCPayServer.Tests/ThirdPartyTests.cs
Expand Up @@ -57,7 +57,6 @@ public async Task CanUseAzureBlobStorage()
Assert.IsType<ViewResult>(
await controller.EditAzureBlobStorageStorageProvider(azureBlobStorageConfiguration));


var shouldBeRedirectingToAzureStorageConfigPage =
Assert.IsType<RedirectToActionResult>(await controller.Storage());
Assert.Equal(nameof(StorageProvider), shouldBeRedirectingToAzureStorageConfigPage.ActionName);
Expand All @@ -72,9 +71,8 @@ public async Task CanUseAzureBlobStorage()
await controller.StorageProvider(StorageProvider.AzureBlobStorage.ToString()))
.Model).ConnectionString);



await UnitTest1.CanUploadRemoveFiles(controller);
var fileId = await UnitTest1.CanUploadFile(controller);
await UnitTest1.CanRemoveFile(controller, fileId);
}

[Fact(Skip = "Fail on CI")]
Expand Down

0 comments on commit 4c303d3

Please sign in to comment.