Skip to content
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: add management permission for workspace create user #92

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/server/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export {
RouteValidationResultFactory,
DestructiveRouteMethod,
SafeRouteMethod,
ensureRawRequest,
} from './router';
export { BasePathProxyServer } from './base_path_proxy_server';
export { OnPreRoutingHandler, OnPreRoutingToolkit } from './lifecycle/on_pre_routing';
Expand Down
1 change: 1 addition & 0 deletions src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ export {
SessionStorageFactory,
DestructiveRouteMethod,
SafeRouteMethod,
ensureRawRequest,
} from './http';

export {
Expand Down
16 changes: 15 additions & 1 deletion src/plugins/workspace/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { schema } from '@osd/config-schema';
import { ensureRawRequest } from '../../../../core/server';

import {
ACL,
Expand Down Expand Up @@ -172,6 +173,19 @@ export function registerRoutes({
},
router.handleLegacyErrors(async (context, req, res) => {
const { attributes } = req.body;
const rawRequest = ensureRawRequest(req);
const authInfo = rawRequest?.auth?.credentials?.authInfo as { user_name?: string } | null;
const permissions = Array.isArray(attributes.permissions)
? attributes.permissions
: [attributes.permissions];

if (!!authInfo?.user_name) {
permissions.push({
type: 'user',
userId: authInfo.user_name,
modes: [WorkspacePermissionMode.Management],
});
Hailong-am marked this conversation as resolved.
Show resolved Hide resolved
}

const result = await client.create(
{
Expand All @@ -181,7 +195,7 @@ export function registerRoutes({
},
{
...attributes,
permissions: convertToACL(attributes.permissions),
permissions: convertToACL(permissions),
}
);
return res.ok({ body: result });
Expand Down
Loading