-
-
Notifications
You must be signed in to change notification settings - Fork 735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: read logs and update cors maintenance root-role permissions #8996
Changes from all commits
f8a62ef
4bb80d2
b68059c
5f9a377
866b46a
0c6fef2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { ADMIN } from 'component/providers/AccessProvider/permissions'; | ||
import { PermissionGuard } from 'component/common/PermissionGuard/PermissionGuard'; | ||
import { EventLog } from 'component/events/EventLog/EventLog'; | ||
import { READ_LOGS, ADMIN } from '@server/types/permissions'; | ||
|
||
export const EventPage = () => ( | ||
<PermissionGuard permissions={ADMIN}> | ||
<PermissionGuard permissions={[ADMIN, READ_LOGS]}> | ||
<EventLog title='Event log' /> | ||
</PermissionGuard> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { FromSchema } from 'json-schema-to-ts'; | ||
|
||
export const setCorsSchema = { | ||
$id: '#/components/schemas/setCorsSchema', | ||
type: 'object', | ||
additionalProperties: false, | ||
description: 'Unleash CORS configuration.', | ||
properties: { | ||
frontendApiOrigins: { | ||
description: | ||
'The list of origins that the front-end API should accept requests from.', | ||
example: ['*'], | ||
type: 'array', | ||
items: { type: 'string' }, | ||
}, | ||
}, | ||
components: {}, | ||
} as const; | ||
|
||
export type SetCorsSchema = FromSchema<typeof setCorsSchema>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ import { | |
type SimpleAuthSettings, | ||
simpleAuthSettingsKey, | ||
} from '../../types/settings/simple-auth-settings'; | ||
import { ADMIN, NONE } from '../../types/permissions'; | ||
import { ADMIN, NONE, UPDATE_CORS } from '../../types/permissions'; | ||
import { createResponseSchema } from '../../openapi/util/create-response-schema'; | ||
import { | ||
uiConfigSchema, | ||
|
@@ -22,6 +22,7 @@ import { emptyResponse } from '../../openapi/util/standard-responses'; | |
import type { IAuthRequest } from '../unleash-types'; | ||
import NotFoundError from '../../error/notfound-error'; | ||
import type { SetUiConfigSchema } from '../../openapi/spec/set-ui-config-schema'; | ||
import type { SetCorsSchema } from '../../openapi/spec/set-cors-schema'; | ||
import { createRequestSchema } from '../../openapi/util/create-request-schema'; | ||
import type { FrontendApiService, SessionService } from '../../services'; | ||
import type MaintenanceService from '../../features/maintenance/maintenance-service'; | ||
|
@@ -99,6 +100,7 @@ class ConfigController extends Controller { | |
], | ||
}); | ||
|
||
// TODO: deprecate when removing `granularAdminPermissions` flag | ||
this.route({ | ||
method: 'post', | ||
path: '', | ||
|
@@ -116,6 +118,24 @@ class ConfigController extends Controller { | |
}), | ||
], | ||
}); | ||
|
||
this.route({ | ||
method: 'post', | ||
path: '/cors', | ||
handler: this.setCors, | ||
permission: [ADMIN, UPDATE_CORS], | ||
middleware: [ | ||
openApiService.validPath({ | ||
tags: ['Admin UI'], | ||
summary: 'Sets allowed CORS origins', | ||
description: | ||
'Sets Cross-Origin Resource Sharing headers for Frontend SDK API.', | ||
operationId: 'setCors', | ||
requestBody: createRequestSchema('setCorsSchema'), | ||
responses: { 204: emptyResponse }, | ||
}), | ||
], | ||
}); | ||
} | ||
|
||
async getUiConfig( | ||
|
@@ -198,6 +218,30 @@ class ConfigController extends Controller { | |
|
||
throw new NotFoundError(); | ||
} | ||
|
||
async setCors( | ||
req: IAuthRequest<void, void, SetCorsSchema>, | ||
res: Response<string>, | ||
): Promise<void> { | ||
const granularAdminPermissions = this.flagResolver.isEnabled( | ||
'granularAdminPermissions', | ||
); | ||
|
||
if (!granularAdminPermissions) { | ||
throw new NotFoundError(); | ||
} | ||
|
||
if (req.body.frontendApiOrigins) { | ||
await this.frontendApiService.setFrontendCorsSettings( | ||
req.body.frontendApiOrigins, | ||
req.audit, | ||
); | ||
res.sendStatus(204); | ||
return; | ||
} | ||
|
||
throw new NotFoundError(); | ||
} | ||
} | ||
Comment on lines
+222
to
245
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previous "setUiConfig" is a generic name, but it only sets CORS. For easy transition into endpoint with proper permissions it's easier to create new one, and avoid potential errors or confusion about permissions in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively we could use a PATCh on the uiConfig, but we're not using PATCH that frequently... but arguably CORS is a configuration on itself, maybe it's fine not having it as part of uiConfig |
||
|
||
export default ConfigController; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a breaking change so we have to delay removing it. Meanwhile I believe you can flag the route as deprecated (for OpenAPI doc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's the process I'll follow.