mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2026-02-22 22:54:23 +01:00
Archive stores and apps (#5296)
* Add flags and migration * Archive store * Archive apps
This commit is contained in:
@@ -66,7 +66,8 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
{
|
||||
StoreDataId = storeId,
|
||||
Name = request.AppName,
|
||||
AppType = CrowdfundAppType.AppType
|
||||
AppType = CrowdfundAppType.AppType,
|
||||
Archived = request.Archived ?? false
|
||||
};
|
||||
|
||||
appData.SetSettings(ToCrowdfundSettings(request));
|
||||
@@ -97,7 +98,8 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
{
|
||||
StoreDataId = storeId,
|
||||
Name = request.AppName,
|
||||
AppType = PointOfSaleAppType.AppType
|
||||
AppType = PointOfSaleAppType.AppType,
|
||||
Archived = request.Archived ?? false
|
||||
};
|
||||
|
||||
appData.SetSettings(ToPointOfSaleSettings(request));
|
||||
@@ -111,7 +113,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
public async Task<IActionResult> UpdatePointOfSaleApp(string appId, CreatePointOfSaleAppRequest request)
|
||||
{
|
||||
var app = await _appService.GetApp(appId, PointOfSaleAppType.AppType);
|
||||
var app = await _appService.GetApp(appId, PointOfSaleAppType.AppType, includeArchived: true);
|
||||
if (app == null)
|
||||
{
|
||||
return AppNotFound();
|
||||
@@ -129,6 +131,10 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
}
|
||||
|
||||
app.Name = request.AppName;
|
||||
if (request.Archived != null)
|
||||
{
|
||||
app.Archived = request.Archived.Value;
|
||||
}
|
||||
app.SetSettings(ToPointOfSaleSettings(request));
|
||||
|
||||
await _appService.UpdateOrCreateApp(app);
|
||||
@@ -153,7 +159,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
public async Task<IActionResult> GetAllApps()
|
||||
{
|
||||
var apps = await _appService.GetAllApps(_userManager.GetUserId(User));
|
||||
var apps = await _appService.GetAllApps(_userManager.GetUserId(User), includeArchived: true);
|
||||
|
||||
return Ok(apps.Select(ToModel).ToArray());
|
||||
}
|
||||
@@ -162,7 +168,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
public async Task<IActionResult> GetAllApps(string storeId)
|
||||
{
|
||||
var apps = await _appService.GetAllApps(_userManager.GetUserId(User), allowNoUser: false, storeId);
|
||||
var apps = await _appService.GetAllApps(_userManager.GetUserId(User), false, storeId, true);
|
||||
|
||||
return Ok(apps.Select(ToModel).ToArray());
|
||||
}
|
||||
@@ -171,7 +177,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
public async Task<IActionResult> GetApp(string appId)
|
||||
{
|
||||
var app = await _appService.GetApp(appId, null);
|
||||
var app = await _appService.GetApp(appId, null, includeArchived: true);
|
||||
if (app == null)
|
||||
{
|
||||
return AppNotFound();
|
||||
@@ -184,7 +190,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
public async Task<IActionResult> GetPosApp(string appId)
|
||||
{
|
||||
var app = await _appService.GetApp(appId, PointOfSaleAppType.AppType);
|
||||
var app = await _appService.GetApp(appId, PointOfSaleAppType.AppType, includeArchived: true);
|
||||
if (app == null)
|
||||
{
|
||||
return AppNotFound();
|
||||
@@ -197,7 +203,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
public async Task<IActionResult> GetCrowdfundApp(string appId)
|
||||
{
|
||||
var app = await _appService.GetApp(appId, CrowdfundAppType.AppType);
|
||||
var app = await _appService.GetApp(appId, CrowdfundAppType.AppType, includeArchived: true);
|
||||
if (app == null)
|
||||
{
|
||||
return AppNotFound();
|
||||
@@ -209,7 +215,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
[HttpDelete("~/api/v1/apps/{appId}")]
|
||||
public async Task<IActionResult> DeleteApp(string appId)
|
||||
{
|
||||
var app = await _appService.GetApp(appId, null);
|
||||
var app = await _appService.GetApp(appId, null, includeArchived: true);
|
||||
if (app == null)
|
||||
{
|
||||
return AppNotFound();
|
||||
@@ -293,6 +299,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
return new AppDataBase
|
||||
{
|
||||
Id = appData.Id,
|
||||
Archived = appData.Archived,
|
||||
AppType = appData.AppType,
|
||||
Name = appData.Name,
|
||||
StoreId = appData.StoreDataId,
|
||||
@@ -305,6 +312,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
return new AppDataBase
|
||||
{
|
||||
Id = appData.Id,
|
||||
Archived = appData.Archived,
|
||||
AppType = appData.AppType,
|
||||
Name = appData.AppName,
|
||||
StoreId = appData.StoreId,
|
||||
@@ -319,6 +327,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
return new PointOfSaleAppData
|
||||
{
|
||||
Id = appData.Id,
|
||||
Archived = appData.Archived,
|
||||
AppType = appData.AppType,
|
||||
Name = appData.Name,
|
||||
StoreId = appData.StoreDataId,
|
||||
@@ -387,6 +396,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
return new CrowdfundAppData
|
||||
{
|
||||
Id = appData.Id,
|
||||
Archived = appData.Archived,
|
||||
AppType = appData.AppType,
|
||||
Name = appData.Name,
|
||||
StoreId = appData.StoreDataId,
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
_storeRepository = storeRepository;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
[Authorize(Policy = Policies.CanViewStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
[HttpGet("~/api/v1/stores")]
|
||||
public Task<ActionResult<IEnumerable<Client.Models.StoreData>>> GetStores()
|
||||
@@ -112,7 +113,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
return Ok(FromModel(store));
|
||||
}
|
||||
|
||||
internal static Client.Models.StoreData FromModel(Data.StoreData data)
|
||||
internal static Client.Models.StoreData FromModel(StoreData data)
|
||||
{
|
||||
var storeBlob = data.GetStoreBlob();
|
||||
return new Client.Models.StoreData
|
||||
@@ -120,6 +121,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
Id = data.Id,
|
||||
Name = data.StoreName,
|
||||
Website = data.StoreWebsite,
|
||||
Archived = data.Archived,
|
||||
SupportUrl = storeBlob.StoreSupportUrl,
|
||||
SpeedPolicy = data.SpeedPolicy,
|
||||
DefaultPaymentMethod = data.GetDefaultPaymentId()?.ToStringNormalized(),
|
||||
@@ -166,6 +168,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
var blob = model.GetStoreBlob();
|
||||
model.StoreName = restModel.Name;
|
||||
model.StoreWebsite = restModel.Website;
|
||||
model.Archived = restModel.Archived;
|
||||
model.SpeedPolicy = restModel.SpeedPolicy;
|
||||
model.SetDefaultPaymentId(defaultPaymentMethod);
|
||||
//we do not include the default payment method in this model and instead opt to set it in the stores/storeid/payment-methods endpoints
|
||||
|
||||
@@ -76,28 +76,26 @@ namespace BTCPayServer.Controllers
|
||||
public async Task<IActionResult> ListApps(
|
||||
string storeId,
|
||||
string sortOrder = null,
|
||||
string sortOrderColumn = null
|
||||
string sortOrderColumn = null,
|
||||
bool archived = false
|
||||
)
|
||||
{
|
||||
var store = GetCurrentStore();
|
||||
var apps = await _appService.GetAllApps(GetUserId(), false, store.Id);
|
||||
var apps = (await _appService.GetAllApps(GetUserId(), false, store.Id, archived))
|
||||
.Where(app => app.Archived == archived);
|
||||
|
||||
if (sortOrder != null && sortOrderColumn != null)
|
||||
{
|
||||
apps = apps.OrderByDescending(app =>
|
||||
{
|
||||
switch (sortOrderColumn)
|
||||
return sortOrderColumn switch
|
||||
{
|
||||
case nameof(app.AppName):
|
||||
return app.AppName;
|
||||
case nameof(app.StoreName):
|
||||
return app.StoreName;
|
||||
case nameof(app.AppType):
|
||||
return app.AppType;
|
||||
default:
|
||||
return app.Id;
|
||||
}
|
||||
}).ToArray();
|
||||
nameof(app.AppName) => app.AppName,
|
||||
nameof(app.StoreName) => app.StoreName,
|
||||
nameof(app.AppType) => app.AppType,
|
||||
_ => app.Id
|
||||
};
|
||||
});
|
||||
|
||||
switch (sortOrder)
|
||||
{
|
||||
@@ -105,7 +103,7 @@ namespace BTCPayServer.Controllers
|
||||
ViewData[$"{sortOrderColumn}SortOrder"] = "asc";
|
||||
break;
|
||||
case "asc":
|
||||
apps = apps.Reverse().ToArray();
|
||||
apps = apps.Reverse();
|
||||
ViewData[$"{sortOrderColumn}SortOrder"] = "desc";
|
||||
break;
|
||||
}
|
||||
@@ -113,7 +111,7 @@ namespace BTCPayServer.Controllers
|
||||
|
||||
return View(new ListAppsViewModel
|
||||
{
|
||||
Apps = apps
|
||||
Apps = apps.ToArray()
|
||||
});
|
||||
}
|
||||
|
||||
@@ -161,7 +159,6 @@ namespace BTCPayServer.Controllers
|
||||
TempData[WellKnownTempData.SuccessMessage] = "App successfully created";
|
||||
CreatedAppId = appData.Id;
|
||||
|
||||
|
||||
var url = await type.ConfigureLink(appData);
|
||||
return Redirect(url);
|
||||
}
|
||||
@@ -190,6 +187,36 @@ namespace BTCPayServer.Controllers
|
||||
|
||||
return RedirectToAction(nameof(UIStoresController.Dashboard), "UIStores", new { storeId = app.StoreDataId });
|
||||
}
|
||||
|
||||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
||||
[HttpPost("{appId}/archive")]
|
||||
public async Task<IActionResult> ToggleArchive(string appId)
|
||||
{
|
||||
var app = GetCurrentApp();
|
||||
if (app == null)
|
||||
return NotFound();
|
||||
|
||||
var type = _appService.GetAppType(app.AppType);
|
||||
if (type is null)
|
||||
{
|
||||
return UnprocessableEntity();
|
||||
}
|
||||
|
||||
var archived = !app.Archived;
|
||||
if (await _appService.SetArchived(app, archived))
|
||||
{
|
||||
TempData[WellKnownTempData.SuccessMessage] = archived
|
||||
? "The app has been archived and will no longer appear in the apps list by default."
|
||||
: "The app has been unarchived and will appear in the apps list by default again.";
|
||||
}
|
||||
else
|
||||
{
|
||||
TempData[WellKnownTempData.ErrorMessage] = $"Failed to {(archived ? "archive" : "unarchive")} the app.";
|
||||
}
|
||||
|
||||
var url = await type.ConfigureLink(app);
|
||||
return Redirect(url);
|
||||
}
|
||||
|
||||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
||||
[HttpPost("{appId}/upload-file")]
|
||||
|
||||
@@ -680,6 +680,7 @@ namespace BTCPayServer.Controllers
|
||||
InvoiceExpiration = (int)storeBlob.InvoiceExpiration.TotalMinutes,
|
||||
DefaultCurrency = storeBlob.DefaultCurrency,
|
||||
BOLT11Expiration = (long)storeBlob.RefundBOLT11Expiration.TotalDays,
|
||||
Archived = store.Archived,
|
||||
CanDelete = _Repo.CanDeleteStores()
|
||||
};
|
||||
|
||||
@@ -827,6 +828,23 @@ namespace BTCPayServer.Controllers
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost("{storeId}/archive")]
|
||||
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie, Policy = Policies.CanModifyStoreSettings)]
|
||||
public async Task<IActionResult> ToggleArchive(string storeId)
|
||||
{
|
||||
CurrentStore.Archived = !CurrentStore.Archived;
|
||||
await _Repo.UpdateStore(CurrentStore);
|
||||
|
||||
TempData[WellKnownTempData.SuccessMessage] = CurrentStore.Archived
|
||||
? "The store has been archived and will no longer appear in the stores list by default."
|
||||
: "The store has been unarchived and will appear in the stores list by default again.";
|
||||
|
||||
return RedirectToAction(nameof(GeneralSettings), new
|
||||
{
|
||||
storeId = CurrentStore.Id
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet("{storeId}/delete")]
|
||||
public IActionResult DeleteStore(string storeId)
|
||||
{
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Abstractions.Constants;
|
||||
using BTCPayServer.Abstractions.Models;
|
||||
using BTCPayServer.Client;
|
||||
using BTCPayServer.Data;
|
||||
using BTCPayServer.Models;
|
||||
using BTCPayServer.Models.StoreViewModels;
|
||||
using BTCPayServer.Rating;
|
||||
using BTCPayServer.Services.Rates;
|
||||
@@ -37,6 +35,26 @@ namespace BTCPayServer.Controllers
|
||||
_rateFactory = rateFactory;
|
||||
}
|
||||
|
||||
[HttpGet()]
|
||||
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie, Policy = Policies.CanModifyStoreSettingsUnscoped)]
|
||||
public async Task<IActionResult> ListStores(bool archived = false)
|
||||
{
|
||||
var stores = await _repo.GetStoresByUserId(GetUserId());
|
||||
var vm = new ListStoresViewModel
|
||||
{
|
||||
Stores = stores
|
||||
.Where(s => s.Archived == archived)
|
||||
.Select(s => new ListStoresViewModel.StoreViewModel
|
||||
{
|
||||
StoreId = s.Id,
|
||||
StoreName = s.StoreName,
|
||||
Archived = s.Archived
|
||||
}).ToList(),
|
||||
Archived = archived
|
||||
};
|
||||
return View(vm);
|
||||
}
|
||||
|
||||
[HttpGet("create")]
|
||||
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie, Policy = Policies.CanModifyStoreSettingsUnscoped)]
|
||||
public async Task<IActionResult> CreateStore(bool skipWizard)
|
||||
|
||||
Reference in New Issue
Block a user