Skip to content

Commit

Permalink
feat: add management permission for workspace create user (opensearch…
Browse files Browse the repository at this point in the history
…-project#92)

Signed-off-by: Lin Wang <wonglam@amazon.com>
  • Loading branch information
wanglam authored and ruanyl committed Sep 15, 2023
1 parent 89094a4 commit 99a3922
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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],
});
}

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

0 comments on commit 99a3922

Please sign in to comment.