Skip to content

Commit

Permalink
Merge pull request #40 from briehl/master
Browse files Browse the repository at this point in the history
Permissions changes
  • Loading branch information
briehl authored Jul 17, 2020
2 parents 9a57a32 + d804a5d commit ce01a76
Show file tree
Hide file tree
Showing 10 changed files with 496 additions and 432 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import DeleteItem from './DeleteItem';
import CopyItem from './CopyItem';
import LinkOrgItem from './LinkOrgItem';
import RenameItem from './RenameItem';
import SharingItem from './SharingItem';
import SharingItem from './sharing/SharingItem';

interface State {
showMenu: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,34 @@ import { LoadingSpinner } from '../../../generic/LoadingSpinner';
import DashboardButton from '../../../generic/DashboardButton';
import Runtime from '../../../../utils/runtime';
import { KBaseServiceClient } from '@kbase/narrative-utils';
import { getCurrentUserPermission } from '../../../../utils/narrativeData';

interface State {
doingDelete: boolean;
isLoading: boolean;
deleteError: any;
canDelete: boolean;
}

export default class DeleteItem extends Component<ControlMenuItemProps, State> {
state = {
doingDelete: false,
isLoading: true,
deleteError: null,
canDelete: false,
};

async componentDidMount() {
const perm = await getCurrentUserPermission(
this.props.narrative.access_group
);
this.setState({
isLoading: false,
canDelete: perm === 'a',
});
}

async doDelete() {
this.setState({
doingDelete: true,
isLoading: true,
});
const workspaceClient = new KBaseServiceClient({
module: 'Workspace',
Expand Down Expand Up @@ -49,9 +62,9 @@ export default class DeleteItem extends Component<ControlMenuItemProps, State> {
render() {
let loadingSpinner = null;
let deleteControls = null;
if (this.state.doingDelete) {
if (this.state.isLoading) {
loadingSpinner = LoadingSpinner({ loading: true });
} else {
} else if (this.state.canDelete) {
deleteControls = (
<React.Fragment>
<div className="pb2">
Expand All @@ -75,6 +88,8 @@ export default class DeleteItem extends Component<ControlMenuItemProps, State> {
</div>
</React.Fragment>
);
} else {
deleteControls = 'You do not have permission to delete this Narrative.';
}
let error = null;
if (this.state.deleteError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ export default class LinkOrgItem extends Component<
} else if (this.state.perm !== 'a') {
return (
<div style={{ textAlign: 'center' }}>
Only users with share access can request to add their narrative to a
group.
You don't have permission to request to add this Narrative to a group.
</div>
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import DashboardButton from '../../../generic/DashboardButton';
import Runtime from '../../../../utils/runtime';
import { DynamicServiceClient } from '../../../../api/serviceWizard';
import { LoadingSpinner } from '../../../generic/LoadingSpinner';
import { getCurrentUserPermission } from '../../../../utils/narrativeData';

interface State {
doingRename: boolean;
isLoading: boolean;
newName: string;
renameError: any;
canRename: boolean;
}

export default class RenameItem extends Component<ControlMenuItemProps, State> {
Expand All @@ -18,12 +20,23 @@ export default class RenameItem extends Component<ControlMenuItemProps, State> {
super(props);
this.currentName = this.props.narrative.narrative_title;
this.state = {
doingRename: false,
isLoading: true,
newName: this.currentName,
renameError: null,
canRename: false,
};
}

async componentDidMount() {
const userPerm = await getCurrentUserPermission(
this.props.narrative.access_group
);
this.setState({
isLoading: false,
canRename: userPerm === 'a',
});
}

validateName(event: React.ChangeEvent) {
const value = (event.target as HTMLInputElement).value;
this.setState({ newName: value || '' });
Expand All @@ -37,7 +50,7 @@ export default class RenameItem extends Component<ControlMenuItemProps, State> {
return;
}
}
this.setState({ doingRename: true });
this.setState({ isLoading: true });
const config = Runtime.getConfig();
const wsId = this.props.narrative.access_group;
const objId = this.props.narrative.obj_id;
Expand All @@ -48,20 +61,19 @@ export default class RenameItem extends Component<ControlMenuItemProps, State> {
version: 'beta',
});
try {
const updatedUpa = await narrativeService.call('rename_narrative', [
await narrativeService.call('rename_narrative', [
{
narrative_ref: `${wsId}/${objId}`,
new_name: this.state.newName,
},
]);
console.log(updatedUpa);
this.props.doneFn();
if (this.props.cancelFn) {
this.props.cancelFn();
}
} catch (error) {
this.setState({
doingRename: false,
isLoading: false,
renameError: error,
});
}
Expand All @@ -73,11 +85,11 @@ export default class RenameItem extends Component<ControlMenuItemProps, State> {

render() {
let loadingSpinner = null;
let copyControls = null;
if (this.state.doingRename) {
let renameControls = null;
if (this.state.isLoading) {
loadingSpinner = LoadingSpinner({ loading: true });
} else {
copyControls = (
} else if (this.state.canRename) {
renameControls = (
<React.Fragment>
<div className="pb2">Enter a new name for the Narrative.</div>
<div>
Expand All @@ -101,6 +113,8 @@ export default class RenameItem extends Component<ControlMenuItemProps, State> {
</div>
</React.Fragment>
);
} else {
renameControls = 'You do not have permission to rename this Narrative';
}
let error = null;
if (this.state.renameError) {
Expand All @@ -110,7 +124,7 @@ export default class RenameItem extends Component<ControlMenuItemProps, State> {
<div style={{ textAlign: 'center' }}>
{loadingSpinner}
{error}
{copyControls}
{renameControls}
</div>
);
}
Expand Down
Loading

0 comments on commit ce01a76

Please sign in to comment.