Beispiel #1
0
        public override async Task <Product> CreateAsync(Product resource)
        {
            var createForm = new CreateForm(ProjectRepository,
                                            ProductDefinitionRepository,
                                            StoreRepository,
                                            UserRolesRepository,
                                            UserRepository,
                                            CurrentUserContext);

            if (!createForm.IsValid(resource))
            {
                throw new JsonApiException(createForm.Errors);
            }

            var product = await base.CreateAsync(resource);

            // TODO: figure out why this throws a NullReferenceException
            // await ProjectRepository.UpdateAsync(result.ProjectId, result.Project);

            if (product != null)
            {
                HangfireClient.Enqueue <WorkflowProductService>(service => service.ManageNewProduct(product.Id));
            }
            return(product);
        }
        public override async Task <Project> UpdateAsync(int id, Project resource)
        {
            //If changing organization, validate the change
            var updateForm = new UpdateForm(UserRepository,
                                            GroupRepository,
                                            CurrentUserContext,
                                            OrganizationRepository,
                                            UserRolesRepository,
                                            OrganizationContext,
                                            ProjectRepository);

            if (!updateForm.IsValid(id, resource))
            {
                throw new JsonApiException(updateForm.Errors);
            }

            var project = await base.UpdateAsync(id, resource);

            // If the owner is changing, call the build engine to update the project iam permissions
            if (resource.OwnerId != 0)
            {
                HangfireClient.Enqueue <WorkflowProjectService>(service => service.ReassignUserTasks(project.Id));
            }
            return(project);
        }
Beispiel #3
0
        public override async Task <User> CreateAsync(User resource)
        {
            User user = await base.CreateAsync(resource);

            if (user != null)
            {
                HangfireClient.Enqueue <WorkflowSecuritySyncService>(service => service.SyncNewUser(user.Id));
            }
            return(user);
        }
Beispiel #4
0
        public override async Task <bool> DeleteAsync(Guid id)
        {
            var products = await GetAsync();

            var product = products.SingleOrDefault(p => p.Id == id);

            if (product != null)
            {
                HangfireClient.Enqueue <WorkflowProductService>(service => service.ManageDeletedProduct(product.Id, product.ProjectId));
            }

            return(await base.DeleteAsync(id));
        }
Beispiel #5
0
        public async Task <WorkflowDefinition> RunActionForProductAsync(Guid id, string type)
        {
            User currentUser = UserRepository.CurrentUser;
            var  product     = await GetProductForActions(id);

            if (product == null)
            {
                return(null);
            }

            if (currentUser.Id != product.Project.OwnerId)
            {
                throw new Exception("Unable to run action.  Current user is not the project owner");
            }

            if (product.ProductWorkflow == null)
            {
                // No running workflow.  Start one.
                int?workflowDefinitionId = GetWorkflowDefinitionIdForType(product, type);

                if (workflowDefinitionId.HasValue)
                {
                    HangfireClient.Enqueue <WorkflowProductService>(service => service.StartProductWorkflow(id, workflowDefinitionId.Value));
                    return(await WorkflowDefinitionRepository.GetAsync(workflowDefinitionId.Value));
                }

                throw new Exception($"Type '{type}' does not have workflow defined");
            }

            // Handle special case for "Cancel" action
            if (type == "Cancel")
            {
                var wd = await GetExecutingWorkflowDefintion(product);

                if (wd == null)
                {
                    throw new Exception("Could not find workflow definition!");
                }

                if (wd.Type == WorkflowType.Startup)
                {
                    throw new Exception("Cannot cancel a startup workflow");
                }

                HangfireClient.Enqueue <WorkflowProductService>(service => service.StopProductWorkflow(id, product.ProjectId, ProductTransitionType.CancelWorkflow));
                return(wd);
            }

            // Trying to start an action workflow while one is already running
            throw new Exception("Cannot start a workflow while one is running");
        }
Beispiel #6
0
        public override async Task <bool> DeleteAsync(Guid id)
        {
            var product = await GetProductForTasks(id);

            if (product != null)
            {
                // Force delete of UserTasks instead of allowing cascade delete so that notifications will be sent.
                var userTasks = product.UserTasks.ToList();
                foreach (var userTask in userTasks)
                {
                    Log.Debug($"Force Delete UserTask: product=${id}, userId={userTask.UserId}, userTaskId={userTask.Id}");
                    await this.UserTaskRepostiory.DeleteAsync(userTask.Id);
                }
                HangfireClient.Enqueue <WorkflowProductService>(service => service.ManageDeletedProduct(product.Id, product.ProjectId));
            }

            return(await base.DeleteAsync(id));
        }
        public override async Task <Project> CreateAsync(Project resource)
        {
            var createForm = new CreateForm(UserRepository,
                                            GroupRepository,
                                            CurrentUserContext,
                                            UserRolesRepository,
                                            OrganizationRepository);

            if (!createForm.IsValid(resource))
            {
                throw new JsonApiException(createForm.Errors);
            }
            var project = await base.CreateAsync(resource);

            if (project != null)
            {
                HangfireClient.Enqueue <BuildEngineProjectService>(service => service.ManageProject(project.Id, null));
            }
            return(project);
        }
Beispiel #8
0
        public async Task RunActionForProductsAsync(IEnumerable <Guid> ids, string type)
        {
            User currentUser = UserRepository.CurrentUser;
            var  products    = await ProductRepository.Get()
                               .Where(p => ids.Contains(p.Id))
                               .Include(p => p.ProductWorkflow)
                               .ThenInclude(pw => pw.Scheme)
                               .Include(p => p.Project)
                               .ThenInclude(pr => pr.Owner)
                               .Include(p => p.ProductDefinition).ToListAsync();

            var productWorflowDefinitions = (from product in products
                                             let workflowDefinitionId = GetWorkflowDefinitionIdForType(product, type)
                                                                        where ProductCanRunAction(workflowDefinitionId, product, type, currentUser.Id)
                                                                        select new ProductWorkflowDefinition {
                Id = product.Id, WorkflowDefinitionId = workflowDefinitionId.Value
            }).ToList();

            foreach (var pwd in productWorflowDefinitions)
            {
                HangfireClient.Enqueue <WorkflowProductService>(service => service.StartProductWorkflow(pwd.Id, pwd.WorkflowDefinitionId));
            }
        }
 public void AddTokenUse(Project project, User user, String use)
 {
     HangfireClient.Enqueue <WorkflowProjectService>(service => service.AddTokenUse(project.Id, user.Id, use));
 }