Commit cdc044aa authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FIX #16246 TIME 0:45 delete attachment in email drafts when deleting...

FIX #16246 TIME 0:45 delete attachment in email drafts when deleting attachment + let user add other attachments in email if draft
parent db029b43
......@@ -15,6 +15,6 @@
<img src="assets/spinner.gif"/>
</div>
</app-root>
<script src="runtime-es2015.1a02c9460fb9ddda5582.js" type="module"></script><script src="runtime-es5.1a02c9460fb9ddda5582.js" nomodule defer></script><script src="polyfills-es5.75b6ffa131ed9d18e439.js" nomodule defer></script><script src="polyfills-es2015.a3390f1652700a53f04b.js" type="module"></script><script src="scripts.3f995a62571f9f668311.js" defer></script><script src="main-es2015.c7ef02fb6dab99ccdce4.js" type="module"></script><script src="main-es5.c7ef02fb6dab99ccdce4.js" nomodule defer></script></body>
<script src="runtime-es2015.1a02c9460fb9ddda5582.js" type="module"></script><script src="runtime-es5.1a02c9460fb9ddda5582.js" nomodule defer></script><script src="polyfills-es5.75b6ffa131ed9d18e439.js" nomodule defer></script><script src="polyfills-es2015.a3390f1652700a53f04b.js" type="module"></script><script src="scripts.3f995a62571f9f668311.js" defer></script><script src="main-es2015.05cb4aa0a16da2645829.js" type="module"></script><script src="main-es5.05cb4aa0a16da2645829.js" nomodule defer></script></body>
</html>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -22,6 +22,7 @@ use Convert\controllers\ConvertThumbnailController;
use Convert\models\AdrModel;
use Docserver\models\DocserverModel;
use Docserver\models\DocserverTypeModel;
use Email\models\EmailModel;
use Group\controllers\PrivilegeController;
use History\controllers\HistoryController;
use Resource\controllers\ResController;
......@@ -260,6 +261,38 @@ class AttachmentController
'data' => [$idToDelete, $idToDelete]
]);
$emails = EmailModel::get([
'select' => ['id', 'document'],
'where' => ["status = 'DRAFT'"]
]);
foreach ($emails as $key => $email) {
$emails[$key]['document'] = json_decode($email['document'], true);
}
$emails = array_filter($emails, function($email) { return !empty($email['document']['attachments']); });
$emails = array_filter($emails, function ($email) use ($idToDelete) {
$attachmentFound = false;
foreach ($email['document']['attachments'] as $attachment) {
if ($attachment['id'] == $idToDelete) {
$attachmentFound = true;
}
}
return $attachmentFound;
});
foreach ($emails as $key => $email) {
$emails[$key]['document']['attachments'] = array_filter($emails[$key]['document']['attachments'], function ($attachment) use ($idToDelete){
return $attachment['id'] != $idToDelete;
});
$emails[$key]['document']['attachments'] = array_values($emails[$key]['document']['attachments']);
$encoded = json_encode($emails[$key]['document']);
EmailModel::update([
'set' => ['document' => $encoded],
'where' => ['id = ?'],
'data' => [$emails[$key]['id']]
]);
}
HistoryController::add([
'tableName' => 'res_attachments',
'recordId' => $args['id'],
......
......@@ -122,7 +122,7 @@ export class SentResourcePageComponent implements OnInit {
});
if (this.functions.empty(this.data.emailId)) {
await this.getAttachElements();
await this.getAttachElements(true);
}
if (this.data.emailId && this.data.emailType === 'email') {
......@@ -319,7 +319,7 @@ export class SentResourcePageComponent implements OnInit {
getEmailData(emailId: number) {
return new Promise((resolve) => {
this.http.get(`../rest/emails/${emailId}`).pipe(
tap((data: any) => {
tap(async (data: any) => {
this.emailCreatorId = data.userId;
this.recipients = data.recipients.map((item: any) => {
......@@ -380,6 +380,10 @@ export class SentResourcePageComponent implements OnInit {
}
});
if (this.emailStatus === 'DRAFT') {
await this.getAttachElements(false);
}
resolve(true);
}),
catchError((err) => {
......@@ -525,7 +529,7 @@ export class SentResourcePageComponent implements OnInit {
});
}
getAttachElements() {
getAttachElements(attachElements: boolean) {
return new Promise((resolve) => {
this.http.get(`../rest/resources/${this.data.resId}/emailsInitialization`).pipe(
tap((data: any) => {
......@@ -537,7 +541,7 @@ export class SentResourcePageComponent implements OnInit {
}
} else {
this.emailAttachTool[element].list = data[element].map((item: any) => {
if (item.attachInMail) {
if (item.attachInMail && attachElements) {
this.toggleAttachMail(item, element, item.status === 'SIGN' ? 'pdf' : 'original');
}
return {
......
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