Add roles to users you invite to your team (#404)

* Add method to check if user is admin or owner

* Add method to enable role based member invites

* Add Select Control element to UI to handle role based invite

* Add flag to allow add member feature for owner or admin level users only

* Fix error with role select element

* Add UI view to modify membership

* Add RoleElement component to handle the Role display

* Integrate api for Updating Accepted Member Role

* Integrate api for Updating Invitee's Role

* Resolve PR comments and merge conflicts
This commit is contained in:
Neil Chauhan
2023-06-20 15:51:25 +05:30
committed by GitHub
parent 4348c905f0
commit 27023eacf8
7 changed files with 289 additions and 18 deletions
+15
View File
@@ -126,3 +126,18 @@ export const getSessionUser = async (req?: NextApiRequest, res?: NextApiResponse
}
if (session && "user" in session) return session.user;
};
export const isAdminOrOwner = async (user, teamId) => {
const membership = await prisma.membership.findUnique({
where: {
userId_teamId: {
userId: user.id,
teamId: teamId,
},
},
});
if (membership && (membership.role === "admin" || membership.role === "owner")) {
return true;
}
return false;
};