Page MenuHomePhabricator

D8200.id27722.diff
No OneTemporary

D8200.id27722.diff

diff --git a/keyserver/src/updaters/thread-updaters.js b/keyserver/src/updaters/thread-updaters.js
--- a/keyserver/src/updaters/thread-updaters.js
+++ b/keyserver/src/updaters/thread-updaters.js
@@ -76,13 +76,14 @@
throw new ServerError('not_logged_in');
}
- const [memberIDs, hasPermission] = await Promise.all([
+ const [memberIDs, hasPermission, fetchThreadResult] = await Promise.all([
verifyUserIDs(request.memberIDs),
checkThreadPermission(
viewer,
request.threadID,
threadPermissions.CHANGE_ROLE,
),
+ fetchThreadInfos(viewer, SQL`t.id = ${request.threadID}`),
]);
if (memberIDs.length === 0) {
throw new ServerError('invalid_parameters');
@@ -91,6 +92,22 @@
throw new ServerError('invalid_credentials');
}
+ const threadInfo = fetchThreadResult.threadInfos[request.threadID];
+
+ const memberRole = threadInfo.members.find(
+ member => member.id === request.memberIDs[0],
+ )?.role;
+
+ const memberRoleCount = threadInfo.members.filter(
+ member => member.role === memberRole,
+ ).length;
+ const memberRoleName = memberRole && threadInfo.roles[memberRole].name;
+
+ // Prevent the last community admin from having their role changed
+ if (memberRoleName === 'Admins' && memberRoleCount === 1) {
+ throw new ServerError('invalid_parameters');
+ }
+
const query = SQL`
SELECT user, role
FROM memberships

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 27, 9:07 AM (20 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2589981
Default Alt Text
D8200.id27722.diff (1 KB)

Event Timeline