private void CheckIfPermissionsGranted(WebhookSubscription webhookSubscription)
        {
            if (webhookSubscription.Webhooks.IsNullOrEmpty())
            {
                return;
            }

            foreach (var webhookDefinition in webhookSubscription.Webhooks)
            {
                CheckPermissions(webhookSubscription.TenantId, webhookDefinition);
            }
        }
        private async Task CheckIfPermissionsGrantedAsync(WebhookSubscription webhookSubscription)
        {
            if (webhookSubscription.Webhooks.IsNullOrEmpty())
            {
                return;
            }

            foreach (var webhookDefinition in webhookSubscription.Webhooks)
            {
                await CheckPermissionsAsync(webhookSubscription.TenantId, webhookDefinition);
            }
        }
Exemple #3
0
 public static WebhookSubscriptionInfo ToWebhookSubscriptionInfo(this WebhookSubscription webhookSubscription)
 {
     return(new WebhookSubscriptionInfo
     {
         Id = webhookSubscription.Id,
         TenantId = webhookSubscription.TenantId,
         IsActive = webhookSubscription.IsActive,
         Secret = webhookSubscription.Secret,
         WebhookUri = webhookSubscription.WebhookUri,
         Webhooks = webhookSubscription.Webhooks.ToJsonString(),
         Headers = webhookSubscription.Headers.ToJsonString()
     });
 }
        public void AddOrUpdateSubscription(WebhookSubscription webhookSubscription)
        {
            CheckIfPermissionsGranted(webhookSubscription);

            if (webhookSubscription.Id == default)
            {
                webhookSubscription.Id     = _guidGenerator.Create();
                webhookSubscription.Secret = WebhookSubscriptionSecretPrefix + Guid.NewGuid().ToString().Replace("-", "");
                WebhookSubscriptionsStore.Insert(webhookSubscription.ToWebhookSubscriptionInfo());
            }
            else
            {
                var subscription = WebhookSubscriptionsStore.Get(webhookSubscription.Id);
                subscription.WebhookUri = webhookSubscription.WebhookUri;
                subscription.Webhooks   = webhookSubscription.Webhooks.ToJsonString();
                subscription.Headers    = webhookSubscription.Headers.ToJsonString();
                WebhookSubscriptionsStore.Update(subscription);
            }
        }
        public virtual async Task AddOrUpdateSubscriptionAsync(WebhookSubscription webhookSubscription)
        {
            await CheckIfPermissionsGrantedAsync(webhookSubscription);

            if (webhookSubscription.Id == default)
            {
                webhookSubscription.Id     = _guidGenerator.Create();
                webhookSubscription.Secret = WebhookSubscriptionSecretPrefix + Guid.NewGuid().ToString("N");
                await WebhookSubscriptionsStore.InsertAsync(webhookSubscription.ToWebhookSubscriptionInfo());
            }
            else
            {
                var subscription = await WebhookSubscriptionsStore.GetAsync(webhookSubscription.Id);

                subscription.WebhookUri = webhookSubscription.WebhookUri;
                subscription.Webhooks   = webhookSubscription.Webhooks.ToJsonString();
                subscription.Headers    = webhookSubscription.Headers.ToJsonString();
                await WebhookSubscriptionsStore.UpdateAsync(subscription);
            }
        }
        public virtual void AddOrUpdateSubscription(WebhookSubscription webhookSubscription)
        {
            UnitOfWorkManager.WithUnitOfWork(() =>
            {
                CheckIfPermissionsGranted(webhookSubscription);

                if (webhookSubscription.Id == default)
                {
                    webhookSubscription.Id     = _guidGenerator.Create();
                    webhookSubscription.Secret = WebhookSubscriptionSecretPrefix + Guid.NewGuid().ToString("N");
                    WebhookSubscriptionsStore.Insert(webhookSubscription.ToWebhookSubscriptionInfo());
                }
                else
                {
                    var subscription        = WebhookSubscriptionsStore.Get(webhookSubscription.Id);
                    subscription.WebhookUri = webhookSubscription.WebhookUri;
                    subscription.Webhooks   = webhookSubscription.Webhooks.ToJsonString();
                    subscription.Headers    = webhookSubscription.Headers.ToJsonString();
                    WebhookSubscriptionsStore.Update(subscription);
                }
            });
        }