/// <summary> /// Deletes the specified item. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> public override bool Delete(WorkflowActivityType item) { var activityService = new WorkflowActivityService((RockContext)this.Context); foreach (var activity in activityService.Queryable().Where(a => a.ActivityTypeId == item.Id)) { activityService.Delete(activity); } return(base.Delete(item)); }
/// <summary> /// Gets the active forms. /// </summary> /// <param name="person">The person.</param> /// <returns></returns> public List <WorkflowAction> GetActiveForms(Person person) { // fetch all the person's alias ids to avoid a join that might be costly var personAliasIds = person.Aliases.Select(a => a.Id).ToList(); // Get all of the active activities that are assigned to the specified person var assignedActiveActivityIdList = new WorkflowActivityService(this.Context as RockContext).Queryable() .Where(a => a.ActivatedDateTime.HasValue && !a.CompletedDateTime.HasValue) .Where(a => (a.AssignedPersonAliasId.HasValue && personAliasIds.Contains(a.AssignedPersonAliasId.Value)) || (a.AssignedGroupId.HasValue && a.AssignedGroup.Members.Any(m => m.PersonId == person.Id))).Select(a => a.Id).ToList(); // Get all of the active form actions with an activity that assigned to the specified person var formActionsQry = GetActiveForms().Where(a => assignedActiveActivityIdList.Contains(a.ActivityId)); // Check security for the action's activity type and workflow type var workflowTypeIds = new Dictionary <int, bool>(); var activityTypeIds = new Dictionary <int, bool>(); var result = formActionsQry.Include(a => a.Activity.Workflow).ToList(); var assignedActivityTypes = result.Select(a => a.ActionTypeCache.ActivityType).Distinct().ToList(); foreach (var assignedActivityType in assignedActivityTypes) { if (!workflowTypeIds.ContainsKey(assignedActivityType.WorkflowTypeId)) { workflowTypeIds.Add(assignedActivityType.WorkflowTypeId, assignedActivityType.WorkflowType.IsAuthorized(Rock.Security.Authorization.VIEW, person)); } if (workflowTypeIds[assignedActivityType.WorkflowTypeId] && !activityTypeIds.ContainsKey(assignedActivityType.Id)) { activityTypeIds.Add(assignedActivityType.Id, assignedActivityType.IsAuthorized(Rock.Security.Authorization.VIEW, person)); } } // Get just the authorized activity types var authorizedActivityTypeIds = activityTypeIds.Where(w => w.Value).Select(w => w.Key).ToList(); // Get the actions that user is authorized to see and that return(result.Where(a => authorizedActivityTypeIds.Contains(a.ActionType.ActivityTypeId)) .ToList()); }