mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-08 07:32:56 +02:00
Flags API (#9666)
* feat: new routes for flags API + flag get + flag creation, migration from socket method + flag update, migration from socket method * fixed bug where you could not unassign someone from a flag * feat: tests for new flags API added missing files for schema update * fix: flag tests to use Write API instead of sockets * feat: flag notes API + tests * chore: remove debug line * test: fix breaking test on mongo
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
define('forum/flags/detail', ['forum/flags/list', 'components', 'translator', 'benchpress', 'forum/account/header', 'accounts/delete'], function (FlagsList, components, translator, Benchpress, AccountHeader, AccountsDelete) {
|
||||
define('forum/flags/detail', ['forum/flags/list', 'components', 'translator', 'benchpress', 'forum/account/header', 'accounts/delete', 'api'], function (FlagsList, components, translator, Benchpress, AccountHeader, AccountsDelete, api) {
|
||||
var Detail = {};
|
||||
|
||||
Detail.init = function () {
|
||||
@@ -18,18 +18,18 @@ define('forum/flags/detail', ['forum/flags/list', 'components', 'translator', 'b
|
||||
$('#assignee').val(app.user.uid);
|
||||
// falls through
|
||||
|
||||
case 'update':
|
||||
socket.emit('flags.update', {
|
||||
flagId: ajaxify.data.flagId,
|
||||
data: $('#attributes').serializeArray(),
|
||||
}, function (err, history) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
case 'update': {
|
||||
const data = $('#attributes').serializeArray().reduce((memo, cur) => {
|
||||
memo[cur.name] = cur.value;
|
||||
return memo;
|
||||
}, {});
|
||||
|
||||
api.put(`/flags/${ajaxify.data.flagId}`, data).then((history) => {
|
||||
app.alertSuccess('[[flags:updated]]');
|
||||
Detail.reloadHistory(history);
|
||||
});
|
||||
}).catch(app.alertError);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'appendNote':
|
||||
socket.emit('flags.appendNote', {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
define('forum/flags/list', ['components', 'Chart', 'categoryFilter', 'autocomplete'], function (components, Chart, categoryFilter, autocomplete) {
|
||||
define('forum/flags/list', ['components', 'Chart', 'categoryFilter', 'autocomplete', 'api'], function (components, Chart, categoryFilter, autocomplete, api) {
|
||||
var Flags = {};
|
||||
|
||||
var selectedCids;
|
||||
@@ -149,26 +149,14 @@ define('forum/flags/list', ['components', 'Chart', 'categoryFilter', 'autocomple
|
||||
|
||||
switch (action) {
|
||||
case 'bulk-assign':
|
||||
socket.emit('flags.update', {
|
||||
flagId: flagId,
|
||||
data: [
|
||||
{
|
||||
name: 'assignee',
|
||||
value: app.user.uid,
|
||||
},
|
||||
],
|
||||
api.put(`/flags/${flagId}`, {
|
||||
assignee: app.user.uid,
|
||||
}, handler);
|
||||
break;
|
||||
|
||||
case 'bulk-mark-resolved':
|
||||
socket.emit('flags.update', {
|
||||
flagId: flagId,
|
||||
data: [
|
||||
{
|
||||
name: 'state',
|
||||
value: 'resolved',
|
||||
},
|
||||
],
|
||||
api.put(`/flags/${flagId}`, {
|
||||
state: 'resolved',
|
||||
}, handler);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
define('flags', ['hooks', 'components'], function (hooks, components) {
|
||||
define('flags', ['hooks', 'components', 'api'], function (hooks, components, api) {
|
||||
var Flag = {};
|
||||
var flagModal;
|
||||
var flagCommit;
|
||||
@@ -59,18 +59,12 @@ define('flags', ['hooks', 'components'], function (hooks, components) {
|
||||
};
|
||||
|
||||
Flag.resolve = function (flagId) {
|
||||
socket.emit('flags.update', {
|
||||
flagId: flagId,
|
||||
data: [
|
||||
{ name: 'state', value: 'resolved' },
|
||||
],
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
api.put(`/flags/${flagId}`, {
|
||||
state: 'resolved',
|
||||
}).then(() => {
|
||||
app.alertSuccess('[[flags:resolved]]');
|
||||
hooks.fire('action:flag.resolved', { flagId: flagId });
|
||||
});
|
||||
}).catch(app.alertError);
|
||||
};
|
||||
|
||||
function createFlag(type, id, reason) {
|
||||
@@ -78,7 +72,7 @@ define('flags', ['hooks', 'components'], function (hooks, components) {
|
||||
return;
|
||||
}
|
||||
var data = { type: type, id: id, reason: reason };
|
||||
socket.emit('flags.create', data, function (err, flagId) {
|
||||
api.post('/flags', data, function (err, flagId) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user