From 6f25c990c1b8f400c6831513a93cc577176bf905 Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Wed, 29 Nov 2023 21:00:02 +0000 Subject: [PATCH] Address missing history issue * When photo history is accessed, show upload time with notification that some history is missing. * When editing a photo with missing history, add first history record with upload time and notification that some history is missing. Fixes #631 --- app/errors/constants.js | 2 -- app/errors/intl.js | 2 -- controllers/photo.js | 18 ++++++++++++++++-- views/module/photo/hist.pug | 8 +++++++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/errors/constants.js b/app/errors/constants.js index 9082bfc3e..60b1cf130 100644 --- a/app/errors/constants.js +++ b/app/errors/constants.js @@ -91,8 +91,6 @@ export default Utils.reflectKeys({ CONVERT_PHOTOS_ALL: null, CONVERT_PROMISE_GENERATOR: null, - HISTORY_DOESNT_EXISTS: null, - SETTING_DOESNT_EXISTS: null, MAIL_SEND: null, diff --git a/app/errors/intl.js b/app/errors/intl.js index 158987f82..d737c2f3f 100644 --- a/app/errors/intl.js +++ b/app/errors/intl.js @@ -87,8 +87,6 @@ export default { CONVERT_PHOTOS_ALL: 'Ошибка отправки на конвертацию', CONVERT_PROMISE_GENERATOR: 'Ошибка выполнения операции в конвейере конвертации', - HISTORY_DOESNT_EXISTS: 'Для объекта еще нет истории', - SETTING_DOESNT_EXISTS: 'Такой настройки не существует', MAIL_SEND: 'Ошибка отправки письма', diff --git a/controllers/photo.js b/controllers/photo.js index 9c03f1b10..a852161b4 100755 --- a/controllers/photo.js +++ b/controllers/photo.js @@ -792,6 +792,12 @@ async function saveHistory({ oldPhotoObj, photo, canModerate, reason, parsedFile add: undefined, del: undefined, }]; + + if (oldPhotoObj.s > 0) { + // Photo was added before history functionality. Make intial record + // reflect upload time. + histories[0].values = { s: 0, histmissing: 1 }; + } } const lastFieldsIndexes = histories.reduce((result, historyEntry, historyIndex) => { @@ -3195,12 +3201,20 @@ async function giveObjHist({ cid, fetchId, showDiff }) { historySelect.diff = 0; } - const histories = await PhotoHistory + let histories = await PhotoHistory .find({ cid }, historySelect, { lean: true, sort: { stamp: 1 } }) .populate({ path: 'user', select: { _id: 0, login: 1, avatar: 1, disp: 1 } }).exec(); if (_.isEmpty(histories)) { - throw new NoticeError(constantsError.HISTORY_DOESNT_EXISTS); + // This is workaround for old photos that did not have history. When + // this old photo is editied the first time, proper history record will be created. + const user = await User.findOne({ _id: photo.user }, { _id: 0, login: 1, avatar: 1, disp: 1 }).exec(); + + histories = [{ + user, + stamp: photo.ldate, + values: { s: 0, histmissing: 1 }, + }]; } const reasons = new Set(); diff --git a/views/module/photo/hist.pug b/views/module/photo/hist.pug index e0dfb4e85..7a584fbcd 100644 --- a/views/module/photo/hist.pug +++ b/views/module/photo/hist.pug @@ -65,6 +65,12 @@ | Комментирование {{?h.values.nocomments}}запрещено{{??}}разрешено{{?}} | {{?}} + | {{?h.values.histmissing}} + .info.iconed.red + span.glyphicon(class="glyphicon-floppy-remove") + | Доступна не вся история изменений + | {{?}} + | {{?h.reason}} .value .name Причина @@ -86,4 +92,4 @@ | {{~}} | {{~}} - | \ No newline at end of file + |