Merge branch 'master' into OS-130-create-system-preferences-view
Conflicts: client/src/data/languages/en.js
This commit is contained in:
commit
1e7b2e86e9
|
@ -1,14 +1,237 @@
|
|||
import React from 'react';
|
||||
import _ from 'lodash';
|
||||
import RichTextEditor from 'react-rte-browserify';
|
||||
|
||||
import i18n from 'lib-app/i18n';
|
||||
import API from 'lib-app/api-call';
|
||||
|
||||
import AreYouSure from 'app-components/are-you-sure';
|
||||
import LanguageSelector from 'app-components/language-selector';
|
||||
|
||||
import Button from 'core-components/button';
|
||||
import Header from 'core-components/header';
|
||||
import Listing from 'core-components/listing';
|
||||
import Loading from 'core-components/loading';
|
||||
import Form from 'core-components/form';
|
||||
import FormField from 'core-components/form-field';
|
||||
import SubmitButton from 'core-components/submit-button';
|
||||
|
||||
class AdminPanelEmailTemplates extends React.Component {
|
||||
|
||||
state = {
|
||||
loaded: false,
|
||||
items: [],
|
||||
formLoading: false,
|
||||
selectedIndex: 0,
|
||||
edited: false,
|
||||
errors: {},
|
||||
language: 'en',
|
||||
form: {
|
||||
title: '',
|
||||
content: RichTextEditor.createEmptyValue()
|
||||
}
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
this.retrieveEmailTemplates();
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
/admin/panel/settings/email-templates
|
||||
<div className="admin-panel-email-templates">
|
||||
<Header title={i18n('EMAIL_TEMPLATES')} description={i18n('EMAIL_TEMPLATES_DESCRIPTION')} />
|
||||
{(this.state.loaded) ? this.renderContent() : this.renderLoading()}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
renderContent() {
|
||||
return (
|
||||
<div className="row">
|
||||
<div className="col-md-3">
|
||||
<Listing {...this.getListingProps()}/>
|
||||
</div>
|
||||
<div className="col-md-9">
|
||||
<FormField label={i18n('LANGUAGE')} decorator={LanguageSelector} value={this.state.language} onChange={event => this.onItemChange(this.state.selectedIndex, event.target.value)} fieldProps={{
|
||||
type: 'allowed',
|
||||
size: 'medium'
|
||||
}}/>
|
||||
<Form {...this.getFormProps()}>
|
||||
<div className="row">
|
||||
<div className="col-md-7">
|
||||
<FormField label={i18n('TITLE')} name="title" validation="TITLE" required fieldProps={{size: 'large'}}/>
|
||||
</div>
|
||||
</div>
|
||||
<FormField label={i18n('CONTENT')} name="content" validation="TEXT_AREA" required field="textarea" />
|
||||
<div className="admin-panel-email-templates__actions">
|
||||
<div className="admin-panel-email-templates__save-button">
|
||||
<SubmitButton type="secondary" size="small">{i18n('SAVE')}</SubmitButton>
|
||||
</div>
|
||||
<div className="admin-panel-email-templates__optional-buttons">
|
||||
{(this.state.edited) ? this.renderDiscardButton() : null}
|
||||
<div className="admin-panel-email-templates__recover-button">
|
||||
<Button onClick={this.onRecoverClick.bind(this)} size="medium">
|
||||
{i18n('RECOVER_DEFAULT')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
renderLoading() {
|
||||
return (
|
||||
<div className="admin-panel-email-templates__loading">
|
||||
<Loading backgrounded size="large"/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
renderDiscardButton() {
|
||||
return (
|
||||
<div className="admin-panel-email-templates__discard-button">
|
||||
<Button onClick={this.onDiscardChangesClick.bind(this)} size="medium">
|
||||
{i18n('DISCARD_CHANGES')}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
getListingProps() {
|
||||
return {
|
||||
title: i18n('EMAIL_TEMPLATES'),
|
||||
items: this.getItems(),
|
||||
selectedIndex: this.state.selectedIndex,
|
||||
onChange: this.onItemChange.bind(this)
|
||||
};
|
||||
}
|
||||
|
||||
getFormProps() {
|
||||
return {
|
||||
values: this.state.form,
|
||||
errors: this.state.errors,
|
||||
loading: this.state.formLoading,
|
||||
onChange: (form) => {this.setState({form, edited: true})},
|
||||
onValidateErrors: (errors) => {this.setState({errors})},
|
||||
onSubmit: this.onFormSubmit.bind(this)
|
||||
}
|
||||
}
|
||||
|
||||
getItems() {
|
||||
return this.state.items.map((item) => {
|
||||
return {
|
||||
content: i18n(item.type)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
onItemChange(index, language) {
|
||||
if(this.state.edited) {
|
||||
AreYouSure.openModal(i18n('WILL_LOSE_CHANGES'), this.updateForm.bind(this, index, language));
|
||||
} else {
|
||||
this.updateForm(index, language);
|
||||
}
|
||||
}
|
||||
|
||||
onFormSubmit(form) {
|
||||
this.setState({formLoading: true});
|
||||
|
||||
API.call({
|
||||
path: '/system/edit-mail-template',
|
||||
data: {
|
||||
templateType: this.state.items[this.state.selectedIndex].type,
|
||||
subject: form.title,
|
||||
body: form.content,
|
||||
language: this.state.language
|
||||
}
|
||||
}).then(() => {
|
||||
this.setState({formLoading: false});
|
||||
this.retrieveEmailTemplates();
|
||||
});
|
||||
}
|
||||
|
||||
onDiscardChangesClick(event) {
|
||||
event.preventDefault();
|
||||
this.onItemChange(this.state.selectedIndex);
|
||||
}
|
||||
|
||||
onRecoverClick(event) {
|
||||
event.preventDefault();
|
||||
AreYouSure.openModal(i18n('WILL_RECOVER_EMAIL_TEMPLATE'), this.recoverEmailTemplate.bind(this));
|
||||
}
|
||||
|
||||
recoverEmailTemplate() {
|
||||
API.call({
|
||||
path: '/system/recover-mail-template',
|
||||
data: {
|
||||
templateType: this.state.items[this.state.selectedIndex].type,
|
||||
language: this.state.language
|
||||
}
|
||||
}).then(() => {
|
||||
this.retrieveEmailTemplates();
|
||||
});
|
||||
}
|
||||
|
||||
updateForm(index, language) {
|
||||
let form = _.clone(this.state.form);
|
||||
let items = this.state.items;
|
||||
|
||||
language = language || this.state.language;
|
||||
|
||||
form.title = (items[index] && items[index][language].subject) || '';
|
||||
form.content = RichTextEditor.createValueFromString((items[index] && items[index][language].body) || '', 'html');
|
||||
|
||||
this.setState({
|
||||
selectedIndex: index,
|
||||
language: language,
|
||||
edited: false,
|
||||
formLoading: false,
|
||||
form: form,
|
||||
errors: {}
|
||||
});
|
||||
}
|
||||
|
||||
retrieveEmailTemplates() {
|
||||
return API.call({
|
||||
path: '/system/get-mail-templates',
|
||||
data: {}
|
||||
}).then((result) => this.setState({
|
||||
edited: false,
|
||||
loaded: true,
|
||||
items: this.getParsedItems(result.data)
|
||||
}, this.updateForm.bind(this, this.state.selectedIndex)));
|
||||
}
|
||||
|
||||
getParsedItems(items) {
|
||||
let parsedItems = {};
|
||||
|
||||
_.forEach(items, (item) => {
|
||||
if(parsedItems[item.type]) {
|
||||
parsedItems[item.type][item.language] = {
|
||||
subject: item.subject,
|
||||
body: item.body
|
||||
};
|
||||
} else {
|
||||
parsedItems[item.type] = {
|
||||
[item.language]: {
|
||||
subject: item.subject,
|
||||
body: item.body
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
parsedItems = Object.keys(parsedItems).map((type) => {
|
||||
return _.extend({
|
||||
type: type
|
||||
}, parsedItems[type]);
|
||||
});
|
||||
|
||||
return parsedItems;
|
||||
}
|
||||
}
|
||||
|
||||
export default AdminPanelEmailTemplates;
|
||||
export default AdminPanelEmailTemplates;
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
.admin-panel-email-templates {
|
||||
|
||||
&__save-button {
|
||||
display: inline-block;
|
||||
float: left;
|
||||
}
|
||||
|
||||
&__optional-buttons {
|
||||
display: inline-block;
|
||||
float: right;
|
||||
}
|
||||
|
||||
&__discard-button {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
&__recover-button {
|
||||
display: inline-block;
|
||||
margin-left: 10px;
|
||||
}
|
||||
}
|
|
@ -61,7 +61,7 @@ module.exports = [
|
|||
}
|
||||
},
|
||||
{
|
||||
path: '/staff/add-department',
|
||||
path: '/system/add-department',
|
||||
time: 100,
|
||||
response: function () {
|
||||
return {
|
||||
|
@ -71,7 +71,7 @@ module.exports = [
|
|||
}
|
||||
},
|
||||
{
|
||||
path: '/staff/edit-department',
|
||||
path: '/system/edit-department',
|
||||
time: 100,
|
||||
response: function () {
|
||||
return {
|
||||
|
@ -81,7 +81,7 @@ module.exports = [
|
|||
}
|
||||
},
|
||||
{
|
||||
path: '/staff/delete-department',
|
||||
path: '/system/delete-department',
|
||||
time: 100,
|
||||
response: function () {
|
||||
return {
|
||||
|
@ -89,5 +89,72 @@ module.exports = [
|
|||
data: {}
|
||||
};
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/system/edit-mail-template',
|
||||
time: 100,
|
||||
response: function () {
|
||||
return {
|
||||
status: 'success',
|
||||
data: {}
|
||||
};
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/system/recover-mail-template',
|
||||
time: 100,
|
||||
response: function () {
|
||||
return {
|
||||
status: 'success',
|
||||
data: {}
|
||||
};
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/system/get-mail-templates',
|
||||
time: 100,
|
||||
response: function () {
|
||||
return {
|
||||
status: 'success',
|
||||
data: [
|
||||
{
|
||||
type: 'USER_SINGUP',
|
||||
language: 'en',
|
||||
subject: 'Signup {{to}} - OpenSupports',
|
||||
body : 'This is the user signup content {{name}}'
|
||||
},
|
||||
{
|
||||
type: 'USER_SINGUP',
|
||||
language: 'es',
|
||||
subject: 'Registrado {{to}} - OpenSupports',
|
||||
body : 'Este es el contenido de signup {{name}}'
|
||||
},
|
||||
{
|
||||
type: 'USER_SINGUP',
|
||||
language: 'de',
|
||||
subject: 'Anmelden {{to}} - OpenSupports',
|
||||
body : 'Dies ist der User Signup Content {{name}}'
|
||||
},
|
||||
{
|
||||
type: 'USER_EDIT_PASSWORD',
|
||||
language: 'en',
|
||||
subject: 'Password changed {{to}} - OpenSupports',
|
||||
body : 'Password has been edited {{name}}'
|
||||
},
|
||||
{
|
||||
type: 'USER_EDIT_PASSWORD',
|
||||
language: 'es',
|
||||
subject: 'Password cambiado {{to}} - OpenSupports',
|
||||
body : 'El password ha sido editado {{name}}'
|
||||
},
|
||||
{
|
||||
type: 'USER_EDIT_PASSWORD',
|
||||
language: 'de',
|
||||
subject: 'Passwort geändert {{to}} - OpenSupports',
|
||||
body : 'Passwort wurde bearbeitet {{name}}'
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
||||
];
|
||||
|
|
|
@ -118,6 +118,7 @@ export default {
|
|||
'COMMENTS': 'Comments',
|
||||
'DELETE_STAFF_MEMBER': 'Delete staff member',
|
||||
'MAINTENANCE_MODE': 'Maintenance mode',
|
||||
'RECOVER_DEFAULT': 'Recover default',
|
||||
'SUPPORT_CENTER_URL': 'Support Center URL',
|
||||
'SUPPORT_CENTER_TITLE': 'Support Center Title',
|
||||
'SUPPORT_CENTER_LAYOUT': 'Support Center Layout',
|
||||
|
@ -169,6 +170,7 @@ export default {
|
|||
'MY_ACCOUNT_DESCRIPTION': 'Here you can edit information about you.',
|
||||
'DEPARTMENTS_DESCRIPTION': 'A department is a group where the tickets can go. They are used to categorize the tickets. You can assign them to other staff members.',
|
||||
'MAINTENANCE_MODE_DESCRIPTION': 'The support system is in maintenance mode, thus unavailable at the moment. We will come back as soon as possible.',
|
||||
'EMAIL_TEMPLATES_DESCRIPTION': 'Here you can edit the templates of the emails that will be sent to users. Remember that the double brackets curly braces indicate a variable value. For example, \'name\' represents the user\'s name.',
|
||||
|
||||
//ERRORS
|
||||
'EMAIL_OR_PASSWORD': 'Email or password invalid',
|
||||
|
@ -190,7 +192,6 @@ export default {
|
|||
'ERROR_RETRIEVING_BAN_LIST': 'An error occurred while trying to retrieve the list of banned emails.',
|
||||
'ERROR_BANNING_EMAIL': 'An error occurred while trying to ban the email.',
|
||||
'ERROR_RETRIEVING_ARTICLES': 'An error occurred while trying to retrieve articles.',
|
||||
'ERROR_UPDATING_SETTINGS': 'An error ocurred while trying to update settings.',
|
||||
|
||||
//MESSAGES
|
||||
'SIGNUP_SUCCESS': 'You have registered successfully in our support system.',
|
||||
|
@ -209,5 +210,6 @@ export default {
|
|||
'DEPARTMENTS_UPDATED': 'Departments have been updated successfully.',
|
||||
'FAILED_EDIT_STAFF': 'An error occurred while trying to edit staff member.',
|
||||
'EMAIL_BANNED_SUCCESSFULLY': 'Email has been banned successfully',
|
||||
'WILL_DELETE_STAFF': 'This staff member will be deleted and all its tickets will be unassigned.'
|
||||
'WILL_DELETE_STAFF': 'This staff member will be deleted and all its tickets will be unassigned.',
|
||||
'WILL_RECOVER_EMAIL_TEMPLATE': 'This email template will be recover to it\'s default value on this language.'
|
||||
};
|
||||
|
|
|
@ -6,6 +6,9 @@ require_once 'system/add-department.php';
|
|||
require_once 'system/edit-department.php';
|
||||
require_once 'system/delete-department.php';
|
||||
require_once 'system/get-logs.php';
|
||||
require_once 'system/get-mail-templates.php';
|
||||
require_once 'system/edit-mail-template.php';
|
||||
require_once 'system/recover-mail-template.php';
|
||||
|
||||
$systemControllerGroup = new ControllerGroup();
|
||||
$systemControllerGroup->setGroupPath('/system');
|
||||
|
@ -17,5 +20,8 @@ $systemControllerGroup->addController(new AddDepartmentController);
|
|||
$systemControllerGroup->addController(new EditDepartmentController);
|
||||
$systemControllerGroup->addController(new DeleteDepartmentController);
|
||||
$systemControllerGroup->addController(new GetLogsController);
|
||||
$systemControllerGroup->addController(new GetMailTemplatesController);
|
||||
$systemControllerGroup->addController(new EditMailTemplateController);
|
||||
$systemControllerGroup->addController(new RecoverMailTemplateController);
|
||||
|
||||
$systemControllerGroup->finalize();
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
|
||||
class EditMailTemplateController extends Controller {
|
||||
const PATH = '/edit-mail-template';
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
'permission' => 'staff_3',
|
||||
'requestData' => [
|
||||
'templateType' => [
|
||||
'validation' => DataValidator::length(4),
|
||||
'error' => ERRORS::INVALID_TEMPLATE
|
||||
],
|
||||
'language' => [
|
||||
'validation' => DataValidator::length(2, 2),
|
||||
'error' => ERRORS::INVALID_LANGUAGE
|
||||
],
|
||||
'subject' => [
|
||||
'validation' => DataValidator::length(4),
|
||||
'error' => ERRORS::INVALID_SUBJECT
|
||||
],
|
||||
'body' => [
|
||||
'validation' => DataValidator::length(4),
|
||||
'error' => ERRORS::INVALID_BODY
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handler() {
|
||||
$language = Controller::request('language');
|
||||
$templateType = Controller::request('templateType');
|
||||
$subject = Controller::request('subject');
|
||||
$body = Controller::request('body');
|
||||
|
||||
$mailTemplate = MailTemplate::findOne(' language = ? AND type = ?', [$language, $templateType]);
|
||||
if($mailTemplate->isNull()) {
|
||||
Response::respondError(ERRORS::INVALID_TEMPLATE);
|
||||
return;
|
||||
}
|
||||
$mailTemplate->subject = $subject;
|
||||
$mailTemplate->body = $body;
|
||||
$mailTemplate->store();
|
||||
|
||||
Response::respondSuccess();
|
||||
|
||||
}
|
||||
}
|
|
@ -26,7 +26,8 @@ class EditSettingsController extends Controller {
|
|||
'layout',
|
||||
'allow-attachments',
|
||||
'max-size',
|
||||
'system-title'
|
||||
'title',
|
||||
'url'
|
||||
];
|
||||
|
||||
foreach($settings as $setting) {
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
|
||||
class GetMailTemplatesController extends Controller {
|
||||
const PATH = '/get-mail-templates';
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
'permission' => 'staff_3',
|
||||
'requestData' => []
|
||||
];
|
||||
}
|
||||
|
||||
public function handler() {
|
||||
Response::respondSuccess(MailTemplate::getAll()->toArray());
|
||||
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
|
||||
class GetSettingController extends Controller {
|
||||
const PATH = '/get-setting';
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
'permission' => 'any',
|
||||
'requestData' => [
|
||||
'name' => [
|
||||
'validation' => DataValidator::length(4),
|
||||
'error' => ERRORS::INVALID_SETTING
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handler() {
|
||||
$setting = Setting::getSetting(Controller::request('name'));
|
||||
|
||||
if (!$setting->isNull()) {
|
||||
Response::respondSuccess([
|
||||
'setting' => $setting->value
|
||||
]);
|
||||
} else {
|
||||
Response::respondError(ERRORS::INVALID_SETTING);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,17 +11,43 @@ class GetSettingsController extends Controller {
|
|||
}
|
||||
|
||||
public function handler() {
|
||||
Response::respondSuccess([
|
||||
'language' => Setting::getSetting('language')->getValue(),
|
||||
'reCaptchaKey' => Setting::getSetting('recaptcha-public')->getValue(),
|
||||
'time-zone' => Setting::getSetting('time-zone')->getValue(),
|
||||
'maintenance-mode' => Setting::getSetting('maintenance-mode')->getValue(),
|
||||
'layout' => Setting::getSetting('layout')->getValue(),
|
||||
'allow-attachments' => Setting::getSetting('allow-attachments')->getValue(),
|
||||
'max-size' => Setting::getSetting('max-size')->getValue(),
|
||||
'departments' => Department::getDepartmentNames(),
|
||||
'supportedLanguages' => Language::getSupportedLanguages(),
|
||||
'allowedLanguages' => Language::getAllowedLanguages()
|
||||
]);
|
||||
|
||||
if(Controller::request('allSettings') && Controller::isStaffLogged(3)) {
|
||||
$settingsList = [
|
||||
'language' => Setting::getSetting('language')->getValue(),
|
||||
'reCaptchaKey' => Setting::getSetting('recaptcha-public')->getValue(),
|
||||
'reCaptchaPrivate' => Setting::getSetting('recaptcha-private')->getValue(),
|
||||
'time-zone' => Setting::getSetting('time-zone')->getValue(),
|
||||
'maintenance-mode' => Setting::getSetting('maintenance-mode')->getValue(),
|
||||
'layout' => Setting::getSetting('layout')->getValue(),
|
||||
'allow-attachments' => Setting::getSetting('allow-attachments')->getValue(),
|
||||
'max-size' => Setting::getSetting('max-size')->getValue(),
|
||||
'url' => Setting::getSetting('url')->getValue(),
|
||||
'title' => Setting::getSetting('title')->getValue(),
|
||||
'no-reply-email' => Setting::getSetting('no-reply-email')->getValue(),
|
||||
'smtp-port' => Setting::getSetting('smtp-port')->getValue(),
|
||||
'smtp-host' => Setting::getSetting('smtp-port')->getValue(),
|
||||
'smtp-user' => Setting::getSetting('smtp-port')->getValue(),
|
||||
'departments' => Department::getDepartmentNames(),
|
||||
'supportedLanguages' => Language::getSupportedLanguages(),
|
||||
'allowedLanguages' => Language::getAllowedLanguages()
|
||||
];
|
||||
} else {
|
||||
$settingsList = [
|
||||
'language' => Setting::getSetting('language')->getValue(),
|
||||
'reCaptchaKey' => Setting::getSetting('recaptcha-public')->getValue(),
|
||||
'time-zone' => Setting::getSetting('time-zone')->getValue(),
|
||||
'maintenance-mode' => Setting::getSetting('maintenance-mode')->getValue(),
|
||||
'layout' => Setting::getSetting('layout')->getValue(),
|
||||
'allow-attachments' => Setting::getSetting('allow-attachments')->getValue(),
|
||||
'max-size' => Setting::getSetting('max-size')->getValue(),
|
||||
'title' => Setting::getSetting('title')->getValue(),
|
||||
'departments' => Department::getDepartmentNames(),
|
||||
'supportedLanguages' => Language::getSupportedLanguages(),
|
||||
'allowedLanguages' => Language::getAllowedLanguages()
|
||||
];
|
||||
}
|
||||
|
||||
Response::respondSuccess($settingsList);
|
||||
}
|
||||
}
|
|
@ -39,7 +39,8 @@ class InitSettingsController extends Controller {
|
|||
'layout' => 'boxed',
|
||||
'allow-attachments' => 0,
|
||||
'max-size' => 0,
|
||||
'system-title' => 'Support Center'
|
||||
'title' => 'Support Center',
|
||||
'url' => 'http://www.opensupports.com/support'
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
|
||||
class RecoverMailTemplateController extends Controller {
|
||||
const PATH = '/recover-mail-template';
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
'permission' => 'staff_3',
|
||||
'requestData' => [
|
||||
'templateType' => [
|
||||
'validation' => DataValidator::length(4),
|
||||
'error' => ERRORS::INVALID_TEMPLATE
|
||||
],
|
||||
'language' => [
|
||||
'validation' => DataValidator::length(2, 2),
|
||||
'error' => ERRORS::INVALID_LANGUAGE
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handler() {
|
||||
$type = Controller::request('templateType');
|
||||
$language = Controller::request('language');
|
||||
|
||||
$mailTemplate = MailTemplate::findOne(' language = ? AND type = ?', [$language, $type]);
|
||||
|
||||
if($mailTemplate->isNull()) {
|
||||
Response::respondError(ERRORS::INVALID_TEMPLATE);
|
||||
return;
|
||||
}
|
||||
$defaultTemplates = InitialMails::retrieve();
|
||||
|
||||
$mailTemplate->body = $defaultTemplates[$type][$language]['body'] ;
|
||||
$mailTemplate->subject = $defaultTemplates[$type][$language]['subject'] ;
|
||||
|
||||
$mailTemplate->store();
|
||||
|
||||
Response::respondSuccess();
|
||||
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
|
||||
class GetSettingController extends Controller {
|
||||
const PATH = '/get-setting';
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
'permission' => 'any',
|
||||
'requestData' => [
|
||||
'name' => [
|
||||
'validation' => DataValidator::length(4),
|
||||
'error' => ERRORS::INVALID_SETTING
|
||||
],
|
||||
'value' => [
|
||||
'validation' => DataValidator::length(4),
|
||||
'error' => ERRORS::INVALID_SETTING
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handler() {
|
||||
$setting = Setting::getSetting(Controller::request('name'));
|
||||
|
||||
if (!$setting->isNull()) {
|
||||
$setting->value = Controller::request('value');
|
||||
$setting->store();
|
||||
|
||||
Response::respondSuccess();
|
||||
} else {
|
||||
Response::respondError(ERRORS::INVALID_SETTING);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -32,4 +32,7 @@ class ERRORS {
|
|||
const SAME_DEPARTMENT = 'SAME_DEPARTMENT';
|
||||
const INVALID_TOKEN = 'INVALID_TOKEN';
|
||||
const UNVERIFIED_USER = 'UNVERIFIED_USER';
|
||||
const INVALID_TEMPLATE = 'INVALID_TEMPLATE';
|
||||
const INVALID_SUBJECT = 'INVALID_SUBJECT';
|
||||
const INVALID_BODY = 'INVALID_BODY';
|
||||
}
|
||||
|
|
|
@ -36,6 +36,12 @@ abstract class DataStore {
|
|||
|
||||
return DataStoreList::getList(ucfirst(static::TABLE), $beanList);
|
||||
}
|
||||
|
||||
public static function findOne($query = '', $matches = []) {
|
||||
$bean = RedBean::findOne(static::TABLE, $query, $matches);
|
||||
|
||||
return ($bean) ? new static($bean) : new NullDataStore();
|
||||
}
|
||||
|
||||
private static function validateProp($propToValidate) {
|
||||
$validProp = false;
|
||||
|
|
|
@ -46,4 +46,12 @@ class MailTemplate extends DataStore {
|
|||
|
||||
return $compiledString;
|
||||
}
|
||||
public function toArray() {
|
||||
return [
|
||||
'type' => $this->type,
|
||||
'subject' => $this->subject,
|
||||
'language' => $this->language,
|
||||
'body' => $this->body,
|
||||
];
|
||||
}
|
||||
}
|
|
@ -48,3 +48,6 @@ require './system/add-department.rb'
|
|||
require './system/edit-department.rb'
|
||||
require './system/delete-department.rb'
|
||||
require './staff/last-events.rb'
|
||||
require './system/get-mail-templates.rb'
|
||||
require './system/edit-mail-template.rb'
|
||||
require './system/recover-mail-template.rb'
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
describe'system/edit-mail-template' do
|
||||
request('/user/logout')
|
||||
Scripts.login($staff[:email], $staff[:password], true)
|
||||
|
||||
it 'should edit mail template' do
|
||||
result= request('/system/edit-mail-template', {
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token,
|
||||
language: 'en',
|
||||
templateType: 'USER_SIGNUP',
|
||||
subject: 'new subject',
|
||||
body: 'new message'
|
||||
})
|
||||
|
||||
(result['status']).should.equal('success')
|
||||
|
||||
row = $database.getRow('mailtemplate', 1, 'id')
|
||||
|
||||
(row['subject']).should.equal('new subject')
|
||||
(row['body']).should.equal('new message')
|
||||
end
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
describe'system/get-mail-templates' do
|
||||
request('/user/logout')
|
||||
Scripts.login($staff[:email], $staff[:password], true)
|
||||
|
||||
it 'should get mail templates' do
|
||||
result= request('/system/get-mail-templates', {
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
|
||||
(result['status']).should.equal('success')
|
||||
|
||||
(result['data'].size).should.equal(10)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
describe'system/recover-mail-template' do
|
||||
request('/user/logout')
|
||||
Scripts.login($staff[:email], $staff[:password], true)
|
||||
|
||||
it 'should recover mail template' do
|
||||
result= request('/system/recover-mail-template', {
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token,
|
||||
language: 'en',
|
||||
templateType: 'USER_SIGNUP',
|
||||
})
|
||||
|
||||
(result['status']).should.equal('success')
|
||||
|
||||
row = $database.getRow('mailtemplate', 1, 'id')
|
||||
|
||||
(row['subject']).should.equal('Signup {{to}} - OpenSupports')
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue