Skip to content

Commit

Permalink
Address missing history issue
Browse files Browse the repository at this point in the history
* When photo history is accessed, show upload time with notification
  that some histiry is missing.
* When editing a photo with missing history, add first history record
  with upload time and notification that some histiry is missing.

Fixes #631
  • Loading branch information
kabalin committed Nov 29, 2023
1 parent 0178126 commit f695c31
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 0 additions & 2 deletions app/errors/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions app/errors/intl.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ export default {
CONVERT_PHOTOS_ALL: 'Ошибка отправки на конвертацию',
CONVERT_PROMISE_GENERATOR: 'Ошибка выполнения операции в конвейере конвертации',

HISTORY_DOESNT_EXISTS: 'Для объекта еще нет истории',

SETTING_DOESNT_EXISTS: 'Такой настройки не существует',

MAIL_SEND: 'Ошибка отправки письма',
Expand Down
18 changes: 16 additions & 2 deletions controllers/photo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 8 additions & 1 deletion views/module/photo/hist.pug
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
| Комментирование {{?h.values.nocomments}}запрещено{{??}}разрешено{{?}}
| {{?}}
| {{?h.values.histmissing}}
.info.iconed.red
span.glyphicon(class="glyphicon-floppy-remove")
| Неполная история снимка
| {{?}}
| {{?h.reason}}
.value
.name Причина
Expand All @@ -86,4 +93,4 @@
| {{~}}
| {{~}}
| </script>
| </script>

0 comments on commit f695c31

Please sign in to comment.