Files
NodeBB/src/flags.js

971 lines
29 KiB
JavaScript
Raw Normal View History

2016-11-23 19:41:35 -05:00
'use strict';
2019-09-24 00:30:59 -04:00
const _ = require('lodash');
const winston = require('winston');
const validator = require('validator');
const db = require('./database');
const user = require('./user');
const groups = require('./groups');
const meta = require('./meta');
const notifications = require('./notifications');
const analytics = require('./analytics');
2019-09-28 14:37:50 -04:00
const categories = require('./categories');
2019-09-24 00:30:59 -04:00
const topics = require('./topics');
const posts = require('./posts');
const privileges = require('./privileges');
const plugins = require('./plugins');
Webpack5 (#10311) * feat: webpack 5 part 1 * fix: gruntfile fixes * fix: fix taskbar warning add app.importScript copy public/src/modules to build folder * refactor: remove commented old code * feat: reenable admin * fix: acp settings pages, fix sortable on manage categories embedded require in html not allowed * fix: bundle serialize/deserizeli so plugins dont break * test: fixe util tests * test: fix require path * test: more test fixes * test: require correct utils module * test: require correct utils * test: log stack * test: fix db require blowing up tests * test: move and disable bundle test * refactor: add aliases * test: disable testing route * fix: move webpack modules necessary for build, into `dependencies` * test: fix one more test remove 500-embed.tpl * fix: restore use of assets/nodebb.min.js, at least for now * fix: remove unnecessary line break * fix: point to proper ACP bundle * test: maybe fix build test * test: composer * refactor: dont need dist * refactor: more cleanup use everything from build/public folder * get rid of conditional import in app.js * fix: ace * refactor: cropper alias * test: lint and test fixes * lint: fix * refactor: rename function to app.require * refactor: go back to using app.require * chore: use github branch * chore: use webpack branch * feat: webpack webinstaller * feat: add chunkFile name with contenthash * refactor: move hooks to top * refactor: get rid of template500Function * fix(deps): use webpack5 branch of 2factor plugin * chore: tagging v2.0.0-beta.0 pre-release version :boom: :shipit: :tada: :rocket: * refactor: disable cache on templates loadTemplate is called once by benchpress and the result is cache internally * refactor: add server side helpers.js * feat: deprecate /plugins shorthand route, closes #10343 * refactor: use build/public for webpack * test: fix filename * fix: more specific selector * lint: ignore * refactor: fix comments * test: add debug for random failing test * refactor: cleanup remove test page, remove dupe functions in utils.common * lint: use relative path for now * chore: bump prerelease version * feat: add translateKeys * fix: optional params * fix: get rid of extra timeago files * refactor: cleanup, require timeago locale earlier remove translator.prepareDOM, it is in header.tpl html tag * refactor: privileges system to use a Map in the backend instead of separate objects for keys and labels (#10378) * refactor: privileges system to use a Map in the backend instead of separate objects for keys and labels - Existing hooks are preserved (to be deprecated at a later date, possibly) - New init hooks are called on NodeBB start, and provide a one-stop shop to add new privileges, instead of having to add to four different hooks * docs: fix typo in comment * test: spec changes * refactor: privileges system to use a Map in the backend instead of separate objects for keys and labels (#10378) * refactor: privileges system to use a Map in the backend instead of separate objects for keys and labels - Existing hooks are preserved (to be deprecated at a later date, possibly) - New init hooks are called on NodeBB start, and provide a one-stop shop to add new privileges, instead of having to add to four different hooks * docs: fix typo in comment * test: spec changes * feat: allow app.require('bootbox'/'benchpressjs') * refactor: require server side utils * test: jquery ready * change istaller to use build/public * test: use document.addEventListener * refactor: closes #10301 * refactor: generateTopicClass * fix: column counts for other privileges * fix: #10443, regression where sorted-list items did not render into the DOM in the predicted order [breaking] * fix: typo in hook name * refactor: introduce a generic autocomplete.init() method that can be called to add nodebb-style autocompletion but using different data sources (e.g. not user/groups/tags) * fix: crash if `delay` not passed in (as it cannot be destructured) * refactor: replace substr * feat: set --panel-offset style in html element based on stored value in localStorage * refactor: addDropupHandler() logic to be less naive - Take into account height of the menu - Don't apply dropUp logic if there's nothing in the dropdown - Remove 'hidden' class (added by default in Persona for post tools) when menu items are added closes #10423 * refactor: simplify utils.params [breaking] Retrospective analysis of the usage of this method suggests that the options passed in are superfluous, and that only `url` is required. Using a browser built-in makes more sense to accomplish what this method sets out to do. * feat: add support for returning full URLSearchParams for utils.params * fix: utils.params() fallback handling * fix: default empty obj for params() * fix: remove \'loggedin\' and \'register\' qs parameters once they have been used, delay invocation of messages until ajaxify.end * fix: utils.params() not allowing relative paths to be passed in * refactor(DRY): new assertPasswordValidity utils method * fix: incorrect error message returned on insufficient privilege on flag edit * fix: read/update/delete access to flags API should be limited for moderators to only post flags in categories they moderate - added failing tests and patched up middleware.assert.flags to fix * refactor: flag api v3 tests to create new post and flags on every round * fix: missing error:no-flag language key * refactor: flags.canView to check flag existence, simplify middleware.assert.flag * feat: flag deletion API endpoint, #10426 * feat: UI for flag deletion, closes #10426 * chore: update plugin versions * chore: up emoji * chore: update markdown * chore: up emoji-android * fix: regression caused by utils.params() refactor, supports arrays and pipes all values through utils.toType, adjusts tests to type check Co-authored-by: Julian Lam <julian@nodebb.org>
2022-04-29 21:39:33 -04:00
const utils = require('./utils');
const batch = require('./batch');
2019-09-24 00:30:59 -04:00
const Flags = module.exports;
Flags._states = new Map([
['open', {
label: '[[flags:state-open]]',
class: 'danger',
}],
['wip', {
label: '[[flags:state-wip]]',
class: 'warning',
}],
['resolved', {
label: '[[flags:state-resolved]]',
class: 'success',
}],
['rejected', {
label: '[[flags:state-rejected]]',
class: 'secondary',
}],
]);
2019-09-24 00:30:59 -04:00
Flags.init = async function () {
2017-07-04 10:09:37 -04:00
// Query plugins for custom filter strategies and merge into core filter strategies
2019-09-24 00:30:59 -04:00
function prepareSets(sets, orSets, prefix, value) {
2017-07-04 10:09:37 -04:00
if (!Array.isArray(value)) {
sets.push(prefix + value);
} else if (value.length) {
if (value.length === 1) {
sets.push(prefix + value[0]);
} else {
orSets.push(value.map(x => prefix + x));
}
2017-07-04 10:09:37 -04:00
}
2019-09-24 00:30:59 -04:00
}
2017-07-04 10:09:37 -04:00
2019-09-24 00:30:59 -04:00
const hookData = {
2017-07-04 10:09:37 -04:00
filters: {
type: function (sets, orSets, key) {
prepareSets(sets, orSets, 'flags:byType:', key);
},
state: function (sets, orSets, key) {
prepareSets(sets, orSets, 'flags:byState:', key);
},
reporterId: function (sets, orSets, key) {
prepareSets(sets, orSets, 'flags:byReporter:', key);
},
assignee: function (sets, orSets, key) {
prepareSets(sets, orSets, 'flags:byAssignee:', key);
},
targetUid: function (sets, orSets, key) {
prepareSets(sets, orSets, 'flags:byTargetUid:', key);
},
cid: function (sets, orSets, key) {
prepareSets(sets, orSets, 'flags:byCid:', key);
},
2021-11-18 16:42:18 -05:00
page: function () { /* noop */ },
perPage: function () { /* noop */ },
2017-07-04 10:09:37 -04:00
quick: function (sets, orSets, key, uid) {
switch (key) {
2020-06-03 11:25:25 -04:00
case 'mine':
2021-02-03 23:59:08 -07:00
sets.push(`flags:byAssignee:${uid}`);
2020-06-03 11:25:25 -04:00
break;
case 'unresolved':
prepareSets(sets, orSets, 'flags:byState:', ['open', 'wip']);
break;
2017-07-04 10:09:37 -04:00
}
},
},
states: Flags._states,
2017-07-04 10:09:37 -04:00
helpers: {
prepareSets: prepareSets,
},
2019-09-24 00:30:59 -04:00
};
2017-07-04 10:09:37 -04:00
2019-09-24 00:30:59 -04:00
try {
({ filters: Flags._filters } = await plugins.hooks.fire('filter:flags.getFilters', hookData));
({ filters: Flags._filters, states: Flags._states } = await plugins.hooks.fire('filter:flags.init', hookData));
2019-09-24 00:30:59 -04:00
} catch (err) {
2021-02-03 23:59:08 -07:00
winston.error(`[flags/init] Could not retrieve filters\n${err.stack}`);
2019-09-24 00:30:59 -04:00
Flags._filters = {};
}
2017-07-04 10:09:37 -04:00
};
2019-09-24 00:30:59 -04:00
Flags.get = async function (flagId) {
const [base, notes, reports] = await Promise.all([
2021-02-03 23:59:08 -07:00
db.getObject(`flag:${flagId}`),
2019-09-24 00:30:59 -04:00
Flags.getNotes(flagId),
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
Flags.getReports(flagId),
2019-09-24 00:30:59 -04:00
]);
if (!base) {
return;
}
const flagObj = {
state: 'open',
2020-04-23 21:50:08 -04:00
assignee: null,
2019-09-24 00:30:59 -04:00
...base,
datetimeISO: utils.toISOString(base.datetime),
2021-02-03 23:59:08 -07:00
target_readable: `${base.type.charAt(0).toUpperCase() + base.type.slice(1)} ${base.targetId}`,
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
target: await Flags.getTarget(base.type, base.targetId, 0),
notes,
reports,
2019-09-24 00:30:59 -04:00
};
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
const data = await plugins.hooks.fire('filter:flags.get', {
2019-09-24 00:30:59 -04:00
flag: flagObj,
});
return data.flag;
};
Flags.getCount = async function ({ uid, filters, query }) {
filters = filters || {};
const flagIds = await Flags.getFlagIdsWithFilters({ filters, uid, query });
return flagIds.length;
};
2016-11-25 12:43:10 -05:00
Flags.getFlagIdsWithFilters = async function ({ filters, uid, query }) {
2019-09-26 22:51:11 -04:00
let sets = [];
const orSets = [];
2018-03-09 12:57:52 -05:00
// Default filter
filters.page = filters.hasOwnProperty('page') ? Math.abs(parseInt(filters.page, 10) || 1) : 1;
filters.perPage = filters.hasOwnProperty('perPage') ? Math.abs(parseInt(filters.perPage, 10) || 20) : 20;
2021-02-04 01:34:30 -07:00
for (const type of Object.keys(filters)) {
if (Flags._filters.hasOwnProperty(type)) {
Flags._filters[type](sets, orSets, filters[type], uid);
} else {
winston.warn(`[flags/list] No flag filter type found: ${type}`);
}
}
2021-11-18 16:42:18 -05:00
sets = (sets.length || orSets.length) ? sets : ['flags:datetime']; // No filter default
2019-09-26 22:51:11 -04:00
let flagIds = [];
if (sets.length === 1) {
flagIds = await db.getSortedSetRevRange(sets[0], 0, -1);
} else if (sets.length > 1) {
flagIds = await db.getSortedSetRevIntersect({ sets: sets, start: 0, stop: -1, aggregate: 'MAX' });
}
2016-12-06 16:11:56 -05:00
2019-09-26 22:51:11 -04:00
if (orSets.length) {
let _flagIds = await Promise.all(orSets.map(async orSet => await db.getSortedSetRevUnion({ sets: orSet, start: 0, stop: -1, aggregate: 'MAX' })));
// Each individual orSet is ANDed together to construct the final list of flagIds
_flagIds = _.intersection(..._flagIds);
// Merge with flagIds returned by sets
2019-09-26 22:51:11 -04:00
if (sets.length) {
// If flag ids are already present, return a subset of flags that are in both sets
flagIds = _.intersection(flagIds, _flagIds);
} else {
// Otherwise, return all flags returned via orSets
flagIds = _.union(flagIds, _flagIds);
2016-12-06 16:11:56 -05:00
}
2019-09-26 22:51:11 -04:00
}
2016-12-06 16:11:56 -05:00
const result = await plugins.hooks.fire('filter:flags.getFlagIdsWithFilters', {
filters,
uid,
query,
flagIds,
});
return result.flagIds;
};
Flags.list = async function (data) {
const filters = data.filters || {};
let flagIds = await Flags.getFlagIdsWithFilters({
filters,
uid: data.uid,
query: data.query,
});
2020-08-18 21:03:59 -04:00
flagIds = await Flags.sort(flagIds, data.sort);
Bootstrap5 (#10894) * chore: up deps * chore: up composer * fix(deps): bump 2factor to v7 * chore: up harmony * chore: up harmony * fix: missing await * feat: allow middlewares to pass in template values via res.locals * feat: buildAccountData middleware automatically added ot all account routes * fix: properly allow values in res.locals.templateValues to be added to the template data * refactor: user/blocks * refactor(accounts): categories and consent * feat: automatically 404 if exposeUid or exposeGroupName come up empty * refactor: remove calls to getUserDataByUserSlug for most account routes, since it is populated via middleware now * fix: allow exposeUid and exposeGroupName to work with slugs with mixed capitalization * fix: move reputation removal check to accountHelpers method * test: skip i18n tests if ref branch when present is not develop * fix(deps): bump theme versions * fix(deps): bump ntfy and 2factor * chore: up harmony * fix: add missing return * fix: #11191, only focus on search input on md environments and up * feat: allow file uploads on mobile chat closes https://github.com/NodeBB/NodeBB/issues/11217 * chore: up themes * chore: add lang string * fix(deps): bump ntfy to 1.0.15 * refactor: use new if/each syntax * chore: up composer * fix: regression from user helper refactor * chore: up harmony * chore: up composer * chore: up harmony * chore: up harmony * chore: up harmony * chore: fix composer version * feat: add increment helper * chore: up harmony * fix: #11228 no timestamps in future :hourglass: * chore: up harmony * check config.theme as well fire action:posts.loaded after processing dom * chore: up harmony * chore: up harmony * chore: up harmony * chore: up themes * chore: up harmony * remove extra class * refactor: move these to core from harmony * chore: up widgets * chore: up widgets * height auto * fix: closes #11238 * dont focus inputs, annoying on mobile * fix: dont focus twice, only focus on chat input on desktop dont wrap widget footer in row * chore: up harmony * chore: up harmony * update chat window * chore: up themes * fix cache buster for skins * chat fixes * chore: up harmony * chore: up composer * refactor: change hook logs to debug * fix: scroll to post right after adding to dom * fix: hash scrolling and highlighting correct post * test: re-enable read API schema tests * fix: add back schema changes for 179faa2270f2ad955dcc4a7b04755acce59e6ffd and c3920ccb10d8ead2dcd9914bb1784bed3f6adfd4 * fix: schema changes from 488f0978a4aa1ca1e4d2a1f2e8c7ef7a681f2f27 * fix: schema changes for f4cf482a874701ce80c0f306c49d8788cec66f87 * fix: schema update for be6bbabd0e2551fbe9571dcf3ee40ad721764543 * fix: schema changes for 69c96078ea78ee2c45885a90a6f6a59f9042a33c * fix: schema changes for d1364c313021e48a879a818b24947e1457c062f7 * fix: schema changes for 84ff1152f7552dd866e25a90972d970b9861107e * fix: schema changes for b860c2605c209e0650ef98f4c80d842ea23a51ce * fix: schema changes for 23cb67a1126481848fac39aafd1e253441e76d7f * fix: schema changes for b916e42f400dac8aa51670b15e439f87f0eb8939 * fix: schema change for a9bbb586fcb3a1c61b5fb69052236e78cdf7d743 * fix: schema changes for 4b738c8cd36c936a1dbe2bb900c694bf6c5520ec * fix: schema changes for 58b5781cea9acb129e6604a82ab5a5bfc0d8394d * fix: schema changes for 794bf01b21709c4be06584d576d706b3d6342057 * fix: schema changes for 80ea12c1c1963f5b39fb64841e4f3c8da3c87af2, e368feef51e0766f119c9710fb4db8f64724725c, and 52ead114bec961c62fa2eb0786540e229f6e4873 * fix: composer-default object in config? * fix: schema changes for 9acdc6808c070555352951c651921df181b10993 and 093093420027999df3c67bf0ea6024f6dbf81d2d * fix: schema changes for c0a52924f1f7ef8caeaacda67363ac269b56042c * fix: schema change for aba420a3f3b774e949c2539c73f3dc0e1ae79a38, move loggedInUser to optional props * fix: schema changes for 8c67031609da30d788561459f8bb76e9a69253de * fix: schema changes for 27e53b42f3ce48fa61d3754375715cd41ffe808d * fix: schema changes for 28359665187b0a3b9ec6226dca1234ebdbd725a5 * fix: breaking test for email confirmation API call * fix: schema changes for refactored search page * fix: schema changes for user object * fix: schema changes for 9f531f957e08eabb4bae844ddd67bde14d9b59f0 * fix: schema changes for c4042c70decd628e5b880bd109515b47e4e16164 and 23175110a29640e6fa052db1079bfedb34a61055 * fix: schema changes for 9b3616b10392e247974eb0c1e6225a1582bf6c69 * fix: schema changes for 5afd5de07d42fd33f039a6f85ded3b4992200e5a * fix: schema change for 1d7baf12171cffbd3af8914bef4e6297d1160d49 * fix: schema changes for 57bfb37c55a839662144e684875003ab52315ecc and be6bbabd0e2551fbe9571dcf3ee40ad721764543 * fix: schema changes for 6e86b4afa20d662af8b9f1c07518df2d8c258105 and 3efad2e13b7319eb9a1f4fda7af047be43ebc11f and 68f66223e73a72f378f193c83a9b5546bede2cda * fix: allowing optional qs prop in pagination keys (not sure why this didn't break before) * fix: re-login on email change * fix: schema changes for c926358d734a2fa410de87f4e4a91744215fc14a * fix: schema changes for 388a8270c9882892bad5c8141f65da8d59eac0fd * fix: schema change for 2658bcc821c22e137a6eeb9bb74098856a642eaf * fix: no need to call account middlewares for chats routes * fix: schema changes for 71743affc3e58dc85d4ffa15ce043d4d9ddd3d67 * fix: final schema changes * test: support for anyOf and oneOf * fix: check thumb * dont scroll to top on back press * remove group log * fix: add top margin to merged and deleted alerts * chore: up widgets * fix: improve fix-lists mixin * chore: up harmony/composer * feat: allow hiding quicksearch results during search * dont record searches made by composer * chore: up 54 * chore: up spam be gone * feat: add prev/next page and page count into mobile paginator * chore: up harmony * chore: up harmony * use old style for IS * fix: hide entire toolbar row if no posts or not singlePost * fix: updated messaging for post-queue template, #11206 * fix: btn-sm on post queue back button * fix: bump harmony, closes #11206 * fix: remove unused alert module import * fix: bump harmony * fix: bump harmony * chore: up harmony * refactor: IS scrolltop * fix: update users:search-user-for-chat source string * feat: support for mark-read toggle on chats dropdown and recent chats list * feat: api v3 calls to mark chat read/unread * feat: send event:chats.mark socket event on mark read or unread * refactor: allow frontend to mark chats as unread, use new API v3 routes instead of socket calls, better frontend event handling * docs: openapi schema updates for chat marking * fix: allow unread state toggling in chats dropdown too * fix: issue where repeated openings of the chats dropdown would continually add events for mark-read/unread * fix: debug log * refactor: move userSearch filter to a module * feat(routes): allow remounting /categories (#11230) * feat: send flags count to frontend on flags list page * refactor: filter form client-side js to extract out some logic * fix: applyFilters to not take any arguments, update selectedCids in updateButton instead of onHidden * fix: use userFilter module for assignee, reporterId, targetUid * fix(openapi): schema changes for updated flags page * fix: dont allow adding duplicates to userFilter * use same var * remove log * fix: closes #11282 * feat: lang key for x-topics * chore: up harmony * chore: up emoji * chore: up harmony * fix: update userFilter to allow new option `selectedBlock` * fix: wrong block name passed to userFilter * fix: https://github.com/NodeBB/NodeBB/issues/11283 * fix: chats, allow multiple dropdowns like in harmony * chore: up harmony * refactor: flag note adding/editing, closes #11285 * fix: remove old prepareEdit logic * chore: add caveat about hacky code block in userFilter module * fix: placeholders for userFilter module * refactor: navigator so it works with multiple thumbs/navigators * chore: up harmony * fix: closes #11287, destroy quick reply autocomplete on navigation * fix: filter disabled categories on user categories page count * chore: up harmony * docs: update openapi spec to include info about passing in timestamps for topic creation, removing timestamp as valid request param for topic replying * fix: send back null values on ACP search dashboard for startDate and endDate if not expicitly passed in, fix tests * fix: tweak table order in ACP dash searches * fix: only invoke navigator click drag on left mouse button * feat: add back unread indicator to navigator * clear bookmark on mark unread * fix: navigator crash on ajaxify * better thumb top calculation * fix: reset user bookmark when topic is marked unread * Revert "fix: reset user bookmark when topic is marked unread" This reverts commit 9bcd85c2c6848c3d325d32027261809da6e11c9e. * fix: update unread indicator on scroll, add unread count * chore: bump harmony * fix: crash on navigator unread update when backing out of a topic * fix: closes #11183 * fix: update topics:recent zset when rescheduling a topic * fix: dupe quote button, increase delay, hide immediately on empty selection * fix: navigator not showing up on first load * refactor: remove glance assorted fixes to navigator dont reduce remaning count if user scrolls down and up quickly only call topic.navigatorCallback when index changes * more sanity checks for bookmark dont allow setting bookmark higher than topic postcount * closes #11218, :train: * Revert "fix: update topics:recent zset when rescheduling a topic" This reverts commit 737973cca9e94b6cb3867492a09e1e0b1af391d5. * fix: #11306, show proper error if queued post doesn't exist was showing no-privileges if someone else accepted the post * https://github.com/NodeBB/NodeBB/issues/11307 dont use li * chore: up harmony * chore: bump version string * fix: copy paste fail * feat: closes #7382, tag filtering add client side support for filtering by tags on /category, /recent and /unread * chore: up harmony * chore: up harmony * Revert "fix: add back req.query fallback for backwards compatibility" [breaking] This reverts commit cf6cc2c454dc35c330393c62ee8ce67b42d8eefb. This commit is no longer required as passing in a CSRF token via query parameter is no longer supported as of NodeBB v3.x This is a breaking change. * fix: pass csrf token in form data, re: NodeBB/NodeBB#11309 * chore: up deps * fix: tests, use x-csrf-token query param removed * test: fix csrf_token * lint: remove unused * feat: add itemprop="image" to avatar helper * fix: get chat upload button in chat modal * breaking: remove deprecated socket.io methods * test: update messaging tests to not use sockets * fix: parent post links * fix: prevent post tooltip if mouse leaves before data/tpl is loaded * chore: up harmony * chore: up harmony * chore: up harmony * chore: up harmony * fix: nested replies indices * fix(deps): bump 2factor * feat: add loggedIn user to all api routes * chore: up themes * refactor: audit admin v3 write api routes as per #11321 * refactor: audit category v3 write api routes as per #11321 [breaking] docs: fix open api spec for #11321 * refactor: audit chat v3 write api routes as per #11321 * refactor: audit files v3 write api routes as per #11321 * refactor: audit flags v3 write api routes as per #11321 * refactor: audit posts v3 write api routes as per #11321 * refactor: audit topics v3 write api routes as per #11321 * refactor: audit users v3 write api routes as per #11321 * fix: lang string * remove min height * fix: empty topic/labels taking up space * fix: tag filtering when changing filter to watched topics or changing popular time limit to month * chore: up harmony * fix: closes #11354, show no post error if queued post already accepted/rejected * test: #11354 * test: #11354 * fix(deps): bump 2factor * fix: #11357 clear cache on thumb remove * fix: thumb remove on windows, closes #11357 * test: openapi for thumbs * test: fix openapi --------- Co-authored-by: Julian Lam <julian@nodebb.org> Co-authored-by: Opliko <opliko.reg@protonmail.com>
2023-03-17 11:58:31 -04:00
const count = flagIds.length;
2020-08-18 21:03:59 -04:00
2019-09-26 22:51:11 -04:00
// Create subset for parsing based on page number (n=20)
const flagsPerPage = Math.abs(parseInt(filters.perPage, 10) || 1);
const pageCount = Math.ceil(flagIds.length / flagsPerPage);
flagIds = flagIds.slice((filters.page - 1) * flagsPerPage, filters.page * flagsPerPage);
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
const reportCounts = await db.sortedSetsCard(flagIds.map(flagId => `flag:${flagId}:reports`));
const flags = await Promise.all(flagIds.map(async (flagId, idx) => {
2021-02-03 23:59:08 -07:00
let flagObj = await db.getObject(`flag:${flagId}`);
2019-09-26 22:51:11 -04:00
flagObj = {
state: 'open',
2020-04-23 21:50:08 -04:00
assignee: null,
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
heat: reportCounts[idx],
2019-09-26 22:51:11 -04:00
...flagObj,
};
flagObj.labelClass = Flags._states.get(flagObj.state).class;
2019-09-26 22:51:11 -04:00
return Object.assign(flagObj, {
2021-02-03 23:59:08 -07:00
target_readable: `${flagObj.type.charAt(0).toUpperCase() + flagObj.type.slice(1)} ${flagObj.targetId}`,
2019-09-26 22:51:11 -04:00
datetimeISO: utils.toISOString(flagObj.datetime),
});
}));
const payload = await plugins.hooks.fire('filter:flags.list', {
2019-09-26 22:51:11 -04:00
flags: flags,
page: filters.page,
2020-08-18 21:03:59 -04:00
uid: data.uid,
2019-09-26 22:51:11 -04:00
});
2019-09-26 22:51:11 -04:00
return {
2020-08-18 21:03:59 -04:00
flags: payload.flags,
Bootstrap5 (#10894) * chore: up deps * chore: up composer * fix(deps): bump 2factor to v7 * chore: up harmony * chore: up harmony * fix: missing await * feat: allow middlewares to pass in template values via res.locals * feat: buildAccountData middleware automatically added ot all account routes * fix: properly allow values in res.locals.templateValues to be added to the template data * refactor: user/blocks * refactor(accounts): categories and consent * feat: automatically 404 if exposeUid or exposeGroupName come up empty * refactor: remove calls to getUserDataByUserSlug for most account routes, since it is populated via middleware now * fix: allow exposeUid and exposeGroupName to work with slugs with mixed capitalization * fix: move reputation removal check to accountHelpers method * test: skip i18n tests if ref branch when present is not develop * fix(deps): bump theme versions * fix(deps): bump ntfy and 2factor * chore: up harmony * fix: add missing return * fix: #11191, only focus on search input on md environments and up * feat: allow file uploads on mobile chat closes https://github.com/NodeBB/NodeBB/issues/11217 * chore: up themes * chore: add lang string * fix(deps): bump ntfy to 1.0.15 * refactor: use new if/each syntax * chore: up composer * fix: regression from user helper refactor * chore: up harmony * chore: up composer * chore: up harmony * chore: up harmony * chore: up harmony * chore: fix composer version * feat: add increment helper * chore: up harmony * fix: #11228 no timestamps in future :hourglass: * chore: up harmony * check config.theme as well fire action:posts.loaded after processing dom * chore: up harmony * chore: up harmony * chore: up harmony * chore: up themes * chore: up harmony * remove extra class * refactor: move these to core from harmony * chore: up widgets * chore: up widgets * height auto * fix: closes #11238 * dont focus inputs, annoying on mobile * fix: dont focus twice, only focus on chat input on desktop dont wrap widget footer in row * chore: up harmony * chore: up harmony * update chat window * chore: up themes * fix cache buster for skins * chat fixes * chore: up harmony * chore: up composer * refactor: change hook logs to debug * fix: scroll to post right after adding to dom * fix: hash scrolling and highlighting correct post * test: re-enable read API schema tests * fix: add back schema changes for 179faa2270f2ad955dcc4a7b04755acce59e6ffd and c3920ccb10d8ead2dcd9914bb1784bed3f6adfd4 * fix: schema changes from 488f0978a4aa1ca1e4d2a1f2e8c7ef7a681f2f27 * fix: schema changes for f4cf482a874701ce80c0f306c49d8788cec66f87 * fix: schema update for be6bbabd0e2551fbe9571dcf3ee40ad721764543 * fix: schema changes for 69c96078ea78ee2c45885a90a6f6a59f9042a33c * fix: schema changes for d1364c313021e48a879a818b24947e1457c062f7 * fix: schema changes for 84ff1152f7552dd866e25a90972d970b9861107e * fix: schema changes for b860c2605c209e0650ef98f4c80d842ea23a51ce * fix: schema changes for 23cb67a1126481848fac39aafd1e253441e76d7f * fix: schema changes for b916e42f400dac8aa51670b15e439f87f0eb8939 * fix: schema change for a9bbb586fcb3a1c61b5fb69052236e78cdf7d743 * fix: schema changes for 4b738c8cd36c936a1dbe2bb900c694bf6c5520ec * fix: schema changes for 58b5781cea9acb129e6604a82ab5a5bfc0d8394d * fix: schema changes for 794bf01b21709c4be06584d576d706b3d6342057 * fix: schema changes for 80ea12c1c1963f5b39fb64841e4f3c8da3c87af2, e368feef51e0766f119c9710fb4db8f64724725c, and 52ead114bec961c62fa2eb0786540e229f6e4873 * fix: composer-default object in config? * fix: schema changes for 9acdc6808c070555352951c651921df181b10993 and 093093420027999df3c67bf0ea6024f6dbf81d2d * fix: schema changes for c0a52924f1f7ef8caeaacda67363ac269b56042c * fix: schema change for aba420a3f3b774e949c2539c73f3dc0e1ae79a38, move loggedInUser to optional props * fix: schema changes for 8c67031609da30d788561459f8bb76e9a69253de * fix: schema changes for 27e53b42f3ce48fa61d3754375715cd41ffe808d * fix: schema changes for 28359665187b0a3b9ec6226dca1234ebdbd725a5 * fix: breaking test for email confirmation API call * fix: schema changes for refactored search page * fix: schema changes for user object * fix: schema changes for 9f531f957e08eabb4bae844ddd67bde14d9b59f0 * fix: schema changes for c4042c70decd628e5b880bd109515b47e4e16164 and 23175110a29640e6fa052db1079bfedb34a61055 * fix: schema changes for 9b3616b10392e247974eb0c1e6225a1582bf6c69 * fix: schema changes for 5afd5de07d42fd33f039a6f85ded3b4992200e5a * fix: schema change for 1d7baf12171cffbd3af8914bef4e6297d1160d49 * fix: schema changes for 57bfb37c55a839662144e684875003ab52315ecc and be6bbabd0e2551fbe9571dcf3ee40ad721764543 * fix: schema changes for 6e86b4afa20d662af8b9f1c07518df2d8c258105 and 3efad2e13b7319eb9a1f4fda7af047be43ebc11f and 68f66223e73a72f378f193c83a9b5546bede2cda * fix: allowing optional qs prop in pagination keys (not sure why this didn't break before) * fix: re-login on email change * fix: schema changes for c926358d734a2fa410de87f4e4a91744215fc14a * fix: schema changes for 388a8270c9882892bad5c8141f65da8d59eac0fd * fix: schema change for 2658bcc821c22e137a6eeb9bb74098856a642eaf * fix: no need to call account middlewares for chats routes * fix: schema changes for 71743affc3e58dc85d4ffa15ce043d4d9ddd3d67 * fix: final schema changes * test: support for anyOf and oneOf * fix: check thumb * dont scroll to top on back press * remove group log * fix: add top margin to merged and deleted alerts * chore: up widgets * fix: improve fix-lists mixin * chore: up harmony/composer * feat: allow hiding quicksearch results during search * dont record searches made by composer * chore: up 54 * chore: up spam be gone * feat: add prev/next page and page count into mobile paginator * chore: up harmony * chore: up harmony * use old style for IS * fix: hide entire toolbar row if no posts or not singlePost * fix: updated messaging for post-queue template, #11206 * fix: btn-sm on post queue back button * fix: bump harmony, closes #11206 * fix: remove unused alert module import * fix: bump harmony * fix: bump harmony * chore: up harmony * refactor: IS scrolltop * fix: update users:search-user-for-chat source string * feat: support for mark-read toggle on chats dropdown and recent chats list * feat: api v3 calls to mark chat read/unread * feat: send event:chats.mark socket event on mark read or unread * refactor: allow frontend to mark chats as unread, use new API v3 routes instead of socket calls, better frontend event handling * docs: openapi schema updates for chat marking * fix: allow unread state toggling in chats dropdown too * fix: issue where repeated openings of the chats dropdown would continually add events for mark-read/unread * fix: debug log * refactor: move userSearch filter to a module * feat(routes): allow remounting /categories (#11230) * feat: send flags count to frontend on flags list page * refactor: filter form client-side js to extract out some logic * fix: applyFilters to not take any arguments, update selectedCids in updateButton instead of onHidden * fix: use userFilter module for assignee, reporterId, targetUid * fix(openapi): schema changes for updated flags page * fix: dont allow adding duplicates to userFilter * use same var * remove log * fix: closes #11282 * feat: lang key for x-topics * chore: up harmony * chore: up emoji * chore: up harmony * fix: update userFilter to allow new option `selectedBlock` * fix: wrong block name passed to userFilter * fix: https://github.com/NodeBB/NodeBB/issues/11283 * fix: chats, allow multiple dropdowns like in harmony * chore: up harmony * refactor: flag note adding/editing, closes #11285 * fix: remove old prepareEdit logic * chore: add caveat about hacky code block in userFilter module * fix: placeholders for userFilter module * refactor: navigator so it works with multiple thumbs/navigators * chore: up harmony * fix: closes #11287, destroy quick reply autocomplete on navigation * fix: filter disabled categories on user categories page count * chore: up harmony * docs: update openapi spec to include info about passing in timestamps for topic creation, removing timestamp as valid request param for topic replying * fix: send back null values on ACP search dashboard for startDate and endDate if not expicitly passed in, fix tests * fix: tweak table order in ACP dash searches * fix: only invoke navigator click drag on left mouse button * feat: add back unread indicator to navigator * clear bookmark on mark unread * fix: navigator crash on ajaxify * better thumb top calculation * fix: reset user bookmark when topic is marked unread * Revert "fix: reset user bookmark when topic is marked unread" This reverts commit 9bcd85c2c6848c3d325d32027261809da6e11c9e. * fix: update unread indicator on scroll, add unread count * chore: bump harmony * fix: crash on navigator unread update when backing out of a topic * fix: closes #11183 * fix: update topics:recent zset when rescheduling a topic * fix: dupe quote button, increase delay, hide immediately on empty selection * fix: navigator not showing up on first load * refactor: remove glance assorted fixes to navigator dont reduce remaning count if user scrolls down and up quickly only call topic.navigatorCallback when index changes * more sanity checks for bookmark dont allow setting bookmark higher than topic postcount * closes #11218, :train: * Revert "fix: update topics:recent zset when rescheduling a topic" This reverts commit 737973cca9e94b6cb3867492a09e1e0b1af391d5. * fix: #11306, show proper error if queued post doesn't exist was showing no-privileges if someone else accepted the post * https://github.com/NodeBB/NodeBB/issues/11307 dont use li * chore: up harmony * chore: bump version string * fix: copy paste fail * feat: closes #7382, tag filtering add client side support for filtering by tags on /category, /recent and /unread * chore: up harmony * chore: up harmony * Revert "fix: add back req.query fallback for backwards compatibility" [breaking] This reverts commit cf6cc2c454dc35c330393c62ee8ce67b42d8eefb. This commit is no longer required as passing in a CSRF token via query parameter is no longer supported as of NodeBB v3.x This is a breaking change. * fix: pass csrf token in form data, re: NodeBB/NodeBB#11309 * chore: up deps * fix: tests, use x-csrf-token query param removed * test: fix csrf_token * lint: remove unused * feat: add itemprop="image" to avatar helper * fix: get chat upload button in chat modal * breaking: remove deprecated socket.io methods * test: update messaging tests to not use sockets * fix: parent post links * fix: prevent post tooltip if mouse leaves before data/tpl is loaded * chore: up harmony * chore: up harmony * chore: up harmony * chore: up harmony * fix: nested replies indices * fix(deps): bump 2factor * feat: add loggedIn user to all api routes * chore: up themes * refactor: audit admin v3 write api routes as per #11321 * refactor: audit category v3 write api routes as per #11321 [breaking] docs: fix open api spec for #11321 * refactor: audit chat v3 write api routes as per #11321 * refactor: audit files v3 write api routes as per #11321 * refactor: audit flags v3 write api routes as per #11321 * refactor: audit posts v3 write api routes as per #11321 * refactor: audit topics v3 write api routes as per #11321 * refactor: audit users v3 write api routes as per #11321 * fix: lang string * remove min height * fix: empty topic/labels taking up space * fix: tag filtering when changing filter to watched topics or changing popular time limit to month * chore: up harmony * fix: closes #11354, show no post error if queued post already accepted/rejected * test: #11354 * test: #11354 * fix(deps): bump 2factor * fix: #11357 clear cache on thumb remove * fix: thumb remove on windows, closes #11357 * test: openapi for thumbs * test: fix openapi --------- Co-authored-by: Julian Lam <julian@nodebb.org> Co-authored-by: Opliko <opliko.reg@protonmail.com>
2023-03-17 11:58:31 -04:00
count,
2020-08-18 21:03:59 -04:00
page: payload.page,
2019-09-26 22:51:11 -04:00
pageCount: pageCount,
};
};
2017-02-24 12:47:46 -05:00
2020-08-18 21:03:59 -04:00
Flags.sort = async function (flagIds, sort) {
const filterPosts = async (flagIds) => {
const keys = flagIds.map(id => `flag:${id}`);
const types = await db.getObjectsFields(keys, ['type']);
return flagIds.filter((id, idx) => types[idx].type === 'post');
};
2020-08-18 21:03:59 -04:00
switch (sort) {
// 'newest' is not handled because that is default
case 'oldest':
flagIds = flagIds.reverse();
break;
case 'reports': {
const keys = flagIds.map(id => `flag:${id}:reports`);
const heat = await db.sortedSetsCard(keys);
const mapped = heat.map((el, i) => ({
index: i, heat: el,
}));
2021-02-04 00:01:39 -07:00
mapped.sort((a, b) => b.heat - a.heat);
2020-08-18 21:03:59 -04:00
flagIds = mapped.map(obj => flagIds[obj.index]);
break;
}
2021-11-18 16:42:18 -05:00
case 'upvotes': // fall-through
case 'downvotes':
case 'replies': {
flagIds = await filterPosts(flagIds);
const keys = flagIds.map(id => `flag:${id}`);
const pids = (await db.getObjectsFields(keys, ['targetId'])).map(obj => obj.targetId);
const votes = (await posts.getPostsFields(pids, [sort])).map(obj => parseInt(obj[sort], 10) || 0);
const sortRef = flagIds.reduce((memo, cur, idx) => {
memo[cur] = votes[idx];
return memo;
}, {});
flagIds = flagIds.sort((a, b) => sortRef[b] - sortRef[a]);
}
2020-08-18 21:03:59 -04:00
}
2020-08-18 21:03:59 -04:00
return flagIds;
};
2019-09-26 22:51:11 -04:00
Flags.validate = async function (payload) {
const [target, reporter] = await Promise.all([
Flags.getTarget(payload.type, payload.id, payload.uid),
user.getUserData(payload.uid),
]);
2019-09-26 22:51:11 -04:00
if (!target) {
throw new Error('[[error:invalid-data]]');
} else if (target.deleted) {
throw new Error('[[error:post-deleted]]');
} else if (!reporter || !reporter.userslug) {
throw new Error('[[error:no-user]]');
} else if (reporter.banned) {
throw new Error('[[error:user-banned]]');
}
2017-02-24 12:47:46 -05:00
// Disallow flagging of profiles/content of privileged users
const [targetPrivileged, reporterPrivileged] = await Promise.all([
user.isPrivileged(target.uid),
user.isPrivileged(reporter.uid),
]);
if (targetPrivileged && !reporterPrivileged) {
throw new Error('[[error:cant-flag-privileged]]');
}
2019-09-26 22:51:11 -04:00
if (payload.type === 'post') {
const editable = await privileges.posts.canEdit(payload.id, payload.uid);
if (!editable.flag && !meta.config['reputation:disabled'] && reporter.reputation < meta.config['min:rep:flag']) {
throw new Error(`[[error:not-enough-reputation-to-flag, ${meta.config['min:rep:flag']}]]`);
2017-02-24 12:47:46 -05:00
}
2019-09-26 22:51:11 -04:00
} else if (payload.type === 'user') {
if (parseInt(payload.id, 10) === parseInt(payload.uid, 10)) {
throw new Error('[[error:cant-flag-self]]');
}
2019-09-26 22:51:11 -04:00
const editable = await privileges.users.canEdit(payload.uid, payload.id);
if (!editable && !meta.config['reputation:disabled'] && reporter.reputation < meta.config['min:rep:flag']) {
throw new Error(`[[error:not-enough-reputation-to-flag, ${meta.config['min:rep:flag']}]]`);
2019-09-26 22:51:11 -04:00
}
} else {
throw new Error('[[error:invalid-data]]');
}
2016-12-06 16:11:56 -05:00
};
2019-09-26 22:51:11 -04:00
Flags.getNotes = async function (flagId) {
2021-02-03 23:59:08 -07:00
let notes = await db.getSortedSetRevRangeWithScores(`flag:${flagId}:notes`, 0, -1);
notes = await modifyNotes(notes);
return notes;
};
Flags.getNote = async function (flagId, datetime) {
datetime = parseInt(datetime, 10);
if (isNaN(datetime)) {
throw new Error('[[error:invalid-data]]');
}
2021-02-03 23:59:08 -07:00
let notes = await db.getSortedSetRangeByScoreWithScores(`flag:${flagId}:notes`, 0, 1, datetime, datetime);
if (!notes.length) {
throw new Error('[[error:invalid-data]]');
}
notes = await modifyNotes(notes);
return notes[0];
};
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
Flags.getFlagIdByTarget = async function (type, id) {
let method;
switch (type) {
case 'post':
method = posts.getPostField;
break;
case 'user':
method = user.getUserField;
break;
default:
throw new Error('[[error:invalid-data]]');
}
return await method(id, 'flagId');
};
async function modifyNotes(notes) {
2019-09-26 22:51:11 -04:00
const uids = [];
2021-02-04 00:01:39 -07:00
notes = notes.map((note) => {
2019-09-26 22:51:11 -04:00
const noteObj = JSON.parse(note.value);
uids.push(noteObj[0]);
return {
uid: noteObj[0],
content: noteObj[1],
datetime: note.score,
datetimeISO: utils.toISOString(note.score),
};
});
const userData = await user.getUsersFields(uids, ['username', 'userslug', 'picture']);
2021-02-04 00:01:39 -07:00
return notes.map((note, idx) => {
2019-09-26 22:51:11 -04:00
note.user = userData[idx];
note.content = validator.escape(note.content);
return note;
});
}
Flags.deleteNote = async function (flagId, datetime) {
datetime = parseInt(datetime, 10);
if (isNaN(datetime)) {
throw new Error('[[error:invalid-data]]');
}
2021-02-03 23:59:08 -07:00
const note = await db.getSortedSetRangeByScore(`flag:${flagId}:notes`, 0, 1, datetime, datetime);
if (!note.length) {
throw new Error('[[error:invalid-data]]');
}
2021-02-03 23:59:08 -07:00
await db.sortedSetRemove(`flag:${flagId}:notes`, note[0]);
};
Flags.create = async function (type, id, uid, reason, timestamp, forceFlag = false) {
2019-09-26 22:51:11 -04:00
let doHistoryAppend = false;
if (!timestamp) {
2016-12-09 14:33:59 -05:00
timestamp = Date.now();
doHistoryAppend = true;
}
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
const [flagExists, targetExists,, targetFlagged, targetUid, targetCid] = await Promise.all([
2019-09-26 22:51:11 -04:00
// Sanity checks
Flags.exists(type, id, uid),
Flags.targetExists(type, id),
Flags.canFlag(type, id, uid, forceFlag),
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
Flags.targetFlagged(type, id),
2019-09-26 22:51:11 -04:00
// Extra data for zset insertion
Flags.getTargetUid(type, id),
Flags.getTargetCid(type, id),
]);
if (!forceFlag && flagExists) {
throw new Error(`[[error:${type}-already-flagged]]`);
2019-09-26 22:51:11 -04:00
} else if (!targetExists) {
throw new Error('[[error:invalid-data]]');
}
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
// If the flag already exists, just add the report
if (targetFlagged) {
const flagId = await Flags.getFlagIdByTarget(type, id);
await Promise.all([
Flags.addReport(flagId, type, id, uid, reason, timestamp),
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
Flags.update(flagId, uid, { state: 'open' }),
]);
2019-09-26 22:51:11 -04:00
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
return await Flags.get(flagId);
}
const flagId = await db.incrObjectField('global', 'nextFlagId');
const batched = [];
batched.push(
2021-02-03 23:59:08 -07:00
db.setObject(`flag:${flagId}`, {
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
flagId: flagId,
type: type,
targetId: id,
targetUid: targetUid,
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
datetime: timestamp,
}),
Flags.addReport(flagId, type, id, uid, reason, timestamp),
2020-07-25 09:14:13 -04:00
db.sortedSetAdd('flags:datetime', timestamp, flagId), // by time, the default
2021-11-18 16:42:18 -05:00
db.sortedSetAdd(`flags:byType:${type}`, timestamp, flagId), // by flag type
db.sortedSetIncrBy('flags:byTarget', 1, [type, id].join(':')), // by flag target (score is count)
2020-07-25 09:14:13 -04:00
analytics.increment('flags') // some fancy analytics
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
);
2019-09-26 22:51:11 -04:00
if (targetUid) {
2021-02-03 23:59:08 -07:00
batched.push(db.sortedSetAdd(`flags:byTargetUid:${targetUid}`, timestamp, flagId)); // by target uid
2019-09-26 22:51:11 -04:00
}
2016-12-06 16:11:56 -05:00
2019-09-26 22:51:11 -04:00
if (targetCid) {
2021-02-03 23:59:08 -07:00
batched.push(db.sortedSetAdd(`flags:byCid:${targetCid}`, timestamp, flagId)); // by target cid
2019-09-26 22:51:11 -04:00
}
2017-11-12 08:45:08 -05:00
2019-09-26 22:51:11 -04:00
if (type === 'post') {
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
batched.push(
2021-11-18 16:42:18 -05:00
db.sortedSetAdd(`flags:byPid:${id}`, timestamp, flagId), // by target pid
2020-07-25 09:14:13 -04:00
posts.setPostField(id, 'flagId', flagId)
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
);
if (targetUid && parseInt(targetUid, 10) !== parseInt(uid, 10)) {
2020-07-25 09:14:13 -04:00
batched.push(user.incrementUserFlagsBy(targetUid, 1));
2019-09-26 22:51:11 -04:00
}
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
} else if (type === 'user') {
2020-07-25 09:14:13 -04:00
batched.push(user.setUserField(id, 'flagId', flagId));
2019-09-26 22:51:11 -04:00
}
2017-02-24 12:47:46 -05:00
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
// Run all the database calls in one single batched call...
2020-07-25 09:14:13 -04:00
await Promise.all(batched);
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
2019-09-26 22:51:11 -04:00
if (doHistoryAppend) {
2021-03-15 17:55:14 -04:00
await Flags.update(flagId, uid, { state: 'open' });
2019-09-26 22:51:11 -04:00
}
2016-12-09 14:33:59 -05:00
const flagObj = await Flags.get(flagId);
plugins.hooks.fire('action:flags.create', { flag: flagObj });
return flagObj;
2016-11-23 19:41:35 -05:00
};
2022-03-23 15:10:10 -04:00
Flags.purge = async function (flagIds) {
const flagData = (await db.getObjects(flagIds.map(flagId => `flag:${flagId}`))).filter(Boolean);
const postFlags = flagData.filter(flagObj => flagObj.type === 'post');
const userFlags = flagData.filter(flagObj => flagObj.type === 'user');
const assignedFlags = flagData.filter(flagObj => !!flagObj.assignee);
2022-03-23 18:38:36 -04:00
const [allReports, cids] = await Promise.all([
db.getSortedSetsMembers(flagData.map(flagObj => `flag:${flagObj.flagId}:reports`)),
2022-03-23 18:38:36 -04:00
categories.getAllCidsFromSet('categories:cid'),
]);
2022-03-23 15:10:10 -04:00
const allReporterUids = allReports.map(flagReports => flagReports.map(report => report && report.split(';')[0]));
const removeReporters = [];
flagData.forEach((flagObj, i) => {
if (Array.isArray(allReporterUids[i])) {
allReporterUids[i].forEach((uid) => {
removeReporters.push([`flags:hash`, [flagObj.type, flagObj.targetId, uid].join(':')]);
removeReporters.push([`flags:byReporter:${uid}`, flagObj.flagId]);
});
}
});
await Promise.all([
db.sortedSetRemoveBulk([
...flagData.map(flagObj => ([`flags:byType:${flagObj.type}`, flagObj.flagId])),
...flagData.map(flagObj => ([`flags:byState:${flagObj.state}`, flagObj.flagId])),
...removeReporters,
...postFlags.map(flagObj => ([`flags:byPid:${flagObj.targetId}`, flagObj.flagId])),
...assignedFlags.map(flagObj => ([`flags:byAssignee:${flagObj.assignee}`, flagObj.flagId])),
...userFlags.map(flagObj => ([`flags:byTargetUid:${flagObj.targetUid}`, flagObj.flagId])),
]),
db.deleteObjectFields(postFlags.map(flagObj => `post:${flagObj.targetId}`, ['flagId'])),
db.deleteObjectFields(userFlags.map(flagObj => `user:${flagObj.targetId}`, ['flagId'])),
2022-03-23 15:10:10 -04:00
db.deleteAll([
...flagIds.map(flagId => `flag:${flagId}`),
...flagIds.map(flagId => `flag:${flagId}:notes`),
...flagIds.map(flagId => `flag:${flagId}:reports`),
2022-03-23 19:07:18 -04:00
...flagIds.map(flagId => `flag:${flagId}:history`),
2022-03-23 15:10:10 -04:00
]),
2022-03-23 18:38:36 -04:00
db.sortedSetRemove(cids.map(cid => `flags:byCid:${cid}`), flagIds),
2022-03-23 15:10:10 -04:00
db.sortedSetRemove('flags:datetime', flagIds),
db.sortedSetRemove(
'flags:byTarget',
flagData.map(flagObj => [flagObj.type, flagObj.targetId].join(':'))
),
]);
};
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
Flags.getReports = async function (flagId) {
const payload = await db.getSortedSetRevRangeWithScores(`flag:${flagId}:reports`, 0, -1);
2021-02-04 00:01:39 -07:00
const [reports, uids] = payload.reduce((memo, cur) => {
const value = cur.value.split(';');
memo[1].push(value.shift());
2021-04-09 14:20:42 -04:00
cur.value = validator.escape(String(value.join(';')));
memo[0].push(cur);
return memo;
}, [[], []]);
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
await Promise.all(reports.map(async (report, idx) => {
report.timestamp = report.score;
report.timestampISO = new Date(report.score).toISOString();
delete report.score;
report.reporter = await user.getUserFields(uids[idx], ['username', 'userslug', 'picture', 'reputation']);
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
}));
return reports;
};
Flags.addReport = async function (flagId, type, id, uid, reason, timestamp) {
await db.sortedSetAddBulk([
[`flags:byReporter:${uid}`, timestamp, flagId],
[`flag:${flagId}:reports`, timestamp, [uid, reason].join(';')],
['flags:hash', flagId, [type, id, uid].join(':')],
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
]);
2021-03-11 21:43:11 -05:00
plugins.hooks.fire('action:flags.addReport', { flagId, type, id, uid, reason, timestamp });
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
};
2019-09-24 00:30:59 -04:00
Flags.exists = async function (type, id, uid) {
return await db.isSortedSetMember('flags:hash', [type, id, uid].join(':'));
2016-11-23 19:41:35 -05:00
};
Webpack5 (#10311) * feat: webpack 5 part 1 * fix: gruntfile fixes * fix: fix taskbar warning add app.importScript copy public/src/modules to build folder * refactor: remove commented old code * feat: reenable admin * fix: acp settings pages, fix sortable on manage categories embedded require in html not allowed * fix: bundle serialize/deserizeli so plugins dont break * test: fixe util tests * test: fix require path * test: more test fixes * test: require correct utils module * test: require correct utils * test: log stack * test: fix db require blowing up tests * test: move and disable bundle test * refactor: add aliases * test: disable testing route * fix: move webpack modules necessary for build, into `dependencies` * test: fix one more test remove 500-embed.tpl * fix: restore use of assets/nodebb.min.js, at least for now * fix: remove unnecessary line break * fix: point to proper ACP bundle * test: maybe fix build test * test: composer * refactor: dont need dist * refactor: more cleanup use everything from build/public folder * get rid of conditional import in app.js * fix: ace * refactor: cropper alias * test: lint and test fixes * lint: fix * refactor: rename function to app.require * refactor: go back to using app.require * chore: use github branch * chore: use webpack branch * feat: webpack webinstaller * feat: add chunkFile name with contenthash * refactor: move hooks to top * refactor: get rid of template500Function * fix(deps): use webpack5 branch of 2factor plugin * chore: tagging v2.0.0-beta.0 pre-release version :boom: :shipit: :tada: :rocket: * refactor: disable cache on templates loadTemplate is called once by benchpress and the result is cache internally * refactor: add server side helpers.js * feat: deprecate /plugins shorthand route, closes #10343 * refactor: use build/public for webpack * test: fix filename * fix: more specific selector * lint: ignore * refactor: fix comments * test: add debug for random failing test * refactor: cleanup remove test page, remove dupe functions in utils.common * lint: use relative path for now * chore: bump prerelease version * feat: add translateKeys * fix: optional params * fix: get rid of extra timeago files * refactor: cleanup, require timeago locale earlier remove translator.prepareDOM, it is in header.tpl html tag * refactor: privileges system to use a Map in the backend instead of separate objects for keys and labels (#10378) * refactor: privileges system to use a Map in the backend instead of separate objects for keys and labels - Existing hooks are preserved (to be deprecated at a later date, possibly) - New init hooks are called on NodeBB start, and provide a one-stop shop to add new privileges, instead of having to add to four different hooks * docs: fix typo in comment * test: spec changes * refactor: privileges system to use a Map in the backend instead of separate objects for keys and labels (#10378) * refactor: privileges system to use a Map in the backend instead of separate objects for keys and labels - Existing hooks are preserved (to be deprecated at a later date, possibly) - New init hooks are called on NodeBB start, and provide a one-stop shop to add new privileges, instead of having to add to four different hooks * docs: fix typo in comment * test: spec changes * feat: allow app.require('bootbox'/'benchpressjs') * refactor: require server side utils * test: jquery ready * change istaller to use build/public * test: use document.addEventListener * refactor: closes #10301 * refactor: generateTopicClass * fix: column counts for other privileges * fix: #10443, regression where sorted-list items did not render into the DOM in the predicted order [breaking] * fix: typo in hook name * refactor: introduce a generic autocomplete.init() method that can be called to add nodebb-style autocompletion but using different data sources (e.g. not user/groups/tags) * fix: crash if `delay` not passed in (as it cannot be destructured) * refactor: replace substr * feat: set --panel-offset style in html element based on stored value in localStorage * refactor: addDropupHandler() logic to be less naive - Take into account height of the menu - Don't apply dropUp logic if there's nothing in the dropdown - Remove 'hidden' class (added by default in Persona for post tools) when menu items are added closes #10423 * refactor: simplify utils.params [breaking] Retrospective analysis of the usage of this method suggests that the options passed in are superfluous, and that only `url` is required. Using a browser built-in makes more sense to accomplish what this method sets out to do. * feat: add support for returning full URLSearchParams for utils.params * fix: utils.params() fallback handling * fix: default empty obj for params() * fix: remove \'loggedin\' and \'register\' qs parameters once they have been used, delay invocation of messages until ajaxify.end * fix: utils.params() not allowing relative paths to be passed in * refactor(DRY): new assertPasswordValidity utils method * fix: incorrect error message returned on insufficient privilege on flag edit * fix: read/update/delete access to flags API should be limited for moderators to only post flags in categories they moderate - added failing tests and patched up middleware.assert.flags to fix * refactor: flag api v3 tests to create new post and flags on every round * fix: missing error:no-flag language key * refactor: flags.canView to check flag existence, simplify middleware.assert.flag * feat: flag deletion API endpoint, #10426 * feat: UI for flag deletion, closes #10426 * chore: update plugin versions * chore: up emoji * chore: update markdown * chore: up emoji-android * fix: regression caused by utils.params() refactor, supports arrays and pipes all values through utils.toType, adjusts tests to type check Co-authored-by: Julian Lam <julian@nodebb.org>
2022-04-29 21:39:33 -04:00
Flags.canView = async (flagId, uid) => {
const exists = await db.isSortedSetMember('flags:datetime', flagId);
if (!exists) {
return false;
}
const [{ type, targetId }, isAdminOrGlobalMod] = await Promise.all([
db.getObject(`flag:${flagId}`),
user.isAdminOrGlobalMod(uid),
]);
if (type === 'post') {
const cid = await Flags.getTargetCid(type, targetId);
const isModerator = await user.isModerator(uid, cid);
return isAdminOrGlobalMod || isModerator;
}
return isAdminOrGlobalMod;
};
Flags.canFlag = async function (type, id, uid, skipLimitCheck = false) {
const limit = meta.config['flags:limitPerTarget'];
if (!skipLimitCheck && limit > 0) {
const score = await db.sortedSetScore('flags:byTarget', `${type}:${id}`);
if (score >= limit) {
throw new Error(`[[error:${type}-flagged-too-many-times]]`);
}
}
const canRead = await privileges.posts.can('topics:read', id, uid);
switch (type) {
case 'user':
return true;
case 'post':
if (!canRead) {
throw new Error('[[error:no-privileges]]');
}
break;
default:
throw new Error('[[error:invalid-data]]');
}
};
2019-09-24 00:30:59 -04:00
Flags.getTarget = async function (type, id, uid) {
if (type === 'user') {
const userData = await user.getUserData(id);
return userData && userData.uid ? userData : {};
}
if (type === 'post') {
let postData = await posts.getPostData(id);
if (!postData) {
return {};
}
postData = await posts.parsePost(postData);
postData = await topics.addPostData([postData], uid);
return postData[0];
}
throw new Error('[[error:invalid-data]]');
};
2019-09-24 00:30:59 -04:00
Flags.targetExists = async function (type, id) {
if (type === 'post') {
return await posts.exists(id);
} else if (type === 'user') {
return await user.exists(id);
2016-11-23 19:41:35 -05:00
}
2019-09-24 00:30:59 -04:00
throw new Error('[[error:invalid-data]]');
2016-11-23 19:41:35 -05:00
};
feat: consolidation of flags to reduce flagspam, #8510 Squashed commit of the following: commit c6d09396208a10c244d7b3d22ffd2d7dd1274d3a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 13:41:32 2020 -0400 fix: more tests commit 32f9af2a87a81fa62ecca01e71d6f0d5b9d37ba1 Merge: e50907535 4eae927d1 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:53:04 2020 -0400 Merge remote-tracking branch 'origin/master' into singleton-flags commit e50907535109dbdbe8f15c3e2fcdf22d90b1332a Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 24 10:52:46 2020 -0400 fix: controllers-admin test commit fd5af99e303de48a80b0ccc166eee19175cf232b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:26:55 2020 -0400 fix(tests): dummy commit to trigger travisCI commit c452a6ffcfaef91403de084c4ae16795cb23c60e Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 17:05:09 2020 -0400 fix(openapi): openapi spec changes commit 8089a74e89128141ab1e6f8ff83447114b3b846b Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:48:00 2020 -0400 fix: reversing the order of reports for display purposes commit a099892b377333561c72f1ad5b6b20ddb4ce8a96 Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:45:44 2020 -0400 refactor: run all flag creation calls in a single batch commit b24999682f9d5a33a08a049749c1f0eb4f00facc Author: Julian Lam <julian@nodebb.org> Date: Fri Jul 17 15:08:23 2020 -0400 feat: handling multiple reporters per flag, #8510 commit 08c75c020021ada754bf0e39eae77d631b01dee5 Author: Julian Lam <julian@nodebb.org> Date: Thu Jul 16 20:53:18 2020 -0400 feat: upgrade script for #8510
2020-07-24 14:10:37 -04:00
Flags.targetFlagged = async function (type, id) {
return await db.sortedSetScore('flags:byTarget', [type, id].join(':')) >= 1;
};
2019-09-24 00:30:59 -04:00
Flags.getTargetUid = async function (type, id) {
if (type === 'post') {
return await posts.getPostField(id, 'uid');
2016-12-06 16:11:56 -05:00
}
2019-09-24 00:30:59 -04:00
return id;
2016-12-06 16:11:56 -05:00
};
2019-09-24 00:30:59 -04:00
Flags.getTargetCid = async function (type, id) {
if (type === 'post') {
return await posts.getCidByPid(id);
}
return null;
};
2019-09-28 14:37:50 -04:00
Flags.update = async function (flagId, uid, changeset) {
2021-02-03 23:59:08 -07:00
const current = await db.getObjectFields(`flag:${flagId}`, ['uid', 'state', 'assignee', 'type', 'targetId']);
if (!current.type) {
return;
}
2019-09-28 14:37:50 -04:00
const now = changeset.datetime || Date.now();
const notifyAssignee = async function (assigneeId) {
if (assigneeId === '' || parseInt(uid, 10) === parseInt(assigneeId, 10)) {
2019-09-28 14:37:50 -04:00
return;
}
2019-09-28 14:37:50 -04:00
const notifObj = await notifications.create({
type: 'my-flags',
2021-02-03 23:59:08 -07:00
bodyShort: `[[notifications:flag_assigned_to_you, ${flagId}]]`,
bodyLong: '',
2021-02-03 23:59:08 -07:00
path: `/flags/${flagId}`,
nid: `flags:assign:${flagId}:uid:${assigneeId}`,
from: uid,
});
2019-09-28 14:37:50 -04:00
await notifications.push(notifObj, [assigneeId]);
};
const isAssignable = async function (assigneeId) {
let allowed = false;
allowed = await user.isAdminOrGlobalMod(assigneeId);
// Mods are also allowed to be assigned, if flag target is post in uid's moderated cid
if (!allowed && current.type === 'post') {
const cid = await posts.getCidByPid(current.targetId);
allowed = await user.isModerator(assigneeId, cid);
}
return allowed;
};
2016-11-23 19:41:35 -05:00
async function rescindNotifications(match) {
const nids = await db.getSortedSetScan({ key: 'notifications', match: `${match}*` });
return notifications.rescind(nids);
}
// Retrieve existing flag data to compare for history-saving/reference purposes
2019-09-28 14:37:50 -04:00
const tasks = [];
2021-02-04 01:34:30 -07:00
for (const prop of Object.keys(changeset)) {
if (current[prop] === changeset[prop]) {
delete changeset[prop];
} else if (prop === 'state') {
if (!Flags._states.has(changeset[prop])) {
2019-09-28 14:37:50 -04:00
delete changeset[prop];
2021-02-04 01:34:30 -07:00
} else {
tasks.push(db.sortedSetAdd(`flags:byState:${changeset[prop]}`, now, flagId));
tasks.push(db.sortedSetRemove(`flags:byState:${current[prop]}`, flagId));
if (changeset[prop] === 'resolved' && meta.config['flags:actionOnResolve'] === 'rescind') {
tasks.push(rescindNotifications(`flag:${current.type}:${current.targetId}`));
}
if (changeset[prop] === 'rejected' && meta.config['flags:actionOnReject'] === 'rescind') {
tasks.push(rescindNotifications(`flag:${current.type}:${current.targetId}`));
}
2016-11-23 19:41:35 -05:00
}
2021-02-04 01:34:30 -07:00
} else if (prop === 'assignee') {
if (changeset[prop] === '') {
tasks.push(db.sortedSetRemove(`flags:byAssignee:${changeset[prop]}`, flagId));
2021-02-04 01:34:30 -07:00
/* eslint-disable-next-line */
} else if (!await isAssignable(parseInt(changeset[prop], 10))) {
2021-02-04 01:34:30 -07:00
delete changeset[prop];
} else {
tasks.push(db.sortedSetAdd(`flags:byAssignee:${changeset[prop]}`, now, flagId));
tasks.push(notifyAssignee(changeset[prop]));
}
2019-09-28 14:37:50 -04:00
}
}
2016-11-23 19:41:35 -05:00
2019-09-28 14:37:50 -04:00
if (!Object.keys(changeset).length) {
return;
}
2017-01-12 10:03:45 -05:00
2021-02-03 23:59:08 -07:00
tasks.push(db.setObject(`flag:${flagId}`, changeset));
2019-09-28 14:37:50 -04:00
tasks.push(Flags.appendHistory(flagId, uid, changeset));
await Promise.all(tasks);
plugins.hooks.fire('action:flags.update', { flagId: flagId, changeset: changeset, uid: uid });
};
Flags.resolveFlag = async function (type, id, uid) {
const flagId = await Flags.getFlagIdByTarget(type, id);
if (parseInt(flagId, 10)) {
await Flags.update(flagId, uid, { state: 'resolved' });
}
2016-11-23 19:41:35 -05:00
};
Flags.resolveUserPostFlags = async function (uid, callerUid) {
if (meta.config['flags:autoResolveOnBan']) {
2021-02-04 00:01:39 -07:00
await batch.processSortedSet(`uid:${uid}:posts`, async (pids) => {
let postData = await posts.getPostsFields(pids, ['pid', 'flagId']);
postData = postData.filter(p => p && p.flagId);
for (const postObj of postData) {
if (parseInt(postObj.flagId, 10)) {
// eslint-disable-next-line no-await-in-loop
await Flags.update(postObj.flagId, callerUid, { state: 'resolved' });
}
}
}, {
batch: 500,
});
}
};
2019-09-28 14:37:50 -04:00
Flags.getHistory = async function (flagId) {
const uids = [];
2021-02-03 23:59:08 -07:00
let history = await db.getSortedSetRevRangeWithScores(`flag:${flagId}:history`, 0, -1);
const targetUid = await db.getObjectField(`flag:${flagId}`, 'targetUid');
2021-02-04 00:01:39 -07:00
history = history.map((entry) => {
2019-09-28 14:37:50 -04:00
entry.value = JSON.parse(entry.value);
2019-09-28 14:37:50 -04:00
uids.push(entry.value[0]);
2019-09-28 14:37:50 -04:00
// Deserialise changeset
const changeset = entry.value[1];
if (changeset.hasOwnProperty('state')) {
2021-02-03 23:59:08 -07:00
changeset.state = changeset.state === undefined ? '' : `[[flags:state-${changeset.state}]]`;
2019-09-28 14:37:50 -04:00
}
2019-09-28 14:37:50 -04:00
return {
uid: entry.value[0],
fields: changeset,
datetime: entry.score,
datetimeISO: utils.toISOString(entry.score),
};
});
// turn assignee uids into usernames
await Promise.all(history.map(async (entry) => {
if (entry.fields.hasOwnProperty('assignee')) {
entry.fields.assignee = await user.getUserField(entry.fields.assignee, 'username');
}
}));
// Append ban history and username change data
history = await mergeBanHistory(history, targetUid, uids);
2022-05-15 22:26:35 -04:00
history = await mergeMuteHistory(history, targetUid, uids);
history = await mergeUsernameEmailChanges(history, targetUid, uids);
2019-09-28 14:37:50 -04:00
const userData = await user.getUsersFields(uids, ['username', 'userslug', 'picture']);
history.forEach((event, idx) => { event.user = userData[idx]; });
// Resort by date
history = history.sort((a, b) => b.datetime - a.datetime);
2019-09-28 14:37:50 -04:00
return history;
};
2019-09-28 14:37:50 -04:00
Flags.appendHistory = async function (flagId, uid, changeset) {
const datetime = changeset.datetime || Date.now();
2016-12-09 14:33:59 -05:00
delete changeset.datetime;
2019-09-28 14:37:50 -04:00
const payload = JSON.stringify([uid, changeset, datetime]);
2021-02-03 23:59:08 -07:00
await db.sortedSetAdd(`flag:${flagId}:history`, datetime, payload);
};
2016-11-23 19:41:35 -05:00
2019-09-28 14:37:50 -04:00
Flags.appendNote = async function (flagId, uid, note, datetime) {
if (datetime) {
try {
await Flags.deleteNote(flagId, datetime);
} catch (e) {
// Do not throw if note doesn't exist
if (!e.message === '[[error:invalid-data]]') {
throw e;
}
}
}
2019-09-28 14:37:50 -04:00
datetime = datetime || Date.now();
2019-09-28 14:37:50 -04:00
const payload = JSON.stringify([uid, note]);
2021-02-03 23:59:08 -07:00
await db.sortedSetAdd(`flag:${flagId}:notes`, datetime, payload);
2019-09-28 15:08:51 -04:00
await Flags.appendHistory(flagId, uid, {
2019-09-28 14:37:50 -04:00
notes: null,
datetime: datetime,
});
2016-11-23 19:41:35 -05:00
};
Flags.notify = async function (flagObj, uid, notifySelf = false) {
2019-09-28 14:37:50 -04:00
const [admins, globalMods] = await Promise.all([
groups.getMembers('administrators', 0, -1),
groups.getMembers('Global Moderators', 0, -1),
]);
let uids = admins.concat(globalMods);
let notifObj = null;
const { displayname } = flagObj.reports[flagObj.reports.length - 1].reporter;
2019-09-28 14:37:50 -04:00
if (flagObj.type === 'post') {
const [title, cid] = await Promise.all([
topics.getTitleByPid(flagObj.targetId),
posts.getCidByPid(flagObj.targetId),
]);
const modUids = await categories.getModeratorUids([cid]);
const titleEscaped = utils.decodeHTMLEntities(title).replace(/%/g, '&#37;').replace(/,/g, '&#44;');
notifObj = await notifications.create({
type: 'new-post-flag',
bodyShort: `[[notifications:user_flagged_post_in, ${displayname}, ${titleEscaped}]]`,
2021-03-15 17:55:14 -04:00
bodyLong: await plugins.hooks.fire('filter:parse.raw', String(flagObj.description || '')),
2019-09-28 14:37:50 -04:00
pid: flagObj.targetId,
2021-02-03 23:59:08 -07:00
path: `/flags/${flagObj.flagId}`,
nid: `flag:post:${flagObj.targetId}:${uid}`,
2019-09-28 14:37:50 -04:00
from: uid,
2021-02-03 23:59:08 -07:00
mergeId: `notifications:user_flagged_post_in|${flagObj.targetId}`,
2019-09-28 14:37:50 -04:00
topicTitle: title,
2017-02-24 12:47:46 -05:00
});
2019-09-28 14:37:50 -04:00
uids = uids.concat(modUids[0]);
} else if (flagObj.type === 'user') {
const targetDisplayname = flagObj.target && flagObj.target.user ? flagObj.target.user.displayname : '[[global:guest]]';
2019-09-28 14:37:50 -04:00
notifObj = await notifications.create({
type: 'new-user-flag',
bodyShort: `[[notifications:user_flagged_user, ${displayname}, ${targetDisplayname}]]`,
2021-03-15 17:55:14 -04:00
bodyLong: await plugins.hooks.fire('filter:parse.raw', String(flagObj.description || '')),
2021-02-03 23:59:08 -07:00
path: `/flags/${flagObj.flagId}`,
nid: `flag:user:${flagObj.targetId}:${uid}`,
2019-09-28 14:37:50 -04:00
from: uid,
2021-02-03 23:59:08 -07:00
mergeId: `notifications:user_flagged_user|${flagObj.targetId}`,
2017-02-24 12:47:46 -05:00
});
2019-09-28 14:37:50 -04:00
} else {
throw new Error('[[error:invalid-data]]');
2016-12-06 16:11:56 -05:00
}
2019-09-28 14:37:50 -04:00
plugins.hooks.fire('action:flags.notify', {
2019-09-28 14:37:50 -04:00
flag: flagObj,
notification: notifObj,
from: uid,
to: uids,
2019-09-28 14:37:50 -04:00
});
if (!notifySelf) {
uids = uids.filter(_uid => parseInt(_uid, 10) !== parseInt(uid, 10));
}
2019-09-28 14:37:50 -04:00
await notifications.push(notifObj, uids);
2016-12-06 16:11:56 -05:00
};
2019-07-22 18:16:18 -04:00
async function mergeBanHistory(history, targetUid, uids) {
2022-05-15 22:26:35 -04:00
return await mergeBanMuteHistory(history, uids, {
set: `uid:${targetUid}:bans:timestamp`,
label: '[[user:banned]]',
reasonDefault: '[[user:info.banned-no-reason]]',
expiryKey: '[[user:info.banned-expiry]]',
});
}
async function mergeMuteHistory(history, targetUid, uids) {
return await mergeBanMuteHistory(history, uids, {
set: `uid:${targetUid}:mutes:timestamp`,
label: '[[user:muted]]',
reasonDefault: '[[user:info.muted-no-reason]]',
expiryKey: '[[user:info.muted-expiry]]',
});
}
async function mergeBanMuteHistory(history, uids, params) {
let recentObjs = await db.getSortedSetRevRange(params.set, 0, 19);
recentObjs = await db.getObjects(recentObjs);
2022-05-15 22:26:35 -04:00
return history.concat(recentObjs.reduce((memo, cur) => {
uids.push(cur.fromUid);
memo.push({
uid: cur.fromUid,
meta: [
{
2022-05-15 22:26:35 -04:00
key: params.label,
value: validator.escape(String(cur.reason || params.reasonDefault)),
labelClass: 'danger',
},
{
2022-05-15 22:26:35 -04:00
key: params.expiryKey,
value: new Date(parseInt(cur.expire, 10)).toISOString(),
labelClass: 'default',
},
],
datetime: parseInt(cur.timestamp, 10),
datetimeISO: utils.toISOString(parseInt(cur.timestamp, 10)),
});
return memo;
}, []));
}
async function mergeUsernameEmailChanges(history, targetUid, uids) {
2021-02-03 23:59:08 -07:00
const usernameChanges = await user.getHistory(`user:${targetUid}:usernames`);
const emailChanges = await user.getHistory(`user:${targetUid}:emails`);
return history.concat(usernameChanges.reduce((memo, changeObj) => {
uids.push(targetUid);
memo.push({
uid: targetUid,
meta: [
{
key: '[[user:change_username]]',
value: changeObj.value,
labelClass: 'primary',
},
],
datetime: changeObj.timestamp,
datetimeISO: changeObj.timestampISO,
});
return memo;
}, [])).concat(emailChanges.reduce((memo, changeObj) => {
uids.push(targetUid);
memo.push({
uid: targetUid,
meta: [
{
key: '[[user:change_email]]',
value: changeObj.value,
labelClass: 'primary',
},
],
datetime: changeObj.timestamp,
datetimeISO: changeObj.timestampISO,
});
return memo;
}, []));
}
2019-07-22 18:16:18 -04:00
require('./promisify')(Flags);