internal static bool HasReviewPermission(UserInfo userInfo, List <int> States) { if (userInfo.IsSuperUser || userInfo.IsInRole("Administrators")) { return(true); } int PortalID = PortalSettings.Current.PortalId; List <int> RolesID = new List <int>(); List <RoleInfo> Roles = RoleController.Instance.GetRoles(PortalID).Cast <RoleInfo>().ToList(); foreach (string Role in userInfo.Roles) { RolesID.Add(Roles.Where(a => a.RoleName == Role).Select(a => a.RoleID).FirstOrDefault()); } if (RolesID.Count > 0 && States == null) { return(WorkflowStatePermission.Query("where (RoleID in (" + string.Join(",", RolesID) + ") or UserID =@0) and AllowAccess=@1", userInfo.UserID, true).ToList().Count > 0); } if (RolesID.Count > 0 && States != null) { return(WorkflowStatePermission.Query("where (RoleID in (" + string.Join(",", RolesID) + ") or UserID =@0) and AllowAccess=@1 and StateID in (" + string.Join(",", States) + ") ", userInfo.UserID, true).Select(a => a.StateID).Distinct().ToList().Count > 0); } return(false); }
public int AddWorkflowStatePermission(WorkflowStatePermission permission, int lastModifiedByUserId) { return(DataProvider.Instance().AddContentWorkflowStatePermission(permission.StateID, permission.PermissionID, permission.RoleID, permission.AllowAccess, permission.UserID, lastModifiedByUserId)); }
internal static List <WorkflowStatePermission> GetStatePermissionsByStateID(int ID) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Workflow + "GetStatePermissionsByStateID", ID); List <WorkflowStatePermission> _WorkflowStatePerm = CacheFactory.Get(CacheKey) as List <WorkflowStatePermission>; if (_WorkflowStatePerm == null) { _WorkflowStatePerm = WorkflowStatePermission.Query("where StateID=@0", ID).ToList(); CacheFactory.Set(CacheKey, _WorkflowStatePerm); } return(_WorkflowStatePerm); }
internal static void DeleteWorkflow(Workflow wflow) { foreach (WorkflowState state in GetAllStatesbyWorkflowID(wflow.ID)) { WorkflowLog.Delete("Where StateID=@0", state.StateID); WorkflowStatePermission.Delete("Where StateID=@0", state.StateID); state.Delete(); } WorkflowPermission.Delete("Where Workflowid=@0", wflow.ID); wflow.Delete(); CacheFactory.Clear(CacheFactory.Keys.Workflow); }
public override void ImportData(ExportImportJob importJob, ImportDto importDto) { if (CheckCancelled(importJob) || CheckPoint.Stage >= 1 || CheckPoint.Completed || CheckPointStageCallback(this)) { return; } var workflowManager = WorkflowManager.Instance; var workflowStateManager = WorkflowStateManager.Instance; var portalId = importJob.PortalId; var importWorkflows = Repository.GetAllItems <ExportWorkflow>().ToList(); var existWorkflows = workflowManager.GetWorkflows(portalId).ToList(); var defaultTabWorkflowId = importWorkflows.FirstOrDefault(w => w.IsDefault)?.WorkflowID ?? 1; CheckPoint.TotalItems = CheckPoint.TotalItems <= 0 ? importWorkflows.Count : CheckPoint.TotalItems; #region importing workflows foreach (var importWorkflow in importWorkflows) { var workflow = existWorkflows.FirstOrDefault(w => w.WorkflowName == importWorkflow.WorkflowName); if (workflow != null) { if (!importWorkflow.IsSystem && importDto.CollisionResolution == CollisionResolution.Overwrite) { if (workflow.Description != importWorkflow.Description || workflow.WorkflowKey != importWorkflow.WorkflowKey) { workflow.Description = importWorkflow.Description; workflow.WorkflowKey = importWorkflow.WorkflowKey; workflowManager.UpdateWorkflow(workflow); Result.AddLogEntry("Updated workflow", workflow.WorkflowName); } } } else { workflow = new Workflow { PortalID = portalId, WorkflowName = importWorkflow.WorkflowName, Description = importWorkflow.Description, WorkflowKey = importWorkflow.WorkflowKey, }; workflowManager.AddWorkflow(workflow); Result.AddLogEntry("Added workflow", workflow.WorkflowName); if (importWorkflow.WorkflowID == defaultTabWorkflowId) { TabWorkflowSettings.Instance.SetDefaultTabWorkflowId(portalId, workflow.WorkflowID); } } importWorkflow.LocalId = workflow.WorkflowID; #region importing workflow states var importStates = Repository.GetRelatedItems <ExportWorkflowState>(importWorkflow.Id).ToList(); foreach (var importState in importStates) { var workflowState = workflow.States.FirstOrDefault(s => s.StateName == importState.StateName); if (workflowState != null) { if (!workflowState.IsSystem) { workflowState.Order = importState.Order; workflowState.IsSystem = false; workflowState.SendNotification = importState.SendNotification; workflowState.SendNotificationToAdministrators = importState.SendNotificationToAdministrators; workflowStateManager.UpdateWorkflowState(workflowState); Result.AddLogEntry("Updated workflow state", workflowState.StateID.ToString()); } } else { workflowState = new WorkflowState { StateName = importState.StateName, WorkflowID = workflow.WorkflowID, Order = importState.Order, IsSystem = importState.IsSystem, SendNotification = importState.SendNotification, SendNotificationToAdministrators = importState.SendNotificationToAdministrators }; WorkflowStateManager.Instance.AddWorkflowState(workflowState); Result.AddLogEntry("Added workflow state", workflowState.StateID.ToString()); } importState.LocalId = workflowState.StateID; #region importin permissions if (!workflowState.IsSystem) { var importPermissions = Repository.GetRelatedItems <ExportWorkflowStatePermission>(importState.Id).ToList(); foreach (var importPermission in importPermissions) { var permissionId = DataProvider.Instance().GetPermissionId( importPermission.PermissionCode, importPermission.PermissionKey, importPermission.PermissionName); if (permissionId != null) { var noRole = Convert.ToInt32(Globals.glbRoleNothing); var userId = UserController.GetUserByName(importDto.PortalId, importPermission.Username)?.UserID; var roleId = Util.GetRoleIdByName(importDto.PortalId, importPermission.RoleID ?? noRole, importPermission.RoleName); var permission = new WorkflowStatePermission { PermissionID = permissionId ?? -1, StateID = workflowState.StateID, RoleID = noRole, UserID = -1, AllowAccess = importPermission.AllowAccess, //TODO: ModuleDefID = ??? what value to set here ? }; if (importPermission.UserID != null && importPermission.UserID > 0 && !string.IsNullOrEmpty(importPermission.Username)) { if (userId == null) { Result.AddLogEntry("Couldn't add tab permission; User is undefined!", $"{importPermission.PermissionKey} - {importPermission.PermissionID}", ReportLevel.Warn); continue; } permission.UserID = userId.Value; } if (importPermission.RoleID != null && importPermission.RoleID > noRole && !string.IsNullOrEmpty(importPermission.RoleName)) { if (roleId == null) { Result.AddLogEntry("Couldn't add tab permission; Role is undefined!", $"{importPermission.PermissionKey} - {importPermission.PermissionID}", ReportLevel.Warn); continue; } permission.RoleID = roleId.Value; } try { var existingPermissions = workflowStateManager.GetWorkflowStatePermissionByState(workflowState.StateID); var local = existingPermissions.FirstOrDefault( x => x.PermissionCode == importPermission.PermissionCode && x.PermissionKey == importPermission.PermissionKey && x.PermissionName.Equals(importPermission.PermissionName, StringComparison.InvariantCultureIgnoreCase) && x.RoleID == roleId && x.UserID == userId); if (local == null) { workflowStateManager.AddWorkflowStatePermission(permission, -1); importPermission.LocalId = permission.WorkflowStatePermissionID; Result.AddLogEntry("Added workflow state permission", permission.WorkflowStatePermissionID.ToString()); } else { importPermission.LocalId = local.WorkflowStatePermissionID; } } catch (Exception ex) { Result.AddLogEntry("Exception adding workflow state permission", ex.Message, ReportLevel.Error); } } } } #endregion } #endregion Repository.UpdateItems(importStates); Result.AddSummary("Imported Workflow", importWorkflows.Count.ToString()); CheckPoint.ProcessedItems++; CheckPointStageCallback(this); // no need to return; very small amount of data processed } #endregion Repository.UpdateItems(importWorkflows); CheckPoint.Stage++; CheckPoint.StageData = null; CheckPoint.Progress = 100; CheckPoint.TotalItems = importWorkflows.Count; CheckPoint.ProcessedItems = importWorkflows.Count; CheckPointStageCallback(this); }
public void AddWorkflowStatePermission(WorkflowStatePermission permission, int userId) { permission.WorkflowStatePermissionID = _workflowStatePermissionsRepository.AddWorkflowStatePermission(permission, userId); }
internal static Workflow UpdateWorkflow(Workflow workflow) { Workflow wflow = new Workflow(); if (workflow.ID == 0) { wflow.Description = workflow.Description; wflow.IsDeleted = workflow.IsDeleted; wflow.Name = workflow.Name; wflow.CreatedBy = workflow.CreatedBy; wflow.CreatedOn = workflow.CreatedOn; wflow.PortalID = workflow.PortalID; wflow.Revisions = 5; wflow.Insert(); UpdateWorkflowState(new WorkflowState { WorkflowID = wflow.ID, IsActive = true, Name = "Draft", Notify = true, Order = 1 }); WorkflowState wState = UpdateWorkflowState(new WorkflowState { WorkflowID = wflow.ID, IsActive = true, Name = "Ready for Review", Notify = true, Order = 2 }); if (wState != null) { DNNModulePermissionInfo DnnPermissionInfo = Vanjaro.Common.Manager.PermissionManager.GetPermissionInfo(PageWorkflowPermission.PERMISSION_CODE).Where(p => p.PermissionKey == PageWorkflowPermission.PERMISSION_REVIEWCONTENT).FirstOrDefault(); WorkflowStatePermission statePerm = new WorkflowStatePermission { StateID = wState.StateID, PermissionID = DnnPermissionInfo.PermissionID, AllowAccess = true }; int PortalID = workflow.PortalID.HasValue ? workflow.PortalID.Value : PortalSettings.Current.PortalId; statePerm.RoleID = RoleController.Instance.GetRoleByName(PortalID, "Administrators").RoleID; statePerm.UserID = null; statePerm.CreatedBy = workflow.CreatedBy; statePerm.CreatedOn = workflow.CreatedOn; statePerm.UpdatedBy = workflow.CreatedBy; statePerm.UpdatedOn = workflow.CreatedOn; statePerm.Insert(); } UpdateWorkflowState(new WorkflowState { WorkflowID = wflow.ID, IsActive = true, Name = "Published", Notify = true, Order = 3 }); } else { wflow = GetWorkflowbyID(workflow.ID); if (wflow != null) { wflow.Description = workflow.Description; wflow.IsDeleted = workflow.IsDeleted; wflow.Name = workflow.Name; wflow.CreatedBy = wflow.CreatedBy; wflow.CreatedOn = wflow.CreatedOn; wflow.DeletedBy = workflow.DeletedBy; wflow.DeletedOn = workflow.DeletedOn; wflow.Revisions = workflow.Revisions; wflow.PortalID = wflow.ID == 1 ? null : workflow.PortalID; wflow.Update(); } } CacheFactory.Clear(CacheFactory.Keys.Workflow); return(wflow); }