From ead74a985fe0285cd30d88f6b4ada0c2954c8a8a Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Fri, 4 Apr 2025 16:28:44 +0900 Subject: [PATCH] Remove deprecated properties --- .../Models/ApplicationUserData.cs | 5 ++++ BTCPayServer.Client/Models/StoreData.cs | 12 ---------- BTCPayServer.Tests/GreenfieldAPITests.cs | 2 ++ .../GreenfieldStoreUsersController.cs | 24 +++++++++++-------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/BTCPayServer.Client/Models/ApplicationUserData.cs b/BTCPayServer.Client/Models/ApplicationUserData.cs index f7498bd48..d9eec2c65 100644 --- a/BTCPayServer.Client/Models/ApplicationUserData.cs +++ b/BTCPayServer.Client/Models/ApplicationUserData.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace BTCPayServer.Client.Models { @@ -62,5 +64,8 @@ namespace BTCPayServer.Client.Models public DateTimeOffset? Created { get; set; } public bool Disabled { get; set; } + + [JsonExtensionData] + public IDictionary AdditionalData { get; set; } = new Dictionary(); } } diff --git a/BTCPayServer.Client/Models/StoreData.cs b/BTCPayServer.Client/Models/StoreData.cs index 389fa299e..f2ffac2a6 100644 --- a/BTCPayServer.Client/Models/StoreData.cs +++ b/BTCPayServer.Client/Models/StoreData.cs @@ -14,22 +14,10 @@ namespace BTCPayServer.Client.Models public class StoreUserData : ApplicationUserData { - /// - /// the id of the user - /// - [Obsolete("Use Id instead")] - public string UserId { get; set; } - /// /// the store role of the user /// public string StoreRole { get; set; } - - /// - /// the store role of the user - /// - [Obsolete("Use StoreRole instead")] - public string Role { get; set; } } public class RoleData diff --git a/BTCPayServer.Tests/GreenfieldAPITests.cs b/BTCPayServer.Tests/GreenfieldAPITests.cs index 316e7611d..8e406abf5 100644 --- a/BTCPayServer.Tests/GreenfieldAPITests.cs +++ b/BTCPayServer.Tests/GreenfieldAPITests.cs @@ -4018,7 +4018,9 @@ namespace BTCPayServer.Tests var users = await client.GetStoreUsers(user.StoreId); var storeUser = Assert.Single(users); Assert.Equal(user.UserId, storeUser.Id); + Assert.Equal(user.UserId, storeUser.AdditionalData["userId"].ToString()); Assert.Equal(ownerRole.Id, storeUser.StoreRole); + Assert.Equal(ownerRole.Id, storeUser.AdditionalData["role"].ToString()); Assert.Equal(user.Email, storeUser.Email); Assert.Equal("The Admin", storeUser.Name); Assert.Equal("avatar.jpg", storeUser.ImageUrl); diff --git a/BTCPayServer/Controllers/GreenField/GreenfieldStoreUsersController.cs b/BTCPayServer/Controllers/GreenField/GreenfieldStoreUsersController.cs index 53ae1b7fa..3a0032bf1 100644 --- a/BTCPayServer/Controllers/GreenField/GreenfieldStoreUsersController.cs +++ b/BTCPayServer/Controllers/GreenField/GreenfieldStoreUsersController.cs @@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json.Linq; using NicolasDorier.RateLimits; using StoreData = BTCPayServer.Data.StoreData; @@ -46,7 +47,7 @@ namespace BTCPayServer.Controllers.Greenfield public async Task GetStoreUsers() { var store = HttpContext.GetStoreData(); - return store == null ? StoreNotFound() : Ok(await FromModel(store)); + return store == null ? StoreNotFound() : Ok(await ToAPI(store)); } [Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)] @@ -74,10 +75,11 @@ namespace BTCPayServer.Controllers.Greenfield var store = HttpContext.GetStoreData(); if (store == null) return StoreNotFound(); -#pragma warning disable CS0618 // Type or member is obsolete - request.StoreRole ??= request.Role; - request.Id ??= request.UserId; -#pragma warning restore CS0618 // Type or member is obsolete + + // Deprecated properties + request.StoreRole ??= request.AdditionalData.TryGetValue("role", out var role) ? role.ToString() : null; + request.Id ??= request.AdditionalData.TryGetValue("userId", out var userId) ? userId.ToString() : null; + ///// var user = await _userManager.FindByIdOrEmail(idOrEmail ?? request.Id); if (user == null) @@ -102,7 +104,7 @@ namespace BTCPayServer.Controllers.Greenfield : this.CreateAPIError(409, "duplicate-store-user-role", "The user is already added to the store"); } - private async Task> FromModel(StoreData store) + private async Task> ToAPI(StoreData store) { var storeUsers = new List(); foreach (var storeUser in store.UserStores) @@ -112,10 +114,12 @@ namespace BTCPayServer.Controllers.Greenfield continue; var data = await UserService.ForAPI(user, [], _callbackGenerator, _uriResolver, Request); data.StoreRole = storeUser.StoreRoleId; -#pragma warning disable CS0618 // Type or member is obsolete - data.UserId = storeUser.ApplicationUserId; - data.Role = storeUser.StoreRoleId; -#pragma warning restore CS0618 // Type or member is obsolete + + // Deprecated properties + data.AdditionalData["userId"] = new JValue(storeUser.ApplicationUserId); + data.AdditionalData["role"] = new JValue(storeUser.StoreRoleId); + ///// + storeUsers.Add(data); } return storeUsers;