Skip to content

Commit 0670bb2

Browse files
Remove member default role from API key creation (#14932)
1 parent 337f1a9 commit 0670bb2

File tree

2 files changed

+6
-30
lines changed

2 files changed

+6
-30
lines changed

packages/twenty-front/src/modules/settings/developers/components/SettingsDevelopersRoleSelector.tsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
21
import { type RoleWithPartialMembers } from '@/settings/roles/types/RoleWithPartialMembers';
32
import { Select } from '@/ui/input/components/Select';
4-
import { useRecoilValue } from 'recoil';
53
import { type IconComponent, useIcons } from 'twenty-ui/display';
64

75
type SettingsDevelopersRoleSelectorProps = {
@@ -21,21 +19,6 @@ export const SettingsDevelopersRoleSelector = ({
2119
}: SettingsDevelopersRoleSelectorProps) => {
2220
const { getIcon } = useIcons();
2321

24-
const currentWorkspace = useRecoilValue(currentWorkspaceState);
25-
26-
let doesDefaultRoleExistInRoles = false;
27-
28-
const defaultRole = currentWorkspace?.defaultRole;
29-
try {
30-
doesDefaultRoleExistInRoles = roles.some(
31-
(role) => role.id === defaultRole?.id,
32-
);
33-
} catch {
34-
throw new Error(
35-
'Default role does not exist in roles, this should not happen',
36-
);
37-
}
38-
3922
if (roles.length === 0) {
4023
return null;
4124
}
@@ -55,8 +38,7 @@ export const SettingsDevelopersRoleSelector = ({
5538
}
5639
}, []);
5740

58-
const selectValue =
59-
value || (doesDefaultRoleExistInRoles ? defaultRole?.id : roles[0].id);
41+
const selectValue = value || options[0]?.value;
6042

6143
return (
6244
<Select

packages/twenty-front/src/pages/settings/developers/api-keys/SettingsDevelopersApiKeysNew.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { addDays } from 'date-fns';
22
import { useState } from 'react';
33

4-
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
54
import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons';
65
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
76
import { SettingsSkeletonLoader } from '@/settings/components/SettingsSkeletonLoader';
@@ -12,7 +11,7 @@ import { Select } from '@/ui/input/components/Select';
1211
import { SettingsTextInput } from '@/ui/input/components/SettingsTextInput';
1312
import { SubMenuTopBarContainer } from '@/ui/layout/page/components/SubMenuTopBarContainer';
1413
import { useLingui } from '@lingui/react/macro';
15-
import { useRecoilCallback, useRecoilValue } from 'recoil';
14+
import { useRecoilCallback } from 'recoil';
1615
import { Key } from 'ts-key-enum';
1716
import { SettingsPath } from 'twenty-shared/types';
1817
import { getSettingsPath, isDefined } from 'twenty-shared/utils';
@@ -29,21 +28,16 @@ export const SettingsDevelopersApiKeysNew = () => {
2928
const { t } = useLingui();
3029
const [generateOneApiKeyToken] = useGenerateApiKeyTokenMutation();
3130
const navigateSettings = useNavigateSettings();
32-
const currentWorkspace = useRecoilValue(currentWorkspaceState);
3331
const { data: rolesData, loading: rolesLoading } = useGetRolesQuery({
3432
onCompleted: (data) => {
3533
if (isDefined(data?.getRoles)) {
36-
const defaultRole = data.getRoles.find(
37-
(role) => role.id === currentWorkspace?.defaultRole?.id,
34+
const apiKeyAssignableRoles = data.getRoles.filter(
35+
(role) => role.canBeAssignedToApiKeys,
3836
);
39-
if (
40-
isDefined(defaultRole) &&
41-
defaultRole.canBeAssignedToApiKeys &&
42-
!formValues.roleId
43-
) {
37+
if (!formValues.roleId && apiKeyAssignableRoles.length > 0) {
4438
setFormValues((prev) => ({
4539
...prev,
46-
roleId: defaultRole.id,
40+
roleId: apiKeyAssignableRoles[0].id,
4741
}));
4842
}
4943
}

0 commit comments

Comments
 (0)