diff --git a/src/components/Container/ManageEmailsPage.vue b/src/components/Container/ManageEmailsPage.vue index 654414346..0326b143f 100644 --- a/src/components/Container/ManageEmailsPage.vue +++ b/src/components/Container/ManageEmailsPage.vue @@ -350,35 +350,16 @@ export default { this.currentTemplate = template; const {openSideModal} = useModal(); - this.$nextTick(() => { - // Remove use group field if current mailable does not support specifying user group access - if (!this.currentMailable.canAssignUserGroupToTemplates) { - this.currentTemplateForm.fields = - this.currentTemplateForm.value.fields.filter( - (field) => field.name !== 'userGroupIds', - ); - } else { - const userGroupField = this.currentTemplateForm.fields.find( - (field) => field.name === 'userGroupIds', - ); - userGroupField.assignableUserGroups = - this.currentMailable['assignableTemplateUserGroups']; - userGroupField.assignedUserGroupIds = this.currentTemplate - ? this.currentTemplate['assignedUserGroupIds'] - : []; - } - - return openSideModal(EditTemplateModal, { + this.$nextTick(() => + openSideModal(EditTemplateModal, { title: this.currentTemplate ? t('manager.mailables.editTemplate') : t('manager.emails.addEmail'), currentTemplateForm: this.currentTemplateForm, - canAssignUserGroups: - this.currentMailable.canAssignUserGroupToTemplates, onUpdateCurrentTemplateForm: this.updateCurrentTemplateForm, onTemplateSaved: this.templateSaved, - }); - }); + }), + ); }, /** @@ -428,6 +409,16 @@ export default { }); } + // Remove user group fields if current mailable does not support specifying user group access + if (!this.currentMailable.canAssignUserGroupToTemplates) { + templateForm.fields = templateForm.fields.filter( + (field) => field.name !== 'userGroupIds', + ); + templateForm.fields = templateForm.fields.filter( + (field) => field.name !== 'isUnrestricted', + ); + } + templateForm.fields = templateForm.fields.map((field) => { if (field.name === 'body') { field.preparedContent = Object.keys( @@ -440,6 +431,21 @@ export default { }; }); } + + if (field.name === 'userGroupIds') { + field.assignableUserGroups = + this.currentMailable['assignableTemplateUserGroups']; + field.assignedUserGroupIds = + this.currentTemplate['assignedUserGroupIds'] || []; + field.isUnrestricted = + this.currentTemplate['isUnrestricted'] || false; + } + + if (field.name === 'isUnrestricted') { + field.isUnrestricted = + this.currentTemplate['isUnrestricted'] || false; + } + return field; }); diff --git a/src/components/Form/FormGroup.vue b/src/components/Form/FormGroup.vue index d427190b1..9d2151acc 100644 --- a/src/components/Form/FormGroup.vue +++ b/src/components/Form/FormGroup.vue @@ -79,6 +79,7 @@ import FieldUpload from './fields/FieldUpload.vue'; import FieldSlider from './fields/FieldSlider.vue'; import FieldUploadImage from './fields/FieldUploadImage.vue'; import FieldEmailTemplateUserGroupSettings from './fields/FieldEmailTemplateUserGroupSettings.vue'; +import FieldEmailTemplateUnrestricted from './fields/FieldEmailTemplateUnrestricted.vue'; import {shouldShowFieldWithinGroup} from './formHelpers'; @@ -111,6 +112,7 @@ export default { FieldUpload, FieldUploadImage, FieldEmailTemplateUserGroupSettings, + FieldEmailTemplateUnrestricted, }, props: { id: String, diff --git a/src/components/Form/fields/FieldEmailTemplateUnrestricted.vue b/src/components/Form/fields/FieldEmailTemplateUnrestricted.vue new file mode 100644 index 000000000..6e7c9535c --- /dev/null +++ b/src/components/Form/fields/FieldEmailTemplateUnrestricted.vue @@ -0,0 +1,52 @@ + + + + + diff --git a/src/components/Form/fields/FieldEmailTemplateUserGroupSettings.vue b/src/components/Form/fields/FieldEmailTemplateUserGroupSettings.vue index e936f54a2..b223317d2 100644 --- a/src/components/Form/fields/FieldEmailTemplateUserGroupSettings.vue +++ b/src/components/Form/fields/FieldEmailTemplateUserGroupSettings.vue @@ -1,16 +1,15 @@