0
Fork 0
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:
Charles Zhao 2023-11-16 16:10:29 +08:00 committed by GitHub
parent 8a50d27757
commit 8547cce5ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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) },
});
}
})
);
}