Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3514347
D9900.id33495.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D9900.id33495.diff
View Options
diff --git a/keyserver/src/creators/role-creator.js b/keyserver/src/creators/role-creator.js
--- a/keyserver/src/creators/role-creator.js
+++ b/keyserver/src/creators/role-creator.js
@@ -4,11 +4,15 @@
getRolePermissionBlobs,
getThreadPermissionBlobFromUserSurfacedPermissions,
} from 'lib/permissions/thread-permissions.js';
+import { threadHasPermission } from 'lib/shared/thread-utils.js';
import {
userSurfacedPermissionsSet,
threadPermissions,
} from 'lib/types/thread-permission-types.js';
-import type { ThreadType } from 'lib/types/thread-types-enum.js';
+import {
+ threadTypeIsCommunityRoot,
+ type ThreadType,
+} from 'lib/types/thread-types-enum.js';
import type {
RoleInfo,
RoleModificationRequest,
@@ -25,7 +29,6 @@
fetchServerThreadInfos,
rawThreadInfosFromServerThreadInfos,
} from '../fetchers/thread-fetchers.js';
-import { checkThreadPermission } from '../fetchers/thread-permission-fetchers.js';
import type { Viewer } from '../session/viewer.js';
import { updateRole } from '../updaters/thread-updaters.js';
@@ -85,16 +88,25 @@
viewer: Viewer,
request: RoleModificationRequest,
): Promise<RoleModificationResult> {
- const hasPermission = await checkThreadPermission(
- viewer,
- request.community,
+ const { community, name, permissions } = request;
+
+ const { threadInfos } = await fetchThreadInfos(viewer, {
+ threadID: community,
+ });
+ const threadInfo = threadInfos[community];
+
+ const hasPermission = threadHasPermission(
+ threadInfo,
threadPermissions.CHANGE_ROLE,
);
+
if (!hasPermission) {
throw new ServerError('invalid_credentials');
}
- const { community, name, permissions } = request;
+ if (!threadTypeIsCommunityRoot(threadInfo.type)) {
+ throw new ServerError('invalid_parameters');
+ }
for (const permission of permissions) {
if (!userSurfacedPermissionsSet.has(permission)) {
@@ -105,11 +117,6 @@
const [id] = await createIDs('roles', 1);
const time = Date.now();
- const { threadInfos } = await fetchThreadInfos(viewer, {
- threadID: community,
- });
- const threadInfo = threadInfos[community];
-
const permissionsBlob = JSON.stringify(
getThreadPermissionBlobFromUserSurfacedPermissions(
permissions,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 4:23 AM (12 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2692798
Default Alt Text
D9900.id33495.diff (2 KB)
Attached To
Mode
D9900: [keyserver] Validate community ID corresponds to a community root in role-creator
Attached
Detach File
Event Timeline
Log In to Comment