Esempio n. 1
0
        public void Promote(string id)
        {
            ErrorStack entity = GetEntity(id);

            if (entity == null)
            {
                throw new HttpResponseException(base.NotFoundErrorResponseMessage(id));
            }

            if (!_billingManager.HasPremiumFeatures(entity.OrganizationId))
            {
                throw new HttpResponseException(PlanLimitReached("Promote to External is a premium feature used to promote an error stack to an external system. Please upgrade your plan to enable this feature."));
            }

            List <ProjectHook> promotedProjectHooks = _projectHookRepository.GetByProjectId(entity.ProjectId).Where(p => p.EventTypes.Contains(ProjectHookRepository.EventTypes.StackPromoted)).ToList();

            if (!promotedProjectHooks.Any())
            {
                throw new HttpResponseException(Request != null
                    ? Request.CreateErrorResponse(HttpStatusCode.NotImplemented, "No promoted web hooks are configured for this project. Please add a promoted web hook to use this feature.")
                    : new HttpResponseMessage(HttpStatusCode.NotImplemented));
            }

            using (IMessageProducer messageProducer = _messageFactory.CreateMessageProducer()) {
                foreach (ProjectHook hook in promotedProjectHooks)
                {
                    messageProducer.Publish(new WebHookNotification {
                        ProjectId = hook.ProjectId,
                        Url       = hook.Url,
                        Data      = WebHookErrorStack.FromErrorStack(entity, _projectRepository, _organizationRepository)
                    });
                }
            }
        }
Esempio n. 2
0
        protected override PermissionResult CanAdd(WebHook value)
        {
            if (String.IsNullOrEmpty(value.Url) || value.EventTypes.Length == 0)
            {
                return(PermissionResult.Deny);
            }

            if (String.IsNullOrEmpty(value.ProjectId) && String.IsNullOrEmpty(value.OrganizationId))
            {
                return(PermissionResult.Deny);
            }

            Project project = null;

            if (!String.IsNullOrEmpty(value.ProjectId))
            {
                project = _projectRepository.GetById(value.ProjectId, true);
                if (!IsInProject(project))
                {
                    return(PermissionResult.DenyWithMessage("Invalid project id specified."));
                }
            }

            if (!String.IsNullOrEmpty(value.OrganizationId) && !IsInOrganization(value.OrganizationId))
            {
                return(PermissionResult.DenyWithMessage("Invalid organization id specified."));
            }

            if (!_billingManager.HasPremiumFeatures(project != null ? project.OrganizationId : value.OrganizationId))
            {
                return(PermissionResult.DenyWithPlanLimitReached("Please upgrade your plan to add integrations."));
            }

            return(PermissionResult.Allow);
        }
Esempio n. 3
0
        public IHttpActionResult Promote(string id)
        {
            if (String.IsNullOrEmpty(id))
            {
                return(NotFound());
            }

            Stack stack = _stackRepository.GetById(id);

            if (stack == null || !CanAccessOrganization(stack.OrganizationId))
            {
                return(NotFound());
            }

            if (!_billingManager.HasPremiumFeatures(stack.OrganizationId))
            {
                return(PlanLimitReached("Promote to External is a premium feature used to promote an error stack to an external system. Please upgrade your plan to enable this feature."));
            }

            List <WebHook> promotedProjectHooks = _webHookRepository.GetByProjectId(stack.ProjectId).Where(p => p.EventTypes.Contains(WebHookRepository.EventTypes.StackPromoted)).ToList();

            if (!promotedProjectHooks.Any())
            {
                return(NotImplemented("No promoted web hooks are configured for this project. Please add a promoted web hook to use this feature."));
            }

            foreach (WebHook hook in promotedProjectHooks)
            {
                var context = new WebHookDataContext(hook.Version, stack, isNew: stack.TotalOccurrences == 1, isRegression: stack.IsRegressed);
                _webHookNotificationQueue.Enqueue(new WebHookNotification {
                    OrganizationId = hook.OrganizationId,
                    ProjectId      = hook.ProjectId,
                    Url            = hook.Url,
                    Data           = _webHookDataPluginManager.CreateFromStack(context)
                });
                // TODO: Add stats metrics for webhooks.
            }

            return(Ok());
        }
        public IHttpActionResult Promote(string id)
        {
            if (String.IsNullOrEmpty(id))
            {
                return(BadRequest());
            }

            Stack stack = _stackRepository.GetById(id);

            if (stack == null || !CanAccessOrganization(stack.OrganizationId))
            {
                return(BadRequest());
            }

            if (!_billingManager.HasPremiumFeatures(stack.OrganizationId))
            {
                return(PlanLimitReached("Promote to External is a premium feature used to promote an error stack to an external system. Please upgrade your plan to enable this feature."));
            }

            List <WebHook> promotedProjectHooks = _webHookRepository.GetByProjectId(stack.ProjectId).Where(p => p.EventTypes.Contains(WebHookRepository.EventTypes.StackPromoted)).ToList();

            if (!promotedProjectHooks.Any())
            {
                return(NotImplemented("No promoted web hooks are configured for this project. Please add a promoted web hook to use this feature."));
            }

            foreach (WebHook hook in promotedProjectHooks)
            {
                _webHookNotificationQueue.EnqueueAsync(new WebHookNotification {
                    ProjectId = hook.ProjectId,
                    Url       = hook.Url,
                    Data      = WebHookStack.FromStack(stack, _projectRepository, _organizationRepository)
                });
            }

            return(Ok());
        }