nodebb-plugin-admin-chats 3.7.0 → 3.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/routes.js +30 -0
- package/package.json +1 -1
- package/plugin.json +1 -0
- package/public/languages/ar/admin-chats.json +2 -1
- package/public/languages/de/admin-chats.json +2 -1
- package/public/languages/de-CH/admin-chats.json +2 -1
- package/public/languages/el/admin-chats.json +2 -1
- package/public/languages/en/admin-chats.json +2 -1
- package/public/languages/en-GB/admin-chats.json +2 -1
- package/public/languages/es/admin-chats.json +2 -1
- package/public/languages/fr/admin-chats.json +2 -1
- package/public/languages/fr-CH/admin-chats.json +2 -1
- package/public/languages/he/admin-chats.json +2 -1
- package/public/languages/hi/admin-chats.json +2 -1
- package/public/languages/it/admin-chats.json +2 -1
- package/public/languages/it-CH/admin-chats.json +2 -1
- package/public/languages/ja/admin-chats.json +2 -1
- package/public/languages/nl/admin-chats.json +2 -1
- package/public/languages/pl/admin-chats.json +2 -1
- package/public/languages/pt-BR/admin-chats.json +2 -1
- package/public/languages/rm-CH/admin-chats.json +2 -1
- package/public/languages/ru/admin-chats.json +2 -1
- package/public/languages/uk/admin-chats.json +2 -1
- package/public/languages/zh-CN/admin-chats.json +2 -1
- package/public/languages/zh-TW/admin-chats.json +2 -1
- package/static/lib/delete-room.js +67 -0
- package/static/lib/live-updates.js +0 -14
- package/templates/partials/chats/options.tpl +8 -1
package/lib/routes.js
CHANGED
|
@@ -352,6 +352,36 @@ function registerRoutes(app, router, middleware) {
|
|
|
352
352
|
}
|
|
353
353
|
});
|
|
354
354
|
|
|
355
|
+
// Room deletion from the admin-chats page. Core's DELETE
|
|
356
|
+
// /api/v3/admin/chats/:roomId is gated on real admin privileges
|
|
357
|
+
// (middleware.admin.checkPrivileges), so holders of the
|
|
358
|
+
// admin-chats:manage privilege cannot use it — this endpoint accepts
|
|
359
|
+
// them too. Goes through Messaging.deleteRooms, so the activity-set
|
|
360
|
+
// wrapper (lib/activity.js) prunes the deleted room from the admin list.
|
|
361
|
+
router.delete('/api/admin-chats/:roomId', ...routeMiddleware, async (req, res) => {
|
|
362
|
+
try {
|
|
363
|
+
const roomId = parseInt(req.params.roomId, 10);
|
|
364
|
+
|
|
365
|
+
if (!req.uid || Number.isNaN(roomId)) {
|
|
366
|
+
return res.status(400).json({ status: { code: 'bad-request', message: 'Invalid room id' } });
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (!await User.isAdministrator(req.uid) && !await canManageAdminChats(req.uid)) {
|
|
370
|
+
return res.status(403).json({ status: { code: 'forbidden', message: 'Admin or manage privilege required' } });
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (!await roomExists(roomId)) {
|
|
374
|
+
return res.status(404).json({ status: { code: 'not-found', message: 'Room not found' } });
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
await Messaging.deleteRooms([roomId]);
|
|
378
|
+
|
|
379
|
+
return res.json({ status: { code: 'ok', message: 'Room deleted' }, roomId });
|
|
380
|
+
} catch (err) {
|
|
381
|
+
return res.status(500).json({ status: { code: 'error', message: err.message } });
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
|
|
355
385
|
router.get('/api/admin-chats/:roomId/lock', ...routeMiddleware, async (req, res) => {
|
|
356
386
|
try {
|
|
357
387
|
const roomId = parseInt(req.params.roomId, 10);
|
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "לא ניתן לטעון או לעדכן את היסטוריית העריכות.",
|
|
19
19
|
"history.restore": "שחזור גרסה",
|
|
20
20
|
"history.restored": "ההודעה שוחזרה לגרסה שנבחרה",
|
|
21
|
-
"history.restoreDescription": "שחזור יציב את תוכן הגרסה שנבחרה כגרסה הנוכחית; הגרסה שהוחלפה תישמר בהיסטוריה."
|
|
21
|
+
"history.restoreDescription": "שחזור יציב את תוכן הגרסה שנבחרה כגרסה הנוכחית; הגרסה שהוחלפה תישמר בהיסטוריה.",
|
|
22
|
+
"errors.delete": "לא ניתן למחוק את חדר הצ'אט."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -18,5 +18,6 @@
|
|
|
18
18
|
"errors.history": "Unable to load or update the edit history.",
|
|
19
19
|
"history.restore": "Restore version",
|
|
20
20
|
"history.restored": "Message restored to the selected version",
|
|
21
|
-
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history."
|
|
21
|
+
"history.restoreDescription": "Restoring sets the selected version as the current one; the replaced version is kept in the history.",
|
|
22
|
+
"errors.delete": "Unable to delete the chat room."
|
|
22
23
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// The Delete Room menu item on the admin-all-chats page is rendered
|
|
4
|
+
// server-side (templates/partials/chats/options.tpl, gated on the manage
|
|
5
|
+
// privilege via room.isAdmin). It deliberately does NOT use core's
|
|
6
|
+
// data-action="delete": core's handler calls the admin-only
|
|
7
|
+
// DELETE /api/v3/admin/chats/:roomId endpoint, which rejects non-admin
|
|
8
|
+
// holders of the admin-chats:manage privilege — so the click goes through
|
|
9
|
+
// the plugin's own endpoint, which accepts them too.
|
|
10
|
+
$(document).ready(function () {
|
|
11
|
+
async function deleteRoom(roomId) {
|
|
12
|
+
const response = await fetch(`${config.relative_path || ''}/api/admin-chats/${roomId}`, {
|
|
13
|
+
method: 'DELETE',
|
|
14
|
+
headers: {
|
|
15
|
+
'x-csrf-token': config.csrf_token,
|
|
16
|
+
},
|
|
17
|
+
credentials: 'same-origin',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
if (!response.ok) {
|
|
21
|
+
throw new Error('Unable to delete room');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return await response.json();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
$(document).on('click', '.admin-chat-delete-room-item', function (ev) {
|
|
28
|
+
ev.preventDefault();
|
|
29
|
+
|
|
30
|
+
const $button = $(this);
|
|
31
|
+
const roomId = parseInt($button.attr('data-room-id'), 10);
|
|
32
|
+
|
|
33
|
+
if (!roomId || $button.hasClass('disabled')) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
require(['modals', 'forum/chats'], function (modals, Chats) {
|
|
38
|
+
// Same confirm dialog core shows for its own Delete Room item
|
|
39
|
+
modals.confirm({
|
|
40
|
+
size: 'small',
|
|
41
|
+
title: '[[modules:chat.delete]]',
|
|
42
|
+
message: '<p>[[modules:chat.delete-prompt]]</p>',
|
|
43
|
+
callback: async function (ok) {
|
|
44
|
+
if (!ok) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
$button.addClass('disabled').attr('aria-disabled', 'true');
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
await deleteRoom(roomId);
|
|
52
|
+
// Drop the room from the sidebar lists and close the
|
|
53
|
+
// open chat window (the patched switchChat renders the
|
|
54
|
+
// empty state for a falsy roomId)
|
|
55
|
+
$(`[component="chat/nav-wrapper"] [data-roomid="${roomId}"]`).remove();
|
|
56
|
+
if (Chats && Chats.switchChat) {
|
|
57
|
+
Chats.switchChat('');
|
|
58
|
+
}
|
|
59
|
+
} catch (err) {
|
|
60
|
+
app.alertError('[[admin-chats:errors.delete]]');
|
|
61
|
+
$button.removeClass('disabled').removeAttr('aria-disabled');
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -25,18 +25,4 @@ $(document).ready(function () {
|
|
|
25
25
|
refreshIfOpen(data && data.roomId);
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
// Core toggles the `deleted` class on a message when it's deleted/restored,
|
|
30
|
-
// but doesn't itself swap which of the delete/restore actions is visible.
|
|
31
|
-
$(document).on('click', '[data-action="delete"], [data-action="restore"]', function () {
|
|
32
|
-
const $message = $(this).closest('[component="chat/message"]');
|
|
33
|
-
if (!$message.length) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
setTimeout(function () {
|
|
37
|
-
const isDeleted = $message.hasClass('deleted');
|
|
38
|
-
$message.find('[data-action="delete"]').toggleClass('hidden', isDeleted).toggle(!isDeleted);
|
|
39
|
-
$message.find('[data-action="restore"]').toggleClass('hidden', !isDeleted).toggle(isDeleted);
|
|
40
|
-
}, 50);
|
|
41
|
-
});
|
|
42
28
|
});
|
|
@@ -81,13 +81,20 @@
|
|
|
81
81
|
</a>
|
|
82
82
|
</li>
|
|
83
83
|
{{{ end }}}
|
|
84
|
-
{{{ if (public && isAdmin) }}}
|
|
84
|
+
{{{ if ((public && isAdmin) && !adminAllChats) }}}
|
|
85
85
|
<li>
|
|
86
86
|
<a class="dropdown-item rounded-1 d-flex align-items-center gap-2" href="#" data-action="delete" role="menuitem">
|
|
87
87
|
<i class="fa fa-fw text-danger fa-trash"></i> {{tx("modules:chat.delete-room")}}
|
|
88
88
|
</a>
|
|
89
89
|
</li>
|
|
90
90
|
{{{ end }}}
|
|
91
|
+
{{{ if (adminAllChats && isAdmin) }}}
|
|
92
|
+
<li>
|
|
93
|
+
<a class="dropdown-item rounded-1 d-flex align-items-center gap-2 admin-chat-delete-room-item" href="#" data-room-id="{roomId}" role="menuitem">
|
|
94
|
+
<i class="fa fa-fw text-danger fa-trash"></i> {{tx("modules:chat.delete-room")}}
|
|
95
|
+
</a>
|
|
96
|
+
</li>
|
|
97
|
+
{{{ end }}}
|
|
91
98
|
</ul>
|
|
92
99
|
</div>
|
|
93
100
|
|