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 @@ -9,7 +9,10 @@ configurableCommunityPermissions, 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, @@ -97,6 +100,15 @@ const { community, name, permissions } = request; + const { threadInfos } = await fetchThreadInfos(viewer, { + threadID: community, + }); + const threadInfo = threadInfos[community]; + + if (!threadTypeIsCommunityRoot(threadInfo.type)) { + throw new ServerError('invalid_parameters'); + } + for (const permission of permissions) { if (!userSurfacedPermissionsSet.has(permission)) { throw new ServerError('invalid_parameters'); @@ -110,11 +122,6 @@ .map(permission => [...configurableCommunityPermissions[permission]]) .flat(); - const { threadInfos } = await fetchThreadInfos(viewer, { - threadID: community, - }); - const threadInfo = threadInfos[community]; - const universalCommunityPermissions = getUniversalCommunityRootPermissionsBlob(threadInfo.type);