mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core: security: add operateIp for oplog
This commit is contained in:
1 parent
d058f7a208
commit
b902b54409
3 files changed
+30
-5
No files matched your search
@@ -243,6 +243,9 @@ class DiscussionDetailHandler extends DiscussionHandler {
|
||||
this.checkPerm(PERM.PERM_EDIT_DISCUSSION_REPLY_SELF);
|
||||
if (this.drdoc.owner !== this.user._id) throw new PermissionError(PERM.PERM_EDIT_DISCUSSION_REPLY_SELF);
|
||||
await discussion.editReply(domainId, drid, content);
|
||||
await oplog.add({
|
||||
...this.drdoc, operator: this.user._id, operateIp: this.request.ip, type: 'edit',
|
||||
});
|
||||
this.back();
|
||||
}
|
||||
|
||||
@@ -255,7 +258,9 @@ class DiscussionDetailHandler extends DiscussionHandler {
|
||||
} else this.checkPerm(PERM.PERM_DELETE_DISCUSSION_SELF);
|
||||
}
|
||||
await discussion.delReply(domainId, drid);
|
||||
await oplog.add({ ...this.drdoc, operator: this.user._id, type: 'drdoc' });
|
||||
await oplog.add({
|
||||
...this.drdoc, operator: this.user._id, operateIp: this.request.ip, type: 'delete',
|
||||
});
|
||||
this.back();
|
||||
}
|
||||
|
||||
@@ -264,8 +269,12 @@ class DiscussionDetailHandler extends DiscussionHandler {
|
||||
@param('content', Types.Content)
|
||||
async postEditTailReply(domainId: string, drid: ObjectID, drrid: ObjectID, content: string) {
|
||||
this.checkPerm(PERM.PERM_EDIT_DISCUSSION_REPLY_SELF);
|
||||
if (this.drdoc.owner !== this.user._id) throw new PermissionError(PERM.PERM_EDIT_DISCUSSION_REPLY_SELF);
|
||||
if (this.drrdoc.owner !== this.user._id) throw new PermissionError(PERM.PERM_EDIT_DISCUSSION_REPLY_SELF);
|
||||
await discussion.editTailReply(domainId, drid, drrid, content);
|
||||
// TODO: history?
|
||||
await oplog.add({
|
||||
...this.drrdoc, operator: this.user._id, operateIp: this.request.ip, type: 'edit',
|
||||
});
|
||||
this.back();
|
||||
}
|
||||
|
||||
@@ -274,7 +283,9 @@ class DiscussionDetailHandler extends DiscussionHandler {
|
||||
async postDeleteTailReply(domainId: string, drid: ObjectID, drrid: ObjectID) {
|
||||
if (this.drrdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_DELETE_DISCUSSION_REPLY);
|
||||
await discussion.delTailReply(domainId, drid, drrid);
|
||||
await oplog.add({ ...this.drrdoc, operator: this.user._id, type: 'drrdoc' });
|
||||
await oplog.add({
|
||||
...this.drrdoc, operator: this.user._id, operateIp: this.request.ip, type: 'delete',
|
||||
});
|
||||
this.back();
|
||||
}
|
||||
|
||||
@@ -339,6 +350,9 @@ class DiscussionEditHandler extends DiscussionHandler {
|
||||
if (!this.user.hasPerm(PERM.PERM_HIGHLIGHT_DISCUSSION)) highlight = this.ddoc.highlight;
|
||||
if (!this.user.hasPerm(PERM.PERM_PIN_DISCUSSION)) pin = this.ddoc.pin;
|
||||
await discussion.edit(domainId, did, title, content, highlight, pin);
|
||||
await oplog.add({
|
||||
...this.ddoc, operator: this.user._id, type: 'edit',
|
||||
});
|
||||
this.response.body = { did };
|
||||
this.response.redirect = this.url('discussion_detail', { did });
|
||||
}
|
||||
@@ -348,7 +362,9 @@ class DiscussionEditHandler extends DiscussionHandler {
|
||||
if (this.ddoc.owner !== this.user._id) this.checkPerm(PERM.PERM_DELETE_DISCUSSION);
|
||||
else this.checkPerm(PERM.PERM_DELETE_DISCUSSION_SELF);
|
||||
await discussion.del(domainId, did);
|
||||
await oplog.add({ ...this.ddoc, operator: this.user._id, type: 'ddoc' });
|
||||
await oplog.add({
|
||||
...this.ddoc, operator: this.user._id, operateIp: this.request.ip, type: 'delete',
|
||||
});
|
||||
this.response.body = { type: this.ddoc.parentType, parent: this.ddoc.parentId };
|
||||
this.response.redirect = this.url('discussion_node', {
|
||||
type: discussion.typeDisplay[this.ddoc.parentType],
|
||||
|
||||
@@ -5,7 +5,12 @@ import db from '../service/db';
|
||||
export const coll = db.collection('oplog');
|
||||
|
||||
export async function add(data: Partial<OplogDoc> & { type: string }): Promise<ObjectID> {
|
||||
const res = await coll.insertOne({ _id: new ObjectID(), ...data });
|
||||
const _data = { ...data };
|
||||
if (_data._id) {
|
||||
_data.id = _data._id;
|
||||
delete _data._id;
|
||||
}
|
||||
const res = await coll.insertOne({ _id: new ObjectID(), ..._data });
|
||||
return res.insertedId;
|
||||
}
|
||||
|
||||
|
||||
@@ -307,6 +307,10 @@ const scripts: UpgradeScript[] = [
|
||||
});
|
||||
return true;
|
||||
},
|
||||
async function _23_24() {
|
||||
await db.collection('oplog').updateMany({}, { $set: { type: 'delete', operateIp: '127.0.0.1' } });
|
||||
return true;
|
||||
},
|
||||
];
|
||||
|
||||
export default scripts;
|
||||
Reference in new issue
Block a user