Skip to content

Commit

Permalink
Merge pull request #641 from kabalin/missinghist
Browse files Browse the repository at this point in the history
Address missing history issue
  • Loading branch information
kabalin authored Dec 1, 2023
2 parents d9be36e + 6f25c99 commit bbb2ecc
Show file tree
Hide file tree
Showing 4 changed files with 23 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
8 changes: 7 additions & 1 deletion views/module/photo/hist.pug
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
| Комментирование {{?h.values.nocomments}}запрещено{{??}}разрешено{{?}}
| {{?}}
| {{?h.values.histmissing}}
.info.iconed.red
span.glyphicon(class="glyphicon-floppy-remove")
| Доступна не вся история изменений
| {{?}}
| {{?h.reason}}
.value
.name Причина
Expand All @@ -86,4 +92,4 @@
| {{~}}
| {{~}}
| </script>
| </script>

0 comments on commit bbb2ecc

Please sign in to comment.