Merge branch 'feature/webhooks-page' of github.com:ONLYOFFICE/DocSpace into feature/webhooks-page
This commit is contained in:
commit
6c299e1fff
@ -177,69 +177,9 @@ public class DbWorker
|
||||
return removeObj;
|
||||
}
|
||||
|
||||
public IAsyncEnumerable<WebhooksLog> ReadJournal(int startIndex, int limit, DateTime? deliveryFrom, DateTime? deliveryTo, string hookUri, int? hookId, int? configId, int? eventId, WebhookGroupStatus? webhookGroupStatus)
|
||||
public IAsyncEnumerable<DbWebhooks> ReadJournal(int startIndex, int limit, DateTime? deliveryFrom, DateTime? deliveryTo, string hookUri, int? hookId, int? configId, int? eventId, WebhookGroupStatus? webhookGroupStatus)
|
||||
{
|
||||
var webhooksDbContext = _dbContextFactory.CreateDbContext();
|
||||
|
||||
var q = webhooksDbContext.WebhooksLogs
|
||||
.AsNoTracking()
|
||||
.Where(r => r.TenantId == Tenant);
|
||||
|
||||
if (deliveryFrom.HasValue)
|
||||
{
|
||||
var from = deliveryFrom.Value;
|
||||
q = q.Where(r => r.Delivery >= from);
|
||||
}
|
||||
|
||||
if (deliveryTo.HasValue)
|
||||
{
|
||||
var to = deliveryTo.Value;
|
||||
q = q.Where(r => r.Delivery <= to);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(hookUri))
|
||||
{
|
||||
q = q.Where(r => r.Config.Uri == hookUri);
|
||||
}
|
||||
|
||||
if (hookId != null)
|
||||
{
|
||||
q = q.Where(r => r.WebhookId == hookId);
|
||||
}
|
||||
|
||||
if (configId != null)
|
||||
{
|
||||
q = q.Where(r => r.ConfigId == configId);
|
||||
}
|
||||
|
||||
if (eventId != null)
|
||||
{
|
||||
q = q.Where(r => r.Id == eventId);
|
||||
}
|
||||
|
||||
if (webhookGroupStatus != null && webhookGroupStatus != WebhookGroupStatus.None)
|
||||
{
|
||||
if ((webhookGroupStatus & WebhookGroupStatus.NotSent) != WebhookGroupStatus.NotSent)
|
||||
{
|
||||
q = q.Where(r => r.Status != 0);
|
||||
}
|
||||
if ((webhookGroupStatus & WebhookGroupStatus.Status2xx) != WebhookGroupStatus.Status2xx)
|
||||
{
|
||||
q = q.Where(r => r.Status < 200 || r.Status >= 300);
|
||||
}
|
||||
if ((webhookGroupStatus & WebhookGroupStatus.Status3xx) != WebhookGroupStatus.Status3xx)
|
||||
{
|
||||
q = q.Where(r => r.Status < 300 || r.Status >= 400);
|
||||
}
|
||||
if ((webhookGroupStatus & WebhookGroupStatus.Status4xx) != WebhookGroupStatus.Status4xx)
|
||||
{
|
||||
q = q.Where(r => r.Status < 400 || r.Status >= 500);
|
||||
}
|
||||
if ((webhookGroupStatus & WebhookGroupStatus.Status5xx) != WebhookGroupStatus.Status5xx)
|
||||
{
|
||||
q = q.Where(r => r.Status < 500);
|
||||
}
|
||||
}
|
||||
var q = GetQueryForJournal(deliveryFrom, deliveryTo, hookUri, hookId, configId, eventId, webhookGroupStatus);
|
||||
|
||||
if (startIndex != 0)
|
||||
{
|
||||
@ -251,17 +191,30 @@ public class DbWorker
|
||||
q = q.Take(limit);
|
||||
}
|
||||
|
||||
return q.OrderByDescending(t => t.Id).AsAsyncEnumerable();
|
||||
return q.AsAsyncEnumerable();
|
||||
}
|
||||
|
||||
public async Task<int> GetTotalByQuery(DateTime? deliveryFrom, DateTime? deliveryTo, string hookUri, int? hookId, int? configId, int? eventId, WebhookGroupStatus? webhookGroupStatus)
|
||||
{
|
||||
return await GetQueryForJournal(deliveryFrom, deliveryTo, hookUri, hookId, configId, eventId, webhookGroupStatus).CountAsync();
|
||||
}
|
||||
|
||||
public async Task<WebhooksLog> ReadJournal(int id)
|
||||
{
|
||||
using var webhooksDbContext = _dbContextFactory.CreateDbContext();
|
||||
|
||||
return await webhooksDbContext.WebhooksLogs
|
||||
var fromDb = await webhooksDbContext.WebhooksLogs
|
||||
.AsNoTracking()
|
||||
.Where(it => it.Id == id)
|
||||
.Join(webhooksDbContext.WebhooksConfigs, r => r.ConfigId, r => r.Id, (log, config) => new DbWebhooks { Log = log, Config = config })
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (fromDb != null)
|
||||
{
|
||||
fromDb.Log.Config = fromDb.Config;
|
||||
}
|
||||
|
||||
return fromDb.Log;
|
||||
}
|
||||
|
||||
public async Task<WebhooksLog> WriteToJournal(WebhooksLog webhook)
|
||||
@ -281,7 +234,12 @@ public class DbWorker
|
||||
{
|
||||
using var webhooksDbContext = _dbContextFactory.CreateDbContext();
|
||||
|
||||
var webhook = await webhooksDbContext.WebhooksLogs.Where(t => t.Id == id).FirstOrDefaultAsync();
|
||||
var webhook = await webhooksDbContext.WebhooksLogs
|
||||
.Where(t => t.Id == id)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (webhook != null)
|
||||
{
|
||||
webhook.Status = status;
|
||||
webhook.RequestHeaders = requestHeaders;
|
||||
webhook.ResponsePayload = responsePayload;
|
||||
@ -290,6 +248,7 @@ public class DbWorker
|
||||
|
||||
webhooksDbContext.WebhooksLogs.Update(webhook);
|
||||
await webhooksDbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return webhook;
|
||||
}
|
||||
@ -342,6 +301,80 @@ public class DbWorker
|
||||
|
||||
return _mapper.Map<DbWebhook, Webhook>(webHook);
|
||||
}
|
||||
|
||||
private IQueryable<DbWebhooks> GetQueryForJournal(DateTime? deliveryFrom, DateTime? deliveryTo, string hookUri, int? hookId, int? configId, int? eventId, WebhookGroupStatus? webhookGroupStatus)
|
||||
{
|
||||
var webhooksDbContext = _dbContextFactory.CreateDbContext();
|
||||
|
||||
var q = webhooksDbContext.WebhooksLogs
|
||||
.AsNoTracking()
|
||||
.OrderByDescending(t => t.Id)
|
||||
.Where(r => r.TenantId == Tenant)
|
||||
.Join(webhooksDbContext.WebhooksConfigs.AsNoTracking(), r => r.ConfigId, r => r.Id, (log, config) => new DbWebhooks { Log = log, Config = config });
|
||||
|
||||
if (deliveryFrom.HasValue)
|
||||
{
|
||||
var from = deliveryFrom.Value;
|
||||
q = q.Where(r => r.Log.Delivery >= from);
|
||||
}
|
||||
|
||||
if (deliveryTo.HasValue)
|
||||
{
|
||||
var to = deliveryTo.Value;
|
||||
q = q.Where(r => r.Log.Delivery <= to);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(hookUri))
|
||||
{
|
||||
q = q.Where(r => r.Config.Uri == hookUri);
|
||||
}
|
||||
|
||||
if (hookId != null)
|
||||
{
|
||||
q = q.Where(r => r.Log.WebhookId == hookId);
|
||||
}
|
||||
|
||||
if (configId != null)
|
||||
{
|
||||
q = q.Where(r => r.Log.ConfigId == configId);
|
||||
}
|
||||
|
||||
if (eventId != null)
|
||||
{
|
||||
q = q.Where(r => r.Log.Id == eventId);
|
||||
}
|
||||
|
||||
if (webhookGroupStatus != null && webhookGroupStatus != WebhookGroupStatus.None)
|
||||
{
|
||||
if ((webhookGroupStatus & WebhookGroupStatus.NotSent) != WebhookGroupStatus.NotSent)
|
||||
{
|
||||
q = q.Where(r => r.Log.Status != 0);
|
||||
}
|
||||
if ((webhookGroupStatus & WebhookGroupStatus.Status2xx) != WebhookGroupStatus.Status2xx)
|
||||
{
|
||||
q = q.Where(r => r.Log.Status < 200 || r.Log.Status >= 300);
|
||||
}
|
||||
if ((webhookGroupStatus & WebhookGroupStatus.Status3xx) != WebhookGroupStatus.Status3xx)
|
||||
{
|
||||
q = q.Where(r => r.Log.Status < 300 || r.Log.Status >= 400);
|
||||
}
|
||||
if ((webhookGroupStatus & WebhookGroupStatus.Status4xx) != WebhookGroupStatus.Status4xx)
|
||||
{
|
||||
q = q.Where(r => r.Log.Status < 400 || r.Log.Status >= 500);
|
||||
}
|
||||
if ((webhookGroupStatus & WebhookGroupStatus.Status5xx) != WebhookGroupStatus.Status5xx)
|
||||
{
|
||||
q = q.Where(r => r.Log.Status < 500);
|
||||
}
|
||||
}
|
||||
|
||||
return q;
|
||||
}
|
||||
}
|
||||
public class DbWebhooks
|
||||
{
|
||||
public WebhooksLog Log { get; set; }
|
||||
public WebhooksConfig Config { get; set; }
|
||||
}
|
||||
|
||||
[Flags]
|
||||
|
@ -48,8 +48,6 @@ public static class WebhooksPayloadExtension
|
||||
{
|
||||
public static ModelBuilderWrapper AddWebhooksLog(this ModelBuilderWrapper modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<WebhooksLog>().Navigation(e => e.Config).AutoInclude();
|
||||
|
||||
modelBuilder
|
||||
.Add(MySqlAddWebhooksLog, Provider.MySql)
|
||||
.Add(PgSqlAddWebhooksLog, Provider.PostgreSql);
|
||||
|
@ -24,7 +24,6 @@
|
||||
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
|
||||
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
|
||||
|
||||
namespace ASC.Web.Api.Controllers.Settings;
|
||||
|
||||
public class WebhooksController : BaseSettingsController
|
||||
@ -109,12 +108,16 @@ public class WebhooksController : BaseSettingsController
|
||||
public async IAsyncEnumerable<WebhooksLogDto> GetJournal(DateTime? deliveryFrom, DateTime? deliveryTo, string hookUri, int? webhookId, int? configId, int? eventId, WebhookGroupStatus? groupStatus)
|
||||
{
|
||||
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
||||
|
||||
_context.SetTotalCount(await _webhookDbWorker.GetTotalByQuery(deliveryFrom, deliveryTo, hookUri, webhookId, configId, eventId, groupStatus));
|
||||
|
||||
var startIndex = Convert.ToInt32(_context.StartIndex);
|
||||
var count = Convert.ToInt32(_context.Count);
|
||||
|
||||
await foreach (var j in _webhookDbWorker.ReadJournal(startIndex, count, deliveryFrom, deliveryTo, hookUri, webhookId, configId, eventId, groupStatus))
|
||||
{
|
||||
yield return _mapper.Map<WebhooksLog, WebhooksLogDto>(j);
|
||||
j.Log.Config = j.Config;
|
||||
yield return _mapper.Map<WebhooksLog, WebhooksLogDto>(j.Log);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user