mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
fix(console): filter out empty org permissions and roles on guide submit (#4897)
This commit is contained in:
parent
8a50d27757
commit
8547cce5ff
1 changed files with 18 additions and 13 deletions
|
@ -34,6 +34,7 @@ import { steps } from '../const';
|
|||
import * as styles from '../index.module.scss';
|
||||
|
||||
type Form = {
|
||||
/* Organization permissions, a.k.a organization scopes */
|
||||
permissions: Array<Omit<OrganizationScope, 'id' | 'tenantId'>>;
|
||||
roles: Array<Omit<OrganizationRole, 'tenantId' | 'id'> & { scopes: Array<Option<string>> }>;
|
||||
};
|
||||
|
@ -115,9 +116,11 @@ function PermissionsAndRoles() {
|
|||
// Create new permissions
|
||||
if (permissions.length > 0) {
|
||||
await Promise.all(
|
||||
permissions.map(async ({ name, description }) => {
|
||||
await api.post(organizationScopesPath, { json: { name, description } });
|
||||
})
|
||||
permissions
|
||||
.filter(({ name }) => name)
|
||||
.map(async ({ name, description }) => {
|
||||
await api.post(organizationScopesPath, { json: { name, description } });
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -130,17 +133,19 @@ function PermissionsAndRoles() {
|
|||
// Create new roles
|
||||
if (roles.length > 0) {
|
||||
await Promise.all(
|
||||
roles.map(async ({ name, description, scopes }) => {
|
||||
const { id } = await api
|
||||
.post(organizationRolePath, { json: { name, description } })
|
||||
.json<OrganizationRole>();
|
||||
roles
|
||||
.filter(({ name }) => name)
|
||||
.map(async ({ name, description, scopes }) => {
|
||||
const { id } = await api
|
||||
.post(organizationRolePath, { json: { name, description } })
|
||||
.json<OrganizationRole>();
|
||||
|
||||
if (scopes.length > 0) {
|
||||
await api.put(`${organizationRolePath}/${id}/scopes`, {
|
||||
json: { organizationScopeIds: scopes.map(({ value }) => value) },
|
||||
});
|
||||
}
|
||||
})
|
||||
if (scopes.length > 0) {
|
||||
await api.put(`${organizationRolePath}/${id}/scopes`, {
|
||||
json: { organizationScopeIds: scopes.map(({ value }) => value) },
|
||||
});
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue