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

Repository form #313

Merged
merged 12 commits into from
Apr 16, 2021
7 changes: 7 additions & 0 deletions src/api/container-distribution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { PulpAPI } from './pulp';

export class API extends PulpAPI {
apiPath = 'distributions/container/container/';
}

export const ContainerDistributionAPI = new API();
7 changes: 7 additions & 0 deletions src/api/execution-environment-namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { HubAPI } from './hub';

class API extends HubAPI {
apiPath = this.getUIPath('execution-environments/namespaces/');
}

export const ExecutionEnvironmentNamespaceAPI = new API();
2 changes: 2 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ export { ActivitiesAPI } from './activities';
export { ContainerTagAPI } from './container-tag';
export { FeatureFlagsType } from './response-types/feature-flags';
export { FeatureFlagsAPI } from './feature-flags';
export { ContainerDistributionAPI } from './container-distribution';
export { ExecutionEnvironmentNamespaceAPI } from './execution-environment-namespace';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Tooltip } from '@patternfly/react-core';
import { Tooltip, Button } from '@patternfly/react-core';
import { Paths } from 'src/paths';
import { BaseHeader, Breadcrumbs, Tabs } from 'src/components';
import { ContainerRepositoryType } from 'src/api';
Expand All @@ -9,6 +9,7 @@ interface IProps {
tab: string;
updateState: (any) => void;
container: ContainerRepositoryType;
pageControls?: React.ReactElement;
}

export class ExecutionEnvironmentHeader extends React.Component<IProps> {
Expand All @@ -28,6 +29,7 @@ export class ExecutionEnvironmentHeader extends React.Component<IProps> {
]}
/>
}
pageControls={this.props.pageControls}
>
<Tooltip content={this.props.container.description}>
<p className={'truncated'}>{this.props.container.description}</p>
Expand Down
96 changes: 96 additions & 0 deletions src/components/execution-environment/repository-form.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import * as React from 'react';
import {
Button,
Form,
FormGroup,
Modal,
TextInput,
} from '@patternfly/react-core';
import { ObjectPermissionField } from 'src/components';
import { GroupObjectPermissionType } from 'src/api';
import { Constants } from 'src/constants';

interface IProps {
name: string;
description: string;
selectedGroups: GroupObjectPermissionType[];
onSave: (string, []) => void;
onCancel: () => void;
permissions: string[];
}

interface IState {
description: string;
selectedGroups: GroupObjectPermissionType[];
}

export class RepositoryForm extends React.Component<IProps, IState> {
constructor(props) {
super(props);
this.state = {
description: this.props.description,
selectedGroups: this.props.selectedGroups,
};
}

render() {
const { name, onSave, onCancel } = this.props;
const { description, selectedGroups } = this.state;
return (
<Modal
variant='large'
onClose={onCancel}
isOpen={true}
title={'Edit repository'}
actions={[
<Button
key='save'
variant='primary'
onClick={() => onSave(description, selectedGroups)}
>
Save
</Button>,
<Button key='cancel' variant='link' onClick={onCancel}>
Cancel
</Button>,
]}
>
<Form>
<FormGroup key='name' fieldId='name' label='Name'>
<TextInput id='name' value={name} isDisabled={true} type='text' />
</FormGroup>
<FormGroup
key='description'
fieldId='description'
label='Description'
>
<TextInput
id='description'
value={description}
isDisabled={
!this.props.permissions.includes(
'container.namespace_change_containerdistribution',
)
}
onChange={value => this.setState({ description: value })}
type='text'
/>
</FormGroup>
<FormGroup key='groups' fieldId='groups' label='Groups with access'>
<ObjectPermissionField
groups={this.state.selectedGroups}
availablePermissions={Constants.CONTAINER_NAMESPACE_PERMISSIONS}
setGroups={g => this.setState({ selectedGroups: g })}
menuAppendTo='parent'
isDisabled={
!this.props.permissions.includes(
'container.change_containernamespace',
)
}
></ObjectPermissionField>
</FormGroup>
</Form>
</Modal>
);
}
}
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ export { MarkdownEditor } from './markdown-editor/markdown-editor';
export { ShaLabel } from './sha-label/sha-label';
export { TagLabel } from './tag-label/tag-label';
export { ExecutionEnvironmentHeader } from './execution-environment-header/execution-environment-header';
export { RepositoryForm } from './execution-environment/repository-form';
5 changes: 3 additions & 2 deletions src/components/permissions/obect-permission-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface IProps {
groups: GroupObjectPermissionType[];
availablePermissions: string[];
setGroups: (groups: GroupObjectPermissionType[]) => void;

isDisabled?: boolean;
menuAppendTo?: 'parent' | 'inline';
}

Expand Down Expand Up @@ -44,6 +44,7 @@ export class ObjectPermissionField extends React.Component<IProps, IState> {
onSelect={this.onSelect}
placeholderText='Find a group'
menuAppendTo={this.props.menuAppendTo}
isDisabled={!!this.props.isDisabled}
/>
<br />
<br />
Expand All @@ -55,7 +56,7 @@ export class ObjectPermissionField extends React.Component<IProps, IState> {
key={group.name}
>
<FlexItem style={{ minWidth: '200px' }}>{group.name}</FlexItem>
<FlexItem grow={{ default: 'grow' }}>
<FlexItem grow={{ default: 'grow' }} style={{ width: '90%' }}>
<PermissionChipSelector
availablePermissions={availablePermissions.map(perm =>
twoWayMapper(perm, Constants.GROUP_HUMAN_PERMISSIONS),
Expand Down
40 changes: 31 additions & 9 deletions src/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,46 @@ export class Constants {
'galaxy.change_synclist': 'Change synclist',
'galaxy.view_synclist': 'View synclist',
'galaxy.add_synclist': 'Add synclist',
'container.add_containernamespace': 'Create new execution environments',
'container.namespace_pull_containerdistribution':
'Pull private execution environments',
'container.namespace_change_containerdistribution':
'Change execution environments',
'container.namespace_view_containerdistribution':
'View private execution environments',
'container.add_containernamespace': 'Create new containers',
'container.namespace_pull_containerdistribution': 'Pull private containers',
'container.namespace_change_containerdistribution': 'Change containers',
'container.namespace_view_containerdistribution': 'View private containers',
'container.namespace_modify_content_containerpushrepository':
'Change image tags',
'container.change_containernamespace':
'Change execution environment namespace permissions',
'Change container namespace permissions',
'container.namespace_push_containerdistribution':
'Push to existing execution environments',
'Push to existing containers',
};
static GROUP_HUMAN_PERMISSIONS = {
change_namespace: 'Change namespace',
upload_to_namespace: 'Upload to namespace',
add_containernamespace: 'Create new containers',
namespace_pull_containerdistribution: 'Pull private containers',
namespace_change_containerdistribution: 'Change containers',
namespace_view_containerdistribution: 'View private containers',
namespace_modify_content_containerpushrepository: 'Change image tags',
change_containernamespace: 'Change container namespace permissions',
namespace_push_containerdistribution: 'Push to existing containers',
view_containernamespace: "View container's namespace",
delete_containernamespace: "Delete container's namespace",
namespace_delete_containerdistribution: "Delete container's distribution",
namespace_view_containerpushrepository: "View container's repository",
namespace_add_containerdistribution: 'Add distribution',
change_containerdistribution: 'Change distribution',
delete_containerdistribution: 'Delete distribution',
push_containerdistribution: 'Push distribution',
pull_containerdistribution: 'Pull distribution',
view_containerdistribution: 'View distribution',
};
static CONTAINER_NAMESPACE_PERMISSIONS = [
'namespace_delete_containerdistribution',
'namespace_view_containerpushrepository',
'change_containernamespace',
'namespace_push_containerdistribution',
'namespace_change_containerdistribution',
'namespace_modify_content_containerpushrepository',
];
static UPSTREAM_HOSTS = [
'galaxy.ansible.com',
'galaxy-dev.ansible.com',
Expand Down
Loading