Ejemplo n.º 1
0
        /// <summary>
        /// Gets the details that allow editing of a form template. This returns
        /// data that might be considered sensitive and should only be returned
        /// when the individual has edit permissions to the template.
        /// </summary>
        /// <param name="template">The template that will be edited.</param>
        /// <param name="rockContext">The database context to use for data queries.</param>
        /// <returns>A <see cref="TemplateEditDetailViewModel"/> view model that represents the form template.</returns>
        private TemplateEditDetailViewModel GetTemplateEditViewModel(WorkflowFormBuilderTemplate template, RockContext rockContext)
        {
            var formConfirmationEmail = template.ConfirmationEmailSettingsJson?.FromJsonOrNull <Rock.Workflow.FormBuilder.FormConfirmationEmailSettings>();
            var confirmationEmail     = formConfirmationEmail?.ToViewModel(rockContext);

            // Special logic to translate the enum values into values that can
            // be used by the recipient picker.
            if (formConfirmationEmail.Destination == Rock.Workflow.FormBuilder.FormConfirmationEmailDestination.Person)
            {
                confirmationEmail.RecipientAttributeGuid = RecipientPersonGuid;
            }
            else if (formConfirmationEmail.Destination == Rock.Workflow.FormBuilder.FormConfirmationEmailDestination.Spouse)
            {
                confirmationEmail.RecipientAttributeGuid = RecipientSpouseGuid;
            }

            return(new TemplateEditDetailViewModel
            {
                Name = template.Name,
                Description = template.Description,
                IsActive = template.IsActive,
                IsLoginRequired = template.IsLoginRequired,
                FormHeader = template.FormHeader,
                FormFooter = template.FormFooter,
                AllowPersonEntry = template.AllowPersonEntry,
                PersonEntry = template.PersonEntrySettingsJson?.FromJsonOrNull <Rock.Workflow.FormBuilder.FormPersonEntrySettings>().ToViewModel(),
                ConfirmationEmail = confirmationEmail,
                CompletionAction = template.CompletionSettingsJson?.FromJsonOrNull <Rock.Workflow.FormBuilder.FormCompletionActionSettings>().ToViewModel()
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the read-only details about the template that will be used to
        /// display the template to the individual before editing.
        /// </summary>
        /// <param name="template">The form template to be represented by the view model.</param>
        /// <param name="rockContext">The database context to use for data queries.</param>
        /// <returns>A <see cref="TemplateDetailViewModel"/> that represents the form template.</returns>
        private TemplateDetailViewModel GetTemplateDetailViewModel(WorkflowFormBuilderTemplate template, RockContext rockContext)
        {
            // Find all workflow types that reference this form template. Do not
            // perform any security checking since we are only showing the name.
            var usedBy = new WorkflowTypeService(rockContext).Queryable()
                         .Where(t => t.FormBuilderTemplateId.HasValue && t.FormBuilderTemplateId == template.Id)
                         .Select(t => new ListItemViewModel
            {
                Value = t.Guid.ToString(),
                Text  = t.Name
            })
                         .ToList();

            return(new TemplateDetailViewModel
            {
                AuditDetails = template.GetAuditDetailViewModel(),
                Description = template.Description,
                IsActive = template.IsActive,
                Name = template.Name,
                UsedBy = usedBy
            });
        }
Ejemplo n.º 3
0
        public BlockActionResult SaveTemplate(Guid guid, TemplateEditDetailViewModel template)
        {
            using (var rockContext = new RockContext())
            {
                var isNew           = false;
                var templateService = new WorkflowFormBuilderTemplateService(rockContext);
                WorkflowFormBuilderTemplate formTemplate;

                // If we are provided an empty guid (not null) then we treat that
                // to mean create a new template.
                if (guid == Guid.Empty)
                {
                    formTemplate = new WorkflowFormBuilderTemplate();
                    templateService.Add(formTemplate);
                    isNew = true;
                }
                else
                {
                    formTemplate = templateService.Get(guid);
                }

                // Perform a check to see if we now have a valid template object
                // and that the user has permission to edit/create it.
                if (formTemplate == null || !formTemplate.IsAuthorized(Authorization.EDIT, RequestContext.CurrentPerson))
                {
                    return(ActionBadRequest("Invalid template."));
                }

                // Store all the template details.
                formTemplate.Name                    = template.Name.Trim();
                formTemplate.Description             = template.Description?.Trim();
                formTemplate.IsActive                = template.IsActive;
                formTemplate.IsLoginRequired         = template.IsLoginRequired;
                formTemplate.FormHeader              = template.FormHeader?.Trim();
                formTemplate.FormFooter              = template.FormFooter?.Trim();
                formTemplate.AllowPersonEntry        = template.AllowPersonEntry;
                formTemplate.PersonEntrySettingsJson = template.PersonEntry?.FromViewModel().ToJson();
                formTemplate.CompletionSettingsJson  = template.CompletionAction?.FromViewModel().ToJson();

                var confirmationEmail = template.ConfirmationEmail?.FromViewModel(rockContext);

                // Special check for template logic. We don't have attributes yet
                // so check if the confirmation e-mail uses the special values to
                // indicate which attribute to be used at runtime. If we find one
                // of those special values then translate it to the enum.
                if (confirmationEmail != null)
                {
                    if (confirmationEmail.RecipientAttributeGuid == RecipientPersonGuid)
                    {
                        confirmationEmail.Destination            = Rock.Workflow.FormBuilder.FormConfirmationEmailDestination.Person;
                        confirmationEmail.RecipientAttributeGuid = null;
                    }
                    else if (confirmationEmail.RecipientAttributeGuid == RecipientSpouseGuid)
                    {
                        confirmationEmail.Destination            = Rock.Workflow.FormBuilder.FormConfirmationEmailDestination.Spouse;
                        confirmationEmail.RecipientAttributeGuid = null;
                    }
                }

                formTemplate.ConfirmationEmailSettingsJson = confirmationEmail?.ToJson();

                rockContext.SaveChanges();

                if (isNew)
                {
                    return(ActionContent(System.Net.HttpStatusCode.Created, this.GetCurrentPageUrl(new Dictionary <string, string>
                    {
                        ["FormTemplateId"] = formTemplate.Id.ToString()
                    })));
                }

                // Ensure navigation properties will work now.
                formTemplate = templateService.Get(formTemplate.Id);

                return(ActionOk(GetTemplateDetailViewModel(formTemplate, rockContext)));
            }
        }