Skip to content

Commit

Permalink
fix: Drop all references to exec unless the feature is enabled (#9920) (
Browse files Browse the repository at this point in the history
#10187)

* fix:  Drop all references to exec unless the feature is enabled #9920

Signed-off-by: Patrick Kerwood <patrick@kerwood.dk>

* fixed tslint issues

Signed-off-by: Patrick Kerwood <patrick@kerwood.dk>
  • Loading branch information
Kerwood authored and crenshaw-dev committed Aug 8, 2022
1 parent 77c972d commit 05c9ba2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
extensionTabs: ResourceTabExtension[],
tabs: Tab[],
execEnabled: boolean,
execAllowed: boolean,
logsAllowed: boolean
) => {
if (!node || node === undefined) {
Expand Down Expand Up @@ -113,7 +114,7 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
}
]);
}
if (execEnabled) {
if (execEnabled && execAllowed) {
tabs = tabs.concat([
{
key: 'exec',
Expand Down Expand Up @@ -270,7 +271,8 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
const settings = await services.authService.settings();
const execEnabled = settings.execEnabled;
const logsAllowed = await services.accounts.canI('logs', 'get', application.spec.project + '/' + application.metadata.name);
return {controlledState, liveState, events, podState, execEnabled, logsAllowed};
const execAllowed = await services.accounts.canI('exec', 'create', application.spec.project + '/' + application.metadata.name);
return {controlledState, liveState, events, podState, execEnabled, execAllowed, logsAllowed};
}}>
{data => (
<React.Fragment>
Expand Down Expand Up @@ -315,6 +317,7 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
}
],
data.execEnabled,
data.execAllowed,
data.logsAllowed
)}
selectedTabKey={props.tab}
Expand Down
28 changes: 20 additions & 8 deletions ui/src/app/applications/components/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -355,16 +355,28 @@ function getActionItems(
action: () => appContext.apis.navigation.goto('.', {node: nodeKey(resource), tab: 'logs'}, {replace: true})
});
}
if (resource.kind === 'Pod') {
items.push({
title: 'Exec',
iconClassName: 'fa fa-terminal',
action: () => appContext.apis.navigation.goto('.', {node: nodeKey(resource), tab: 'exec'}, {replace: true})
});
}

if (isQuickStart) {
return from([items]);
}

const execAction = services.authService
.settings()
.then(async settings => {
const execAllowed = await services.accounts.canI('exec', 'create', application.spec.project + '/' + application.metadata.name);
if (resource.kind === 'Pod' && settings.execEnabled && execAllowed) {
return items.concat([
{
title: 'Exec',
iconClassName: 'fa fa-terminal',
action: async () => appContext.apis.navigation.goto('.', {node: nodeKey(resource), tab: 'exec'}, {replace: true})
}
]);
}
return items;
})
.catch(() => items);

const resourceActions = services.applications
.getResourceActions(application.metadata.name, resource)
.then(actions => {
Expand All @@ -389,7 +401,7 @@ function getActionItems(
);
})
.catch(() => items);
menuItems = merge(from([items]), from(resourceActions));
menuItems = merge(from([items]), from(resourceActions), from(execAction));
return menuItems;
}

Expand Down

0 comments on commit 05c9ba2

Please sign in to comment.