Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Added ability to change a role in an organization

Vladyslav Matsiiako25bb966a32e1
diff --git a/backend/src/routes/v2/organizations.ts b/backend/src/routes/v2/organizations.ts
index 1362a7759a..e1488e8a71 100644
--- a/backend/src/routes/v2/organizations.ts
+++ b/backend/src/routes/v2/organizations.ts
@@ -30,7 +30,7 @@ router.patch(
'/:organizationId/memberships/:membershipId',
param('organizationId').exists().trim(),
param('membershipId').exists().trim(),
- body('role').exists().isString().trim().isIn([ADMIN, MEMBER]),
+ body('role').exists().isString().trim().isIn([OWNER, ADMIN, MEMBER]),
validateRequest,
requireAuth({
acceptedAuthModes: ['jwt', 'apiKey']
diff --git a/frontend/src/components/basic/table/UserTable.tsx b/frontend/src/components/basic/table/UserTable.tsx
index e82556b50d..02e65c547a 100644
--- a/frontend/src/components/basic/table/UserTable.tsx
+++ b/frontend/src/components/basic/table/UserTable.tsx
@@ -2,8 +2,8 @@ import { useEffect, useState } from 'react';
import { useRouter } from 'next/router';
import { faX } from '@fortawesome/free-solid-svg-icons';
+import changeUserRoleInOrganization from '@app/pages/api/organization/changeUserRoleInOrganization';
import deleteUserFromOrganization from '@app/pages/api/organization/deleteUserFromOrganization';
-import changeUserRoleInWorkspace from '@app/pages/api/workspace/changeUserRoleInWorkspace';
import deleteUserFromWorkspace from '@app/pages/api/workspace/deleteUserFromWorkspace';
import getLatestFileKey from '@app/pages/api/workspace/getLatestFileKey';
import uploadKeys from '@app/pages/api/workspace/uploadKeys';
@@ -55,9 +55,9 @@ const UserTable = ({ userData, changeData, myUser, filter, resendInvite, isOrg }
]);
};
- // Update the rold of a certain user
+ // Update the role of a certain user
const handleRoleUpdate = (index: number, e: string) => {
- changeUserRoleInWorkspace(userData[index].membershipId, e);
+ changeUserRoleInOrganization(String(localStorage.getItem("orgData.id")), userData[index].membershipId, e);
changeData([
...userData.slice(0, index),
...[
@@ -145,9 +145,9 @@ const UserTable = ({ userData, changeData, myUser, filter, resendInvite, isOrg }
</td>
<td className="pl-6 pr-10 py-2 border-mineshaft-700 border-t text-gray-300">
<div className="justify-start h-full flex flex-row items-center">
- {row.status === 'granted' &&
+ {row.status === 'accepted' &&
((myRole === 'admin' && row.role !== 'owner') || myRole === 'owner') &&
- myUser !== row.email ? (
+ (myUser !== row.email) ? (
<Listbox
isSelected={row.role}
onChange={(e) => handleRoleUpdate(index, e)}
diff --git a/frontend/src/pages/api/organization/changeUserRoleInOrganization.ts b/frontend/src/pages/api/organization/changeUserRoleInOrganization.ts
new file mode 100644
index 0000000000..6bbe966c40
--- /dev/null
+++ b/frontend/src/pages/api/organization/changeUserRoleInOrganization.ts
@@ -0,0 +1,27 @@
+import SecurityClient from '@app/components/utilities/SecurityClient';
+
+/**
+ * This function change the access of a user in a certain organization
+ * @param {string} organizationId
+ * @param {string} membershipId
+ * @param {string} role
+ * @returns
+ */
+const changeUserRoleInOrganization = (organizationId: string, membershipId: string, role: string) =>
+ SecurityClient.fetchCall(`/api/v2/organizations/${organizationId}/memberships/${membershipId}`, {
+ method: 'PATCH',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify({
+ role
+ })
+ }).then(async (res) => {
+ if (res && res.status === 200) {
+ return res;
+ }
+ console.log('Failed to change the user role in an org');
+ return undefined;
+ });
+
+export default changeUserRoleInOrganization;