Commit 5faba65d authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #10568 TIME 5:00 customize subject in email templates

parent 8e04c61c
......@@ -177,6 +177,10 @@ UPDATE groupbasket SET list_event_data = jsonb_set(list_event_data, '{canUpdateD
UPDATE groupbasket SET list_event_data = jsonb_set(list_event_data, '{canUpdateData}', 'false') WHERE list_event_data->>'canUpdate' = 'false';
UPDATE groupbasket SET list_event_data = list_event_data - 'canUpdate';
/* TEMPLATES */
ALTER TABLE templates DROP COLUMN IF EXISTS template_subject;
ALTER TABLE templates ADD COLUMN template_subject character varying(255);
Please register or sign in to reply
/* RE CREATE VIEWS */
CREATE OR REPLACE VIEW res_view_letterbox AS
SELECT r.res_id,
......
......@@ -751,6 +751,10 @@ class EmailController
return ['errors' => 'Data isHtml is not a boolean or empty', 'code' => 400];
}
if (!empty($args['data']['object']) && !Validator::stringType()->length(1, 256)->validate($args['data']['object'])) {
return ['errors' => 'Data object is not a string or is more than 256 characters', 'code' => 400];
}
if (!empty($args['data']['sender']['email'])) {
$configuration = ConfigurationModel::getByService(['service' => 'admin_email_server', 'select' => ['value']]);
$configuration = json_decode($configuration['value'], true);
......
......@@ -159,6 +159,13 @@ class TemplateController
$template['template_file_name'] = $storeResult['file_destination_name'];
}
if (!empty($body['subject'])) {
if (!Validator::stringType()->validate($body['subject']) && !Validator::length(1, 255)->validate($body['subject'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body subject is too long or not a string']);
}
$template['template_subject'] = $body['subject'];
}
$id = TemplateModel::create($template);
if (!empty($body['entities']) && is_array($body['entities'])) {
foreach ($body['entities'] as $entity) {
......@@ -236,6 +243,13 @@ class TemplateController
$template['template_file_name'] = $storeResult['file_destination_name'];
}
if (!empty($body['subject'])) {
if (!Validator::stringType()->validate($body['subject']) && !Validator::length(1, 255)->validate($body['subject'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body subject is too long or not a string']);
}
$template['template_subject'] = $body['subject'];
}
TemplateAssociationModel::delete(['where' => ['template_id = ?'], 'data' => [$aArgs['id']]]);
if (!empty($body['entities']) && is_array($body['entities'])) {
foreach ($body['entities'] as $entity) {
......@@ -462,7 +476,7 @@ class TemplateController
$data = [$entities, 'HTML', 'sendmail'];
$templates = TemplateModel::getWithAssociation([
'select' => ['DISTINCT(templates.template_id)', 'templates.template_label'],
'select' => ['DISTINCT(templates.template_id)', 'templates.template_label', 'templates.template_subject'],
'where' => $where,
'data' => $data,
'orderBy' => ['templates.template_label']
......@@ -470,8 +484,9 @@ class TemplateController
foreach ($templates as $key => $template) {
$templates[$key] = [
'id' => $template['template_id'],
'label' => $template['template_label']
'id' => $template['template_id'],
'label' => $template['template_label'],
'subject' => $template['template_subject']
];
}
......@@ -491,7 +506,7 @@ class TemplateController
}
$templates = TemplateModel::getWithAssociation([
'select' => ['DISTINCT(templates.template_id)', 'templates.template_content'],
'select' => ['DISTINCT(templates.template_id)', 'templates.template_content', 'templates.template_subject'],
'where' => ['(templates_association.value_field in (?) OR templates_association.template_id IS NULL)', 'templates.template_type = ?', 'templates.template_target = ?', 'templates.template_id = ?'],
'data' => [$entities, 'HTML', 'sendmail', $args['id']],
'orderBy' => ['templates.template_id']
......@@ -519,9 +534,14 @@ class TemplateController
'content' => $template['template_content'],
'data' => $dataToMerge
]);
$fileContent = base64_decode($mergedDocument['encodedDocument']);
$mergedDocument = base64_decode($mergedDocument['encodedDocument']);
$mergedSubject = MergeController::mergeDocument([
'content' => $template['template_subject'],
'data' => $dataToMerge
]);
$mergedSubject = base64_decode($mergedSubject['encodedDocument']);
return $response->withJson(['mergedDocument' => $fileContent]);
return $response->withJson(['mergedDocument' => $mergedDocument, 'mergedSubject' => $mergedSubject]);
}
private static function controlCreateTemplate(array $aArgs)
......
......@@ -107,6 +107,7 @@ abstract class TemplateModelAbstract
'template_attachment_type' => $args['template_attachment_type'],
'template_path' => $args['template_path'],
'template_file_name' => $args['template_file_name'],
'template_subject' => $args['template_subject'],
]
]);
......
......@@ -33,10 +33,10 @@
<mat-card *ngIf="!loading" class="card-app-content" style="display: contents;">
<form style="display: contents;" class="form-horizontal" (ngSubmit)="onSubmit()" #templatesFormUp="ngForm">
<div class="col-sm-12">
<div class="form-group">
<div class="form-group" *ngIf="!creationMode">
<div class="col-sm-12">
<mat-form-field>
<input matInput *ngIf="!creationMode" type="number" title="{{lang.technicalId}}"
<input matInput type="number" title="{{lang.technicalId}}"
value="{{template.id}}" placeholder="{{lang.technicalId}}" disabled>
</mat-form-field>
</div>
......@@ -104,6 +104,16 @@
</div>
</div>
<div class="form-group" *ngIf="template.target == 'sendmail'">
<div class="col-sm-12">
<mat-form-field>
<input matInput name="subject" [(ngModel)]="template.subject"
title="{{lang.subject}}" type="text"
placeholder="{{lang.subject}}" maxlength="255" required>
</mat-form-field>
</div>
</div>
<div class="form-group" *ngIf="availableTypes.length > 1">
<div class="col-sm-12">
<mat-radio-group [disabled]="!creationMode" required name="type"
......
......@@ -128,6 +128,7 @@ export class TemplateAdministrationComponent implements OnInit, OnDestroy {
datasource: data.template.template_datasource,
target: data.template.template_target,
type: data.template.template_type,
subject: data.template.template_subject,
file: {}
};
this.updateTemplateType();
......
......@@ -100,7 +100,7 @@
</mat-form-field>
<mat-form-field floatLabel="never">
<input matInput [placeholder]="lang.object" [readonly]="!canManageMail()" [(ngModel)]="emailsubject"
maxlength="70">
maxlength="255">
Please register or sign in to reply
<button mat-icon-button matSuffix *ngFor="let keyVal of emailAttachTool | keyvalue"
[disabled]="!canManageMail() || (emailAttachTool[keyVal.key].list.length === 0)"
[title]="emailAttachTool[keyVal.key].title"
......@@ -213,9 +213,9 @@
</mat-menu>
<button mat-raised-button color="primary"
*ngIf="canManageMail() && privilegeService.hasCurrentUserPrivilege('sendmail')" (click)="onSubmit()"
[disabled]="recipients.length === 0">{{lang.send}}</button>
[disabled]="recipients.length === 0 || emailsubject.length > 256">{{lang.send}}</button>
<button mat-raised-button color="warn" (click)="deleteEmail()"
*ngIf="data.emailId && data.emailType === 'email'"
[disabled]="headerService.user.id !== emailCreatorId">{{lang.delete}}</button>
</div>
</div>
\ No newline at end of file
</div>
......@@ -256,6 +256,10 @@ export class SentResourcePageComponent implements OnInit {
if (!this.htmlMode) {
tinymce.get('emailSignature').setContent(tinymce.get('emailSignature').getContent({ format: 'text' }));
}
if (!this.functions.empty(data.mergedSubject)) {
this.emailsubject = data.mergedSubject;
}
}),
catchError((err) => {
this.notify.handleSoftErrors(err);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment