Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow community editors to invite users #1001

Merged
merged 2 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion core/lib/server/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,45 @@ export const createUserWithMembership = async (data: {
};
}

if (!user?.isSuperAdmin && isSuperAdmin) {
if (!user.isSuperAdmin && isSuperAdmin) {
return {
title: "Failed to add member",
error: "You cannot add members as super admins",
};
}

// If they're adding a community member, make sure their role is equivalent or higher than
// the new member's. If they're adding a different type of membership, the community
// membership is always a contributor, so we can skip this check.
if (membership.type === MembershipType.community) {
const rolesRanking = {
[MemberRole.admin]: 2,
[MemberRole.editor]: 1,
[MemberRole.contributor]: 0,
};
const highestRole = user.memberships.reduce(
(highestRole, m) => {
if (m.communityId === community.id) {
if (!highestRole || rolesRanking[m.role] > rolesRanking[highestRole]) {
return m.role;
}
}
return highestRole;
},
undefined as MemberRole | undefined
);

const roleIsHighEnough =
highestRole && rolesRanking[highestRole] >= rolesRanking[membership.role];

if (!roleIsHighEnough) {
return {
title: "Failed to add member",
error: "You cannot add members with a higher role than your own",
};
}
}

let nameQuery: (trx: Transaction<Database>) => Promise<string>;
let membershipQuery: (trx: Transaction<Database>, userId: UsersId) => Promise<unknown>;
let target: CapabilityTarget;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
INSERT INTO
"membership_capabilities"
VALUES
(
'editor'::"MemberRole",
'community'::"MembershipType",
'addCommunityMember'::"Capabilities"
);
Loading