Skip to content

Commit 6f25c99

Browse files
committed
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
1 parent 0178126 commit 6f25c99

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

app/errors/constants.js

-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ export default Utils.reflectKeys({
9191
CONVERT_PHOTOS_ALL: null,
9292
CONVERT_PROMISE_GENERATOR: null,
9393

94-
HISTORY_DOESNT_EXISTS: null,
95-
9694
SETTING_DOESNT_EXISTS: null,
9795

9896
MAIL_SEND: null,

app/errors/intl.js

-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ export default {
8787
CONVERT_PHOTOS_ALL: 'Ошибка отправки на конвертацию',
8888
CONVERT_PROMISE_GENERATOR: 'Ошибка выполнения операции в конвейере конвертации',
8989

90-
HISTORY_DOESNT_EXISTS: 'Для объекта еще нет истории',
91-
9290
SETTING_DOESNT_EXISTS: 'Такой настройки не существует',
9391

9492
MAIL_SEND: 'Ошибка отправки письма',

controllers/photo.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,12 @@ async function saveHistory({ oldPhotoObj, photo, canModerate, reason, parsedFile
792792
add: undefined,
793793
del: undefined,
794794
}];
795+
796+
if (oldPhotoObj.s > 0) {
797+
// Photo was added before history functionality. Make intial record
798+
// reflect upload time.
799+
histories[0].values = { s: 0, histmissing: 1 };
800+
}
795801
}
796802

797803
const lastFieldsIndexes = histories.reduce((result, historyEntry, historyIndex) => {
@@ -3195,12 +3201,20 @@ async function giveObjHist({ cid, fetchId, showDiff }) {
31953201
historySelect.diff = 0;
31963202
}
31973203

3198-
const histories = await PhotoHistory
3204+
let histories = await PhotoHistory
31993205
.find({ cid }, historySelect, { lean: true, sort: { stamp: 1 } })
32003206
.populate({ path: 'user', select: { _id: 0, login: 1, avatar: 1, disp: 1 } }).exec();
32013207

32023208
if (_.isEmpty(histories)) {
3203-
throw new NoticeError(constantsError.HISTORY_DOESNT_EXISTS);
3209+
// This is workaround for old photos that did not have history. When
3210+
// this old photo is editied the first time, proper history record will be created.
3211+
const user = await User.findOne({ _id: photo.user }, { _id: 0, login: 1, avatar: 1, disp: 1 }).exec();
3212+
3213+
histories = [{
3214+
user,
3215+
stamp: photo.ldate,
3216+
values: { s: 0, histmissing: 1 },
3217+
}];
32043218
}
32053219

32063220
const reasons = new Set();

views/module/photo/hist.pug

+7-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
| Комментирование {{?h.values.nocomments}}запрещено{{??}}разрешено{{?}}
6666
| {{?}}
6767
68+
| {{?h.values.histmissing}}
69+
.info.iconed.red
70+
span.glyphicon(class="glyphicon-floppy-remove")
71+
| Доступна не вся история изменений
72+
| {{?}}
73+
6874
| {{?h.reason}}
6975
.value
7076
.name Причина
@@ -86,4 +92,4 @@
8692
| {{~}}
8793
8894
| {{~}}
89-
| </script>
95+
| </script>

0 commit comments

Comments
 (0)