Local Greenfield Client for Plugins (#2410)

* wip

* Local GreenField Client for Plugins

* support notification handlers being missing

* Initial support for scoped btcpay client

* test out scoped local client

* wip

* small fix

* Throw exception if using local greenfield client and it has not been implemented yet

* adapt based on new changes in BTCPay

* update

* fix tests

* Allow Local client to bypass authorization handler

* Add Misc endpoints to Local API Client

* Add new endpoints

* Apply code review changes
This commit is contained in:
Andrew Camilleri
2021-07-27 14:11:47 +02:00
committed by GitHub
parent 14e4d2d675
commit ba165ddd4f
22 changed files with 1065 additions and 106 deletions

View File

@@ -71,7 +71,7 @@ namespace BTCPayServer.Services.Notifications
var queryables = GetNotificationsQueryable(dbContext, query);
return (Items: (await queryables.withPaging.ToListAsync()).Select(ToViewModel).ToList(),
return (Items: (await queryables.withPaging.ToListAsync()).Select(ToViewModel).Where(model => model != null).ToList(),
Count: await queryables.withoutPaging.CountAsync());
}
@@ -125,7 +125,7 @@ namespace BTCPayServer.Services.Notifications
await dbContext.SaveChangesAsync();
InvalidateNotificationCache(userIds.ToArray());
return items.Select(ToViewModel).ToList();
return items.Select(ToViewModel).Where(model => model != null).ToList();
}
public async Task Remove(NotificationsQuery notificationsQuery)
@@ -144,6 +144,8 @@ namespace BTCPayServer.Services.Notifications
private NotificationViewModel ToViewModel(NotificationData data)
{
var handler = GetHandler(data.NotificationType);
if (handler is null)
return null;
var notification = JsonConvert.DeserializeObject(ZipUtils.Unzip(data.Blob), handler.NotificationBlobType);
var obj = new NotificationViewModel {Id = data.Id, Created = data.Created, Seen = data.Seen};
handler.FillViewModel(notification, obj);
@@ -152,9 +154,8 @@ namespace BTCPayServer.Services.Notifications
public INotificationHandler GetHandler(string notificationId)
{
if (_handlersByNotificationType.TryGetValue(notificationId, out var h))
return h;
throw new InvalidOperationException($"No INotificationHandler found for {notificationId}");
_handlersByNotificationType.TryGetValue(notificationId, out var h);
return h;
}
}