private void editStateCodeActivity_ExecuteCode(object sender, EventArgs e) { if (!PermissionsFacade.GetPermissionsForCurrentUser(EntityToken).Contains(PermissionType.Publish)) { var formData = WorkflowFacade.GetFormData(InstanceId, true); if (formData.ExcludedEvents == null) { formData.ExcludedEvents = new List <string>(); } formData.ExcludedEvents.Add("SaveAndPublish"); } IPage selectedPage; if (!BindingExist("SelectedPage")) { selectedPage = GetDataItemFromEntityToken <IPage>(); if (selectedPage.PublicationStatus == GenericPublishProcessController.Published) { selectedPage.PublicationStatus = GenericPublishProcessController.Draft; } Bindings.Add("SelectedPage", selectedPage); } else { selectedPage = GetBinding <IPage>("SelectedPage"); } if (!BindingExist("UrlTitleIsRequired")) { var isRootPage = PageManager.GetParentId(selectedPage.Id) == Guid.Empty; Bindings["UrlTitleIsRequired"] = !isRootPage; Bindings["IsRootPage"] = isRootPage; } IFormMarkupProvider markupProvider = new FormDefinitionFileMarkupProvider(@"\Administrative\EditPage.xml"); XDocument formDocument; using (var reader = markupProvider.GetReader()) { formDocument = XDocument.Load(reader); } var bindingsXElement = formDocument.Root.Element(DataTypeDescriptorFormsHelper.CmsNamespace + FormKeyTagNames.Bindings); var layoutXElement = formDocument.Root.Element(DataTypeDescriptorFormsHelper.CmsNamespace + FormKeyTagNames.Layout); var tabPanelsXElement = layoutXElement.Element(DataTypeDescriptorFormsHelper.MainNamespace + "TabPanels"); IEnumerable <ICompositionContainer> compositionContainers = selectedPage.GetAllowedMetaDataContainers().Evaluate(); var compositionTabs = new Dictionary <Guid, XElement>(); foreach (var compositionContainer in compositionContainers) { var element = new XElement(Namespaces.BindingFormsStdUiControls10 + "PlaceHolder"); element.Add(new XAttribute("Label", StringResourceSystemFacade.ParseString(compositionContainer.Label))); compositionTabs.Add(compositionContainer.Id, element); } var clientValidationRules = new Dictionary <string, List <ClientValidationRule> >(); var pageMetaDataDefinitions = selectedPage.GetAllowedMetaDataDefinitions(); foreach (var pageMetaDataDefinition in pageMetaDataDefinitions) { var metaDatTypeId = pageMetaDataDefinition.MetaDataTypeId; var dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(metaDatTypeId); Verify.IsNotNull(dataTypeDescriptor, "Failed to get meta data type by id '{0}'. If data type was purposely removed, in order to fix this exception you should remove IPageMetaDataDefinition records that reference this data type.", metaDatTypeId); var metaDataType = TypeManager.TryGetType(dataTypeDescriptor.TypeManagerTypeName); Verify.IsNotNull(metaDataType, "Failed to get meta data type '{0}', id: {1}. If it has been removed, references from '{2}' have to be removed as well", dataTypeDescriptor.TypeManagerTypeName, metaDatTypeId, typeof(IPageMetaDataDefinition).Name); var helper = CreateDataTypeDescriptorFormsHelper(pageMetaDataDefinition, dataTypeDescriptor); var metaData = selectedPage.GetMetaData(pageMetaDataDefinition.Name, metaDataType); if (metaData == null) { metaData = DataFacade.BuildNew(metaDataType); PageMetaDataFacade.AssignMetaDataSpecificValues(metaData, pageMetaDataDefinition.Name, selectedPage); var localizedData = metaData as ILocalizedControlled; if (localizedData != null) { localizedData.SourceCultureName = UserSettings.ActiveLocaleCultureInfo.Name; } var publishControlled = metaData as IPublishControlled; publishControlled.PublicationStatus = GenericPublishProcessController.Draft; helper.UpdateWithNewBindings(Bindings); helper.ObjectToBindings(metaData, Bindings); } else { helper.UpdateWithBindings(metaData, Bindings); } bindingsXElement.Add(helper.BindingXml.Elements()); compositionTabs[pageMetaDataDefinition.MetaDataContainerId].Add(helper.PanelXml); clientValidationRules.AddDictionary(helper.GetBindingsValidationRules(metaData)); } var previewTabPanel = tabPanelsXElement.Elements().Last(); foreach (var element in compositionTabs.Values) { previewTabPanel.AddBeforeSelf(element); } IDictionary <string, string> transitionNames = new Dictionary <string, string>(); transitionNames.Add(GenericPublishProcessController.Draft, StringResourceSystemFacade.GetString("Composite.Management", "PublishingStatus.draft")); transitionNames.Add(GenericPublishProcessController.AwaitingApproval, StringResourceSystemFacade.GetString("Composite.Management", "PublishingStatus.awaitingApproval")); var username = UserValidationFacade.GetUsername(); var userPermissionDefinitions = PermissionTypeFacade.GetUserPermissionDefinitions(username); var userGroupPermissionDefinitions = PermissionTypeFacade.GetUserGroupPermissionDefinitions(username); var currentPermissionTypes = PermissionTypeFacade.GetCurrentPermissionTypes(UserValidationFacade.GetUserToken(), EntityToken, userPermissionDefinitions, userGroupPermissionDefinitions); foreach (var permissionType in currentPermissionTypes) { if (GenericPublishProcessController.AwaitingPublicationActionPermissionType.Contains(permissionType)) { transitionNames.Add(GenericPublishProcessController.AwaitingPublication, StringResourceSystemFacade.GetString("Composite.Management", "PublishingStatus.awaitingPublication")); break; } } var contents = DataFacade.GetData <IPagePlaceholderContent>(false) .Where(f => f.PageId == selectedPage.Id && f.VersionId == selectedPage.VersionId) .ToList(); var namedXhtmlFragments = contents.ToDictionary(content => content.PlaceHolderId, content => content.Content ?? ""); UpdateBinding("SelectablePageTypeIds", GetSelectablePageTypes()); UpdateBinding("SelectableTemplateIds", GetSelectablePageTemplates()); UpdateBinding("NamedXhtmlFragments", namedXhtmlFragments); UpdateBinding("StateOptions", transitionNames); var formDefinition = formDocument.GetDocumentAsString(); DeliverFormData( selectedPage.Title, StandardUiContainerTypes.Document, formDefinition, Bindings, clientValidationRules ); }
/// <exclude /> public static FlowToken Execute(EntityToken entityToken, ActionToken actionToken, FlowControllerServicesContainer flowControllerServicesContainer, TaskManagerEvent taskManagerEvent) { if (entityToken == null) { throw new ArgumentNullException("entityToken"); } if (actionToken == null) { throw new ArgumentNullException("actionToken"); } AddEntityTokenToContext(entityToken); string username = UserValidationFacade.GetUsername(); #if NO_SECURITY #else HookingFacade.EnsureInitialization(); IEnumerable <UserPermissionDefinition> userPermissionDefinitions = PermissionTypeFacade.GetUserPermissionDefinitions(username); IEnumerable <UserGroupPermissionDefinition> userGroupPermissionDefinitions = PermissionTypeFacade.GetUserGroupPermissionDefinitions(username); SecurityResult securityResult = SecurityResolver.Resolve(UserValidationFacade.GetUserToken(), actionToken, entityToken, userPermissionDefinitions, userGroupPermissionDefinitions); if (securityResult != SecurityResult.Allowed && !(entityToken is SecurityViolationWorkflowEntityToken)) { return(ExecuteSecurityViolation(actionToken, entityToken, flowControllerServicesContainer)); } #endif bool ignoreLocking = actionToken.IsIgnoreEntityTokenLocking(); if (!ignoreLocking && ActionLockingFacade.IsLocked(entityToken)) { return(ExecuteEntityTokenLocked(actionToken, entityToken, flowControllerServicesContainer)); } IActionExecutor actionExecutor = ActionExecutorCache.GetActionExecutor(actionToken); ActionEventSystemFacade.FireOnBeforeActionExecution(entityToken, actionToken); FlowToken flowToken; using (TaskContainer taskContainer = TaskManagerFacade.CreateNewTasks(entityToken, actionToken, taskManagerEvent)) { ITaskManagerFlowControllerService taskManagerService = null; if (flowControllerServicesContainer.GetService(typeof(ITaskManagerFlowControllerService)) == null) { taskManagerService = new TaskManagerFlowControllerService(taskContainer); flowControllerServicesContainer.AddService(taskManagerService); } try { if (actionExecutor is IActionExecutorSerializedParameters) { string serializedEntityToken = EntityTokenSerializer.Serialize(entityToken); string serializedActionToken = ActionTokenSerializer.Serialize(actionToken); flowToken = Execute(actionExecutor as IActionExecutorSerializedParameters, serializedEntityToken, serializedActionToken, actionToken, flowControllerServicesContainer); } else { flowToken = Execute(actionExecutor, entityToken, actionToken, flowControllerServicesContainer); } } finally { if (taskManagerService != null) { flowControllerServicesContainer.RemoveService(taskManagerService); } } taskContainer.SetOnIdleTaskManagerEvent(new FlowTaskManagerEvent(flowToken)); taskContainer.UpdateTasksWithFlowToken(flowToken); taskContainer.SaveTasks(); } ActionEventSystemFacade.FireOnAfterActionExecution(entityToken, actionToken, flowToken); IManagementConsoleMessageService managementConsoleMessageService = flowControllerServicesContainer .GetService <IManagementConsoleMessageService>(); if (managementConsoleMessageService != null) { FlowControllerFacade.RegisterNewFlowInformation(flowToken, entityToken, actionToken, managementConsoleMessageService.CurrentConsoleId); } else { Log.LogWarning(nameof(ActionExecutorFacade), "Missing ManagementConsoleMessageService, can not register the flow"); } return(flowToken); }
private static Dictionary <string, string> GetAvailablePublishingFlowTransitions(EntityToken entityToken) { var transitionNames = new Dictionary <string, string> { { GenericPublishProcessController.Draft, LocalizationFiles.Composite_Management.PublishingStatus_draft }, { GenericPublishProcessController.AwaitingApproval, LocalizationFiles.Composite_Management.PublishingStatus_awaitingApproval } }; var username = UserValidationFacade.GetUsername(); var userPermissionDefinitions = PermissionTypeFacade.GetUserPermissionDefinitions(username); var userGroupPermissionDefinition = PermissionTypeFacade.GetUserGroupPermissionDefinitions(username); var currentPermissionTypes = PermissionTypeFacade.GetCurrentPermissionTypes(UserValidationFacade.GetUserToken(), entityToken, userPermissionDefinitions, userGroupPermissionDefinition); foreach (var permissionType in currentPermissionTypes) { if (GenericPublishProcessController.AwaitingPublicationActionPermissionType.Contains(permissionType)) { transitionNames.Add(GenericPublishProcessController.AwaitingPublication, LocalizationFiles.Composite_Management.PublishingStatus_awaitingPublication); break; } } return(transitionNames); }