Skip to content

Commit b49df5e

Browse files
authored
Merge pull request #136 from PretendoNetwork/work/audit-log
Work/audit log
2 parents 477c758 + 8c561b7 commit b49df5e

File tree

8 files changed

+367
-14
lines changed

8 files changed

+367
-14
lines changed

apps/juxtaposition-ui/src/database.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const { NOTIFICATION } = require('@/models/notifications');
88
const { POST } = require('@/models/post');
99
const { SETTINGS } = require('@/models/settings');
1010
const { REPORT } = require('@/models/report');
11+
const { LOGS } = require('@/models/logs');
1112
const { logger } = require('@/logger');
1213
const { config } = require('@/config');
1314

@@ -506,6 +507,11 @@ async function getReportById(id) {
506507
return REPORT.findById(id);
507508
}
508509

510+
async function getLogsForTarget(targetPID, offset, limit) {
511+
verifyConnected();
512+
return LOGS.find({ target: targetPID }).sort({ timestamp: -1 }).skip(offset).limit(limit);
513+
}
514+
509515
module.exports = {
510516
connect,
511517
getCommunities,
@@ -563,5 +569,6 @@ module.exports = {
563569
getReportsByOffender,
564570
getReportsByPost,
565571
getDuplicateReports,
566-
getReportById
572+
getReportById,
573+
getLogsForTarget
567574
};
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const { Schema, model } = require('mongoose');
2+
3+
const actionEnum = [
4+
'REMOVE_POST',
5+
'IGNORE_REPORT',
6+
'LIMIT_POSTING',
7+
'TEMP_BAN',
8+
'PERMA_BAN',
9+
'UNBAN',
10+
'UPDATE_USER',
11+
'MAKE_COMMUNITY',
12+
'UPDATE_COMMUNITY',
13+
'DELETE_COMMUNITY'
14+
];
15+
16+
const auditLogSchema = new Schema({
17+
actor: {
18+
type: Number,
19+
required: true
20+
},
21+
action: {
22+
type: String,
23+
enum: actionEnum,
24+
required: true
25+
},
26+
target: {
27+
type: String,
28+
required: true
29+
},
30+
context: {
31+
type: String,
32+
required: true
33+
},
34+
timestamp: {
35+
type: Date,
36+
default: Date.now,
37+
required: true
38+
},
39+
changed_fields: {
40+
type: [String],
41+
default: [],
42+
required: true
43+
}
44+
});
45+
46+
const LOGS = model('LOGS', auditLogSchema);
47+
48+
module.exports = {
49+
auditLogSchema,
50+
LOGS
51+
};

0 commit comments

Comments
 (0)