mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
use reflow to migrate from flow to typescript
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
// @flow
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import { Checkbox } from "@scm-manager/ui-components";
|
||||
|
||||
type Props = {
|
||||
t: string => string,
|
||||
disabled: boolean,
|
||||
name: string,
|
||||
checked: boolean,
|
||||
onChange?: (value: boolean, name?: string) => void
|
||||
};
|
||||
|
||||
class PermissionCheckbox extends React.Component<Props> {
|
||||
render() {
|
||||
const { t } = this.props;
|
||||
return (
|
||||
<Checkbox
|
||||
key={this.props.name}
|
||||
name={this.props.name}
|
||||
helpText={t("verbs.repository." + this.props.name + ".description")}
|
||||
label={t("verbs.repository." + this.props.name + ".displayName")}
|
||||
checked={this.props.checked}
|
||||
onChange={this.props.onChange}
|
||||
disabled={this.props.disabled}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default translate("plugins")(PermissionCheckbox);
|
||||
@@ -0,0 +1,30 @@
|
||||
import React from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import { Checkbox } from '@scm-manager/ui-components';
|
||||
|
||||
type Props = {
|
||||
t: (p: string) => string;
|
||||
disabled: boolean;
|
||||
name: string;
|
||||
checked: boolean;
|
||||
onChange?: (value: boolean, name?: string) => void;
|
||||
};
|
||||
|
||||
class PermissionCheckbox extends React.Component<Props> {
|
||||
render() {
|
||||
const { t } = this.props;
|
||||
return (
|
||||
<Checkbox
|
||||
key={this.props.name}
|
||||
name={this.props.name}
|
||||
helpText={t('verbs.repository.' + this.props.name + '.description')}
|
||||
label={t('verbs.repository.' + this.props.name + '.displayName')}
|
||||
checked={this.props.checked}
|
||||
onChange={this.props.onChange}
|
||||
disabled={this.props.disabled}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default translate('plugins')(PermissionCheckbox);
|
||||
@@ -1,16 +1,15 @@
|
||||
// @flow
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import { Select } from "@scm-manager/ui-components";
|
||||
import React from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import { Select } from '@scm-manager/ui-components';
|
||||
|
||||
type Props = {
|
||||
t: string => string,
|
||||
availableRoles: string[],
|
||||
handleRoleChange: string => void,
|
||||
role: string,
|
||||
label?: string,
|
||||
helpText?: string,
|
||||
loading?: boolean
|
||||
t: (p: string) => string;
|
||||
availableRoles: string[];
|
||||
handleRoleChange: (p: string) => void;
|
||||
role: string;
|
||||
label?: string;
|
||||
helpText?: string;
|
||||
loading?: boolean;
|
||||
};
|
||||
|
||||
class RoleSelector extends React.Component<Props> {
|
||||
@@ -21,19 +20,19 @@ class RoleSelector extends React.Component<Props> {
|
||||
handleRoleChange,
|
||||
loading,
|
||||
label,
|
||||
helpText
|
||||
helpText,
|
||||
} = this.props;
|
||||
|
||||
if (!availableRoles) return null;
|
||||
|
||||
const options = role
|
||||
? this.createSelectOptions(availableRoles)
|
||||
: ["", ...this.createSelectOptions(availableRoles)];
|
||||
: ['', ...this.createSelectOptions(availableRoles)];
|
||||
|
||||
return (
|
||||
<Select
|
||||
onChange={handleRoleChange}
|
||||
value={role ? role : ""}
|
||||
value={role ? role : ''}
|
||||
options={options}
|
||||
loading={loading}
|
||||
label={label}
|
||||
@@ -46,10 +45,10 @@ class RoleSelector extends React.Component<Props> {
|
||||
return roles.map(role => {
|
||||
return {
|
||||
label: role,
|
||||
value: role
|
||||
value: role,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default translate("repos")(RoleSelector);
|
||||
export default translate('repos')(RoleSelector);
|
||||
@@ -1,92 +0,0 @@
|
||||
import React from "react";
|
||||
import { shallow, mount } from "@scm-manager/ui-tests/enzyme-router";
|
||||
import "@scm-manager/ui-tests/enzyme";
|
||||
import "@scm-manager/ui-tests/i18n";
|
||||
import DeletePermissionButton from "./DeletePermissionButton";
|
||||
|
||||
import { confirmAlert } from "@scm-manager/ui-components";
|
||||
jest.mock("@scm-manager/ui-components", () => ({
|
||||
confirmAlert: jest.fn(),
|
||||
DeleteButton: require.requireActual("@scm-manager/ui-components").DeleteButton
|
||||
}));
|
||||
|
||||
describe("DeletePermissionButton", () => {
|
||||
|
||||
it("should render nothing, if the delete link is missing", () => {
|
||||
const permission = {
|
||||
_links: {}
|
||||
};
|
||||
|
||||
const navLink = shallow(
|
||||
<DeletePermissionButton
|
||||
permission={permission}
|
||||
deletePermission={() => {}}
|
||||
/>
|
||||
);
|
||||
expect(navLink.text()).toBe("");
|
||||
});
|
||||
|
||||
it("should render the delete icon", () => {
|
||||
const permission = {
|
||||
_links: {
|
||||
delete: {
|
||||
href: "/permission"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const deleteIcon = mount(
|
||||
<DeletePermissionButton
|
||||
permission={permission}
|
||||
deletePermission={() => {}}
|
||||
/>
|
||||
);
|
||||
expect(deleteIcon.html()).not.toBe("");
|
||||
});
|
||||
|
||||
it("should open the confirm dialog on button click", () => {
|
||||
const permission = {
|
||||
_links: {
|
||||
delete: {
|
||||
href: "/permission"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const button = mount(
|
||||
<DeletePermissionButton
|
||||
permission={permission}
|
||||
deletePermission={() => {}}
|
||||
/>
|
||||
);
|
||||
button.find(".fa-trash").simulate("click");
|
||||
|
||||
expect(confirmAlert.mock.calls.length).toBe(1);
|
||||
});
|
||||
|
||||
it("should call the delete permission function with delete url", () => {
|
||||
const permission = {
|
||||
_links: {
|
||||
delete: {
|
||||
href: "/permission"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let calledUrl = null;
|
||||
function capture(permission) {
|
||||
calledUrl = permission._links.delete.href;
|
||||
}
|
||||
|
||||
const button = mount(
|
||||
<DeletePermissionButton
|
||||
permission={permission}
|
||||
confirmDialog={false}
|
||||
deletePermission={capture}
|
||||
/>
|
||||
);
|
||||
button.find(".fa-trash").simulate("click");
|
||||
|
||||
expect(calledUrl).toBe("/permission");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,92 @@
|
||||
import React from 'react';
|
||||
import { shallow, mount } from '@scm-manager/ui-tests/enzyme-router';
|
||||
import '@scm-manager/ui-tests/enzyme';
|
||||
import '@scm-manager/ui-tests/i18n';
|
||||
import DeletePermissionButton from './DeletePermissionButton';
|
||||
|
||||
import { confirmAlert } from '@scm-manager/ui-components';
|
||||
jest.mock('@scm-manager/ui-components', () => ({
|
||||
confirmAlert: jest.fn(),
|
||||
DeleteButton: require.requireActual('@scm-manager/ui-components')
|
||||
.DeleteButton,
|
||||
}));
|
||||
|
||||
describe('DeletePermissionButton', () => {
|
||||
it('should render nothing, if the delete link is missing', () => {
|
||||
const permission = {
|
||||
_links: {},
|
||||
};
|
||||
|
||||
const navLink = shallow(
|
||||
<DeletePermissionButton
|
||||
permission={permission}
|
||||
deletePermission={() => {}}
|
||||
/>,
|
||||
);
|
||||
expect(navLink.text()).toBe('');
|
||||
});
|
||||
|
||||
it('should render the delete icon', () => {
|
||||
const permission = {
|
||||
_links: {
|
||||
delete: {
|
||||
href: '/permission',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const deleteIcon = mount(
|
||||
<DeletePermissionButton
|
||||
permission={permission}
|
||||
deletePermission={() => {}}
|
||||
/>,
|
||||
);
|
||||
expect(deleteIcon.html()).not.toBe('');
|
||||
});
|
||||
|
||||
it('should open the confirm dialog on button click', () => {
|
||||
const permission = {
|
||||
_links: {
|
||||
delete: {
|
||||
href: '/permission',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const button = mount(
|
||||
<DeletePermissionButton
|
||||
permission={permission}
|
||||
deletePermission={() => {}}
|
||||
/>,
|
||||
);
|
||||
button.find('.fa-trash').simulate('click');
|
||||
|
||||
expect(confirmAlert.mock.calls.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should call the delete permission function with delete url', () => {
|
||||
const permission = {
|
||||
_links: {
|
||||
delete: {
|
||||
href: '/permission',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
let calledUrl = null;
|
||||
function capture(permission) {
|
||||
calledUrl = permission._links.delete.href;
|
||||
}
|
||||
|
||||
const button = mount(
|
||||
<DeletePermissionButton
|
||||
permission={permission}
|
||||
confirmDialog={false}
|
||||
deletePermission={capture}
|
||||
/>,
|
||||
);
|
||||
button.find('.fa-trash').simulate('click');
|
||||
|
||||
expect(calledUrl).toBe('/permission');
|
||||
});
|
||||
});
|
||||
@@ -1,51 +1,50 @@
|
||||
// @flow
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import type { Permission } from "@scm-manager/ui-types";
|
||||
import { confirmAlert } from "@scm-manager/ui-components";
|
||||
import React from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import { Permission } from '@scm-manager/ui-types';
|
||||
import { confirmAlert } from '@scm-manager/ui-components';
|
||||
|
||||
type Props = {
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
confirmDialog?: boolean,
|
||||
t: string => string,
|
||||
permission: Permission;
|
||||
namespace: string;
|
||||
repoName: string;
|
||||
confirmDialog?: boolean;
|
||||
t: (p: string) => string;
|
||||
deletePermission: (
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
) => void,
|
||||
loading: boolean
|
||||
repoName: string,
|
||||
) => void;
|
||||
loading: boolean;
|
||||
};
|
||||
|
||||
class DeletePermissionButton extends React.Component<Props> {
|
||||
static defaultProps = {
|
||||
confirmDialog: true
|
||||
confirmDialog: true,
|
||||
};
|
||||
|
||||
deletePermission = () => {
|
||||
this.props.deletePermission(
|
||||
this.props.permission,
|
||||
this.props.namespace,
|
||||
this.props.repoName
|
||||
this.props.repoName,
|
||||
);
|
||||
};
|
||||
|
||||
confirmDelete = () => {
|
||||
const { t } = this.props;
|
||||
confirmAlert({
|
||||
title: t("permission.delete-permission-button.confirm-alert.title"),
|
||||
message: t("permission.delete-permission-button.confirm-alert.message"),
|
||||
title: t('permission.delete-permission-button.confirm-alert.title'),
|
||||
message: t('permission.delete-permission-button.confirm-alert.message'),
|
||||
buttons: [
|
||||
{
|
||||
label: t("permission.delete-permission-button.confirm-alert.submit"),
|
||||
onClick: () => this.deletePermission()
|
||||
label: t('permission.delete-permission-button.confirm-alert.submit'),
|
||||
onClick: () => this.deletePermission(),
|
||||
},
|
||||
{
|
||||
label: t("permission.delete-permission-button.confirm-alert.cancel"),
|
||||
onClick: () => null
|
||||
}
|
||||
]
|
||||
label: t('permission.delete-permission-button.confirm-alert.cancel'),
|
||||
onClick: () => null,
|
||||
},
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
@@ -70,4 +69,4 @@ class DeletePermissionButton extends React.Component<Props> {
|
||||
}
|
||||
}
|
||||
|
||||
export default translate("repos")(DeletePermissionButton);
|
||||
export default translate('repos')(DeletePermissionButton);
|
||||
@@ -1,70 +1,69 @@
|
||||
//@flow
|
||||
import * as validator from "./permissionValidation";
|
||||
import * as validator from './permissionValidation';
|
||||
|
||||
describe("permission validation", () => {
|
||||
it("should return true if permission is valid and does not exist", () => {
|
||||
describe('permission validation', () => {
|
||||
it('should return true if permission is valid and does not exist', () => {
|
||||
const permissions = [];
|
||||
const name = "PermissionName";
|
||||
const name = 'PermissionName';
|
||||
const groupPermission = false;
|
||||
|
||||
expect(
|
||||
validator.isPermissionValid(name, groupPermission, permissions)
|
||||
validator.isPermissionValid(name, groupPermission, permissions),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true if permission is valid and does not exists with same group permission", () => {
|
||||
it('should return true if permission is valid and does not exists with same group permission', () => {
|
||||
const permissions = [
|
||||
{
|
||||
name: "PermissionName",
|
||||
name: 'PermissionName',
|
||||
groupPermission: true,
|
||||
type: "READ",
|
||||
type: 'READ',
|
||||
_links: {},
|
||||
verbs: []
|
||||
}
|
||||
verbs: [],
|
||||
},
|
||||
];
|
||||
const name = "PermissionName";
|
||||
const name = 'PermissionName';
|
||||
const groupPermission = false;
|
||||
|
||||
expect(
|
||||
validator.isPermissionValid(name, groupPermission, permissions)
|
||||
validator.isPermissionValid(name, groupPermission, permissions),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false if permission is valid but exists", () => {
|
||||
it('should return false if permission is valid but exists', () => {
|
||||
const permissions = [
|
||||
{
|
||||
name: "PermissionName",
|
||||
name: 'PermissionName',
|
||||
groupPermission: false,
|
||||
type: "READ",
|
||||
type: 'READ',
|
||||
_links: {},
|
||||
verbs: []
|
||||
}
|
||||
verbs: [],
|
||||
},
|
||||
];
|
||||
const name = "PermissionName";
|
||||
const name = 'PermissionName';
|
||||
const groupPermission = false;
|
||||
|
||||
expect(
|
||||
validator.isPermissionValid(name, groupPermission, permissions)
|
||||
validator.isPermissionValid(name, groupPermission, permissions),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false if permission does not exist but is invalid", () => {
|
||||
it('should return false if permission does not exist but is invalid', () => {
|
||||
const permissions = [];
|
||||
const name = "@PermissionName";
|
||||
const name = '@PermissionName';
|
||||
const groupPermission = false;
|
||||
|
||||
expect(
|
||||
validator.isPermissionValid(name, groupPermission, permissions)
|
||||
validator.isPermissionValid(name, groupPermission, permissions),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false if permission is not valid and does not exist", () => {
|
||||
it('should return false if permission is not valid and does not exist', () => {
|
||||
const permissions = [];
|
||||
const name = "@PermissionName";
|
||||
const name = '@PermissionName';
|
||||
const groupPermission = false;
|
||||
|
||||
expect(
|
||||
validator.isPermissionValid(name, groupPermission, permissions)
|
||||
validator.isPermissionValid(name, groupPermission, permissions),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,5 @@
|
||||
// @flow
|
||||
import {validation} from "@scm-manager/ui-components";
|
||||
import type {PermissionCollection} from "@scm-manager/ui-types";
|
||||
import { validation } from '@scm-manager/ui-components';
|
||||
import { PermissionCollection } from '@scm-manager/ui-types';
|
||||
|
||||
const isNameValid = validation.isNameValid;
|
||||
|
||||
@@ -9,7 +8,7 @@ export { isNameValid };
|
||||
export const isPermissionValid = (
|
||||
name: string,
|
||||
groupPermission: boolean,
|
||||
permissions: PermissionCollection
|
||||
permissions: PermissionCollection,
|
||||
) => {
|
||||
return (
|
||||
isNameValid(name) &&
|
||||
@@ -20,7 +19,7 @@ export const isPermissionValid = (
|
||||
const currentPermissionIncludeName = (
|
||||
name: string,
|
||||
groupPermission: boolean,
|
||||
permissions: PermissionCollection
|
||||
permissions: PermissionCollection,
|
||||
) => {
|
||||
for (let i = 0; i < permissions.length; i++) {
|
||||
if (
|
||||
@@ -1,27 +1,26 @@
|
||||
// @flow
|
||||
import React from "react";
|
||||
import React from 'react';
|
||||
import {
|
||||
ButtonGroup,
|
||||
Button,
|
||||
SubmitButton,
|
||||
Modal
|
||||
} from "@scm-manager/ui-components";
|
||||
import { translate } from "react-i18next";
|
||||
import PermissionCheckbox from "../components/PermissionCheckbox";
|
||||
Modal,
|
||||
} from '@scm-manager/ui-components';
|
||||
import { translate } from 'react-i18next';
|
||||
import PermissionCheckbox from '../components/PermissionCheckbox';
|
||||
|
||||
type Props = {
|
||||
readOnly: boolean,
|
||||
availableVerbs: string[],
|
||||
selectedVerbs: string[],
|
||||
onSubmit: (string[]) => void,
|
||||
onClose: () => void,
|
||||
readOnly: boolean;
|
||||
availableVerbs: string[];
|
||||
selectedVerbs: string[];
|
||||
onSubmit: (p: string[]) => void;
|
||||
onClose: () => void;
|
||||
|
||||
// context props
|
||||
t: string => string
|
||||
t: (p: string) => string;
|
||||
};
|
||||
|
||||
type State = {
|
||||
verbs: any
|
||||
verbs: any;
|
||||
};
|
||||
|
||||
class AdvancedPermissionsDialog extends React.Component<Props, State> {
|
||||
@@ -33,9 +32,11 @@ class AdvancedPermissionsDialog extends React.Component<Props, State> {
|
||||
verb =>
|
||||
(verbs[verb] = props.selectedVerbs
|
||||
? props.selectedVerbs.includes(verb)
|
||||
: false)
|
||||
: false),
|
||||
);
|
||||
this.state = { verbs };
|
||||
this.state = {
|
||||
verbs,
|
||||
};
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -53,7 +54,7 @@ class AdvancedPermissionsDialog extends React.Component<Props, State> {
|
||||
));
|
||||
|
||||
const submitButton = !readOnly ? (
|
||||
<SubmitButton label={t("permission.advanced.dialog.submit")} />
|
||||
<SubmitButton label={t('permission.advanced.dialog.submit')} />
|
||||
) : null;
|
||||
|
||||
const body = <>{verbSelectBoxes}</>;
|
||||
@@ -63,7 +64,7 @@ class AdvancedPermissionsDialog extends React.Component<Props, State> {
|
||||
<ButtonGroup>
|
||||
{submitButton}
|
||||
<Button
|
||||
label={t("permission.advanced.dialog.abort")}
|
||||
label={t('permission.advanced.dialog.abort')}
|
||||
action={onClose}
|
||||
/>
|
||||
</ButtonGroup>
|
||||
@@ -72,7 +73,7 @@ class AdvancedPermissionsDialog extends React.Component<Props, State> {
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={t("permission.advanced.dialog.title")}
|
||||
title={t('permission.advanced.dialog.title')}
|
||||
closeFunction={() => onClose()}
|
||||
body={body}
|
||||
footer={footer}
|
||||
@@ -83,17 +84,22 @@ class AdvancedPermissionsDialog extends React.Component<Props, State> {
|
||||
|
||||
handleChange = (value: boolean, name: string) => {
|
||||
const { verbs } = this.state;
|
||||
const newVerbs = { ...verbs, [name]: value };
|
||||
this.setState({ verbs: newVerbs });
|
||||
const newVerbs = {
|
||||
...verbs,
|
||||
[name]: value,
|
||||
};
|
||||
this.setState({
|
||||
verbs: newVerbs,
|
||||
});
|
||||
};
|
||||
|
||||
onSubmit = () => {
|
||||
this.props.onSubmit(
|
||||
Object.entries(this.state.verbs)
|
||||
.filter(e => e[1])
|
||||
.map(e => e[0])
|
||||
.map(e => e[0]),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export default translate("repos")(AdvancedPermissionsDialog);
|
||||
export default translate('repos')(AdvancedPermissionsDialog);
|
||||
@@ -1,7 +1,11 @@
|
||||
// @flow
|
||||
import React from "react";
|
||||
import {translate} from "react-i18next";
|
||||
import type {PermissionCollection, PermissionCreateEntry, RepositoryRole, SelectValue} from "@scm-manager/ui-types";
|
||||
import React from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import {
|
||||
PermissionCollection,
|
||||
PermissionCreateEntry,
|
||||
RepositoryRole,
|
||||
SelectValue,
|
||||
} from '@scm-manager/ui-types';
|
||||
import {
|
||||
Button,
|
||||
GroupAutocomplete,
|
||||
@@ -9,34 +13,34 @@ import {
|
||||
Radio,
|
||||
SubmitButton,
|
||||
Subtitle,
|
||||
UserAutocomplete
|
||||
} from "@scm-manager/ui-components";
|
||||
import * as validator from "../components/permissionValidation";
|
||||
import RoleSelector from "../components/RoleSelector";
|
||||
import AdvancedPermissionsDialog from "./AdvancedPermissionsDialog";
|
||||
import {findVerbsForRole} from "../modules/permissions";
|
||||
UserAutocomplete,
|
||||
} from '@scm-manager/ui-components';
|
||||
import * as validator from '../components/permissionValidation';
|
||||
import RoleSelector from '../components/RoleSelector';
|
||||
import AdvancedPermissionsDialog from './AdvancedPermissionsDialog';
|
||||
import { findVerbsForRole } from '../modules/permissions';
|
||||
|
||||
type Props = {
|
||||
availableRoles: RepositoryRole[],
|
||||
availableVerbs: string[],
|
||||
createPermission: (permission: PermissionCreateEntry) => void,
|
||||
loading: boolean,
|
||||
currentPermissions: PermissionCollection,
|
||||
groupAutocompleteLink: string,
|
||||
userAutocompleteLink: string,
|
||||
availableRoles: RepositoryRole[];
|
||||
availableVerbs: string[];
|
||||
createPermission: (permission: PermissionCreateEntry) => void;
|
||||
loading: boolean;
|
||||
currentPermissions: PermissionCollection;
|
||||
groupAutocompleteLink: string;
|
||||
userAutocompleteLink: string;
|
||||
|
||||
// Context props
|
||||
t: string => string
|
||||
t: (p: string) => string;
|
||||
};
|
||||
|
||||
type State = {
|
||||
name: string,
|
||||
role?: string,
|
||||
verbs?: string[],
|
||||
groupPermission: boolean,
|
||||
valid: boolean,
|
||||
value?: SelectValue,
|
||||
showAdvancedDialog: boolean
|
||||
name: string;
|
||||
role?: string;
|
||||
verbs?: string[];
|
||||
groupPermission: boolean;
|
||||
valid: boolean;
|
||||
value?: SelectValue;
|
||||
showAdvancedDialog: boolean;
|
||||
};
|
||||
|
||||
class CreatePermissionForm extends React.Component<Props, State> {
|
||||
@@ -44,23 +48,23 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
name: "",
|
||||
name: '',
|
||||
role: props.availableRoles[0].name,
|
||||
verbs: undefined,
|
||||
groupPermission: false,
|
||||
valid: true,
|
||||
value: undefined,
|
||||
showAdvancedDialog: false
|
||||
showAdvancedDialog: false,
|
||||
};
|
||||
}
|
||||
|
||||
permissionScopeChanged = event => {
|
||||
const groupPermission = event.target.value === "GROUP_PERMISSION";
|
||||
const groupPermission = event.target.value === 'GROUP_PERMISSION';
|
||||
this.setState({
|
||||
value: undefined,
|
||||
name: "",
|
||||
name: '',
|
||||
groupPermission: groupPermission,
|
||||
valid: false
|
||||
valid: false,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -71,7 +75,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
<GroupAutocomplete
|
||||
autocompleteLink={this.props.groupAutocompleteLink}
|
||||
valueSelected={this.selectName}
|
||||
value={this.state.value ? this.state.value : ""}
|
||||
value={this.state.value ? this.state.value : ''}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -79,7 +83,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
<UserAutocomplete
|
||||
autocompleteLink={this.props.userAutocompleteLink}
|
||||
valueSelected={this.selectName}
|
||||
value={this.state.value ? this.state.value : ""}
|
||||
value={this.state.value ? this.state.value : ''}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -91,8 +95,8 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
valid: validator.isPermissionValid(
|
||||
value.value.id,
|
||||
this.state.groupPermission,
|
||||
this.props.currentPermissions
|
||||
)
|
||||
this.props.currentPermissions,
|
||||
),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -117,7 +121,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
<>
|
||||
<hr />
|
||||
<Subtitle
|
||||
subtitle={t("permission.add-permission.add-permission-heading")}
|
||||
subtitle={t('permission.add-permission.add-permission-heading')}
|
||||
/>
|
||||
{advancedDialog}
|
||||
<form onSubmit={this.submit}>
|
||||
@@ -127,14 +131,14 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
name="permission_scope"
|
||||
value="USER_PERMISSION"
|
||||
checked={!this.state.groupPermission}
|
||||
label={t("permission.user-permission")}
|
||||
label={t('permission.user-permission')}
|
||||
onChange={this.permissionScopeChanged}
|
||||
/>
|
||||
<Radio
|
||||
name="permission_scope"
|
||||
value="GROUP_PERMISSION"
|
||||
checked={this.state.groupPermission}
|
||||
label={t("permission.group-permission")}
|
||||
label={t('permission.group-permission')}
|
||||
onChange={this.permissionScopeChanged}
|
||||
/>
|
||||
</div>
|
||||
@@ -148,19 +152,19 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
<div className="column is-narrow">
|
||||
<RoleSelector
|
||||
availableRoles={availableRoleNames}
|
||||
label={t("permission.role")}
|
||||
helpText={t("permission.help.roleHelpText")}
|
||||
label={t('permission.role')}
|
||||
helpText={t('permission.help.roleHelpText')}
|
||||
handleRoleChange={this.handleRoleChange}
|
||||
role={role}
|
||||
/>
|
||||
</div>
|
||||
<div className="column">
|
||||
<LabelWithHelpIcon
|
||||
label={t("permission.permissions")}
|
||||
helpText={t("permission.help.permissionsHelpText")}
|
||||
label={t('permission.permissions')}
|
||||
helpText={t('permission.help.permissionsHelpText')}
|
||||
/>
|
||||
<Button
|
||||
label={t("permission.advanced-button.label")}
|
||||
label={t('permission.advanced-button.label')}
|
||||
action={this.toggleAdvancedPermissionsDialog}
|
||||
/>
|
||||
</div>
|
||||
@@ -170,9 +174,9 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
<div className="columns">
|
||||
<div className="column">
|
||||
<SubmitButton
|
||||
label={t("permission.add-permission.submit-button")}
|
||||
label={t('permission.add-permission.submit-button')}
|
||||
loading={loading}
|
||||
disabled={!this.state.valid || this.state.name === ""}
|
||||
disabled={!this.state.valid || this.state.name === ''}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -183,7 +187,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
|
||||
toggleAdvancedPermissionsDialog = () => {
|
||||
this.setState(prevState => ({
|
||||
showAdvancedDialog: !prevState.showAdvancedDialog
|
||||
showAdvancedDialog: !prevState.showAdvancedDialog,
|
||||
}));
|
||||
};
|
||||
|
||||
@@ -191,7 +195,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
this.setState({
|
||||
showAdvancedDialog: false,
|
||||
role: undefined,
|
||||
verbs: newVerbs
|
||||
verbs: newVerbs,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -200,7 +204,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
name: this.state.name,
|
||||
role: this.state.role,
|
||||
verbs: this.state.verbs,
|
||||
groupPermission: this.state.groupPermission
|
||||
groupPermission: this.state.groupPermission,
|
||||
});
|
||||
this.removeState();
|
||||
e.preventDefault();
|
||||
@@ -208,11 +212,11 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
|
||||
removeState = () => {
|
||||
this.setState({
|
||||
name: "",
|
||||
name: '',
|
||||
role: this.props.availableRoles[0].name,
|
||||
verbs: undefined,
|
||||
valid: true,
|
||||
value: undefined
|
||||
value: undefined,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -223,7 +227,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
}
|
||||
this.setState({
|
||||
role: selectedRole.name,
|
||||
verbs: []
|
||||
verbs: [],
|
||||
});
|
||||
};
|
||||
|
||||
@@ -232,4 +236,4 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
};
|
||||
}
|
||||
|
||||
export default translate("repos")(CreatePermissionForm);
|
||||
export default translate('repos')(CreatePermissionForm);
|
||||
@@ -1,7 +1,6 @@
|
||||
//@flow
|
||||
import React from "react";
|
||||
import {connect} from "react-redux";
|
||||
import {translate} from "react-i18next";
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { translate } from 'react-i18next';
|
||||
import {
|
||||
createPermission,
|
||||
createPermissionReset,
|
||||
@@ -21,58 +20,68 @@ import {
|
||||
isCreatePermissionPending,
|
||||
isFetchAvailablePermissionsPending,
|
||||
isFetchPermissionsPending,
|
||||
modifyPermissionReset
|
||||
} from "../modules/permissions";
|
||||
import {ErrorPage, LabelWithHelpIcon, Loading, Subtitle} from "@scm-manager/ui-components";
|
||||
import type {Permission, PermissionCollection, PermissionCreateEntry, RepositoryRole} from "@scm-manager/ui-types";
|
||||
import SinglePermission from "./SinglePermission";
|
||||
import CreatePermissionForm from "./CreatePermissionForm";
|
||||
import type {History} from "history";
|
||||
import {getPermissionsLink} from "../../modules/repos";
|
||||
modifyPermissionReset,
|
||||
} from '../modules/permissions';
|
||||
import {
|
||||
ErrorPage,
|
||||
LabelWithHelpIcon,
|
||||
Loading,
|
||||
Subtitle,
|
||||
} from '@scm-manager/ui-components';
|
||||
import {
|
||||
Permission,
|
||||
PermissionCollection,
|
||||
PermissionCreateEntry,
|
||||
RepositoryRole,
|
||||
} from '@scm-manager/ui-types';
|
||||
import SinglePermission from './SinglePermission';
|
||||
import CreatePermissionForm from './CreatePermissionForm';
|
||||
import { History } from 'history';
|
||||
import { getPermissionsLink } from '../../modules/repos';
|
||||
import {
|
||||
getGroupAutoCompleteLink,
|
||||
getRepositoryRolesLink,
|
||||
getRepositoryVerbsLink,
|
||||
getUserAutoCompleteLink
|
||||
} from "../../../modules/indexResource";
|
||||
getUserAutoCompleteLink,
|
||||
} from '../../../modules/indexResource';
|
||||
|
||||
type Props = {
|
||||
availablePermissions: boolean,
|
||||
availableRepositoryRoles: RepositoryRole[],
|
||||
availableVerbs: string[],
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
loading: boolean,
|
||||
error: Error,
|
||||
permissions: PermissionCollection,
|
||||
hasPermissionToCreate: boolean,
|
||||
loadingCreatePermission: boolean,
|
||||
repositoryRolesLink: string,
|
||||
repositoryVerbsLink: string,
|
||||
permissionsLink: string,
|
||||
groupAutocompleteLink: string,
|
||||
userAutocompleteLink: string,
|
||||
availablePermissions: boolean;
|
||||
availableRepositoryRoles: RepositoryRole[];
|
||||
availableVerbs: string[];
|
||||
namespace: string;
|
||||
repoName: string;
|
||||
loading: boolean;
|
||||
error: Error;
|
||||
permissions: PermissionCollection;
|
||||
hasPermissionToCreate: boolean;
|
||||
loadingCreatePermission: boolean;
|
||||
repositoryRolesLink: string;
|
||||
repositoryVerbsLink: string;
|
||||
permissionsLink: string;
|
||||
groupAutocompleteLink: string;
|
||||
userAutocompleteLink: string;
|
||||
|
||||
//dispatch functions
|
||||
fetchAvailablePermissionsIfNeeded: (
|
||||
repositoryRolesLink: string,
|
||||
repositoryVerbsLink: string
|
||||
) => void,
|
||||
fetchPermissions: (link: string, namespace: string, repoName: string) => void,
|
||||
repositoryVerbsLink: string,
|
||||
) => void;
|
||||
fetchPermissions: (link: string, namespace: string, repoName: string) => void;
|
||||
createPermission: (
|
||||
link: string,
|
||||
permission: PermissionCreateEntry,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
callback?: () => void
|
||||
) => void,
|
||||
createPermissionReset: (string, string) => void,
|
||||
modifyPermissionReset: (string, string) => void,
|
||||
deletePermissionReset: (string, string) => void,
|
||||
callback?: () => void,
|
||||
) => void;
|
||||
createPermissionReset: (p1: string, p2: string) => void;
|
||||
modifyPermissionReset: (p1: string, p2: string) => void;
|
||||
deletePermissionReset: (p1: string, p2: string) => void;
|
||||
// context props
|
||||
t: string => string,
|
||||
match: any,
|
||||
history: History
|
||||
t: (p: string) => string;
|
||||
match: any;
|
||||
history: History;
|
||||
};
|
||||
|
||||
class Permissions extends React.Component<Props> {
|
||||
@@ -87,7 +96,7 @@ class Permissions extends React.Component<Props> {
|
||||
deletePermissionReset,
|
||||
permissionsLink,
|
||||
repositoryRolesLink,
|
||||
repositoryVerbsLink
|
||||
repositoryVerbsLink,
|
||||
} = this.props;
|
||||
|
||||
createPermissionReset(namespace, repoName);
|
||||
@@ -102,7 +111,7 @@ class Permissions extends React.Component<Props> {
|
||||
this.props.permissionsLink,
|
||||
permission,
|
||||
this.props.namespace,
|
||||
this.props.repoName
|
||||
this.props.repoName,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -120,13 +129,13 @@ class Permissions extends React.Component<Props> {
|
||||
loadingCreatePermission,
|
||||
hasPermissionToCreate,
|
||||
userAutocompleteLink,
|
||||
groupAutocompleteLink
|
||||
groupAutocompleteLink,
|
||||
} = this.props;
|
||||
if (error) {
|
||||
return (
|
||||
<ErrorPage
|
||||
title={t("permission.error-title")}
|
||||
subtitle={t("permission.error-subtitle")}
|
||||
title={t('permission.error-title')}
|
||||
subtitle={t('permission.error-subtitle')}
|
||||
error={error}
|
||||
/>
|
||||
);
|
||||
@@ -150,26 +159,26 @@ class Permissions extends React.Component<Props> {
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Subtitle subtitle={t("permission.title")} />
|
||||
<Subtitle subtitle={t('permission.title')} />
|
||||
<table className="card-table table is-hoverable is-fullwidth">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<LabelWithHelpIcon
|
||||
label={t("permission.name")}
|
||||
helpText={t("permission.help.nameHelpText")}
|
||||
label={t('permission.name')}
|
||||
helpText={t('permission.help.nameHelpText')}
|
||||
/>
|
||||
</th>
|
||||
<th>
|
||||
<LabelWithHelpIcon
|
||||
label={t("permission.role")}
|
||||
helpText={t("permission.help.roleHelpText")}
|
||||
label={t('permission.role')}
|
||||
helpText={t('permission.help.roleHelpText')}
|
||||
/>
|
||||
</th>
|
||||
<th>
|
||||
<LabelWithHelpIcon
|
||||
label={t("permission.permissions")}
|
||||
helpText={t("permission.help.permissionsHelpText")}
|
||||
label={t('permission.permissions')}
|
||||
helpText={t('permission.help.permissionsHelpText')}
|
||||
/>
|
||||
</th>
|
||||
<th />
|
||||
@@ -212,7 +221,7 @@ const mapStateToProps = (state, ownProps) => {
|
||||
const loadingCreatePermission = isCreatePermissionPending(
|
||||
state,
|
||||
namespace,
|
||||
repoName
|
||||
repoName,
|
||||
);
|
||||
const hasPermissionToCreate = hasCreatePermission(state, namespace, repoName);
|
||||
const repositoryRolesLink = getRepositoryRolesLink(state);
|
||||
@@ -239,7 +248,7 @@ const mapStateToProps = (state, ownProps) => {
|
||||
loadingCreatePermission,
|
||||
permissionsLink,
|
||||
groupAutocompleteLink,
|
||||
userAutocompleteLink
|
||||
userAutocompleteLink,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -250,13 +259,13 @@ const mapDispatchToProps = dispatch => {
|
||||
},
|
||||
fetchAvailablePermissionsIfNeeded: (
|
||||
repositoryRolesLink: string,
|
||||
repositoryVerbsLink: string
|
||||
repositoryVerbsLink: string,
|
||||
) => {
|
||||
dispatch(
|
||||
fetchAvailablePermissionsIfNeeded(
|
||||
repositoryRolesLink,
|
||||
repositoryVerbsLink
|
||||
)
|
||||
repositoryVerbsLink,
|
||||
),
|
||||
);
|
||||
},
|
||||
createPermission: (
|
||||
@@ -264,10 +273,10 @@ const mapDispatchToProps = dispatch => {
|
||||
permission: PermissionCreateEntry,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
callback?: () => void
|
||||
callback?: () => void,
|
||||
) => {
|
||||
dispatch(
|
||||
createPermission(link, permission, namespace, repoName, callback)
|
||||
createPermission(link, permission, namespace, repoName, callback),
|
||||
);
|
||||
},
|
||||
createPermissionReset: (namespace: string, repoName: string) => {
|
||||
@@ -278,11 +287,11 @@ const mapDispatchToProps = dispatch => {
|
||||
},
|
||||
deletePermissionReset: (namespace: string, repoName: string) => {
|
||||
dispatch(deletePermissionReset(namespace, repoName));
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(translate("repos")(Permissions));
|
||||
mapDispatchToProps,
|
||||
)(translate('repos')(Permissions));
|
||||
@@ -1,49 +1,48 @@
|
||||
// @flow
|
||||
import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
import type { History } from "history";
|
||||
import { translate } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import type { RepositoryRole, Permission } from "@scm-manager/ui-types";
|
||||
import { Button, Icon } from "@scm-manager/ui-components";
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { History } from 'history';
|
||||
import { translate } from 'react-i18next';
|
||||
import styled from 'styled-components';
|
||||
import { RepositoryRole, Permission } from '@scm-manager/ui-types';
|
||||
import { Button, Icon } from '@scm-manager/ui-components';
|
||||
import {
|
||||
modifyPermission,
|
||||
isModifyPermissionPending,
|
||||
deletePermission,
|
||||
isDeletePermissionPending,
|
||||
findVerbsForRole
|
||||
} from "../modules/permissions";
|
||||
import DeletePermissionButton from "../components/buttons/DeletePermissionButton";
|
||||
import RoleSelector from "../components/RoleSelector";
|
||||
import AdvancedPermissionsDialog from "./AdvancedPermissionsDialog";
|
||||
findVerbsForRole,
|
||||
} from '../modules/permissions';
|
||||
import DeletePermissionButton from '../components/buttons/DeletePermissionButton';
|
||||
import RoleSelector from '../components/RoleSelector';
|
||||
import AdvancedPermissionsDialog from './AdvancedPermissionsDialog';
|
||||
|
||||
type Props = {
|
||||
availableRepositoryRoles: RepositoryRole[],
|
||||
availableRepositoryVerbs: string[],
|
||||
submitForm: Permission => void,
|
||||
availableRepositoryRoles: RepositoryRole[];
|
||||
availableRepositoryVerbs: string[];
|
||||
submitForm: (p: Permission) => void;
|
||||
modifyPermission: (
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
name: string
|
||||
) => void,
|
||||
permission: Permission,
|
||||
t: string => string,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
match: any,
|
||||
history: History,
|
||||
loading: boolean,
|
||||
name: string,
|
||||
) => void;
|
||||
permission: Permission;
|
||||
t: (p: string) => string;
|
||||
namespace: string;
|
||||
repoName: string;
|
||||
match: any;
|
||||
history: History;
|
||||
loading: boolean;
|
||||
deletePermission: (
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
name: string
|
||||
) => void,
|
||||
deleteLoading: boolean
|
||||
name: string,
|
||||
) => void;
|
||||
deleteLoading: boolean;
|
||||
};
|
||||
|
||||
type State = {
|
||||
permission: Permission,
|
||||
showAdvancedDialog: boolean
|
||||
permission: Permission;
|
||||
showAdvancedDialog: boolean;
|
||||
};
|
||||
|
||||
const FullWidthTr = styled.tr`
|
||||
@@ -65,13 +64,13 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
|
||||
this.state = {
|
||||
permission: {
|
||||
name: "",
|
||||
name: '',
|
||||
role: undefined,
|
||||
verbs: defaultPermission.verbs,
|
||||
groupPermission: false,
|
||||
_links: {}
|
||||
_links: {},
|
||||
},
|
||||
showAdvancedDialog: false
|
||||
showAdvancedDialog: false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -85,8 +84,8 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
role: permission.role,
|
||||
verbs: permission.verbs,
|
||||
groupPermission: permission.groupPermission,
|
||||
_links: permission._links
|
||||
}
|
||||
_links: permission._links,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -95,7 +94,7 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
this.props.deletePermission(
|
||||
this.props.permission,
|
||||
this.props.namespace,
|
||||
this.props.repoName
|
||||
this.props.repoName,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -106,14 +105,14 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
loading,
|
||||
namespace,
|
||||
repoName,
|
||||
t
|
||||
t,
|
||||
} = this.props;
|
||||
const { permission, showAdvancedDialog } = this.state;
|
||||
const availableRoleNames =
|
||||
!!availableRepositoryRoles && availableRepositoryRoles.map(r => r.name);
|
||||
const readOnly = !this.mayChangePermissions();
|
||||
const roleSelector = readOnly ? (
|
||||
<td>{permission.role ? permission.role : t("permission.custom")}</td>
|
||||
<td>{permission.role ? permission.role : t('permission.custom')}</td>
|
||||
) : (
|
||||
<td>
|
||||
<RoleSelector
|
||||
@@ -141,9 +140,9 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
|
||||
const iconType =
|
||||
permission && permission.groupPermission ? (
|
||||
<Icon title={t("permission.group")} name="user-friends" />
|
||||
<Icon title={t('permission.group')} name="user-friends" />
|
||||
) : (
|
||||
<Icon title={t("permission.user")} name="user" />
|
||||
<Icon title={t('permission.user')} name="user" />
|
||||
);
|
||||
|
||||
return (
|
||||
@@ -154,7 +153,7 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
{roleSelector}
|
||||
<VCenteredTd>
|
||||
<Button
|
||||
label={t("permission.advanced-button.label")}
|
||||
label={t('permission.advanced-button.label')}
|
||||
action={this.handleDetailedPermissionsPressed}
|
||||
/>
|
||||
</VCenteredTd>
|
||||
@@ -177,11 +176,15 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
};
|
||||
|
||||
handleDetailedPermissionsPressed = () => {
|
||||
this.setState({ showAdvancedDialog: true });
|
||||
this.setState({
|
||||
showAdvancedDialog: true,
|
||||
});
|
||||
};
|
||||
|
||||
closeAdvancedPermissionsDialog = () => {
|
||||
this.setState({ showAdvancedDialog: false });
|
||||
this.setState({
|
||||
showAdvancedDialog: false,
|
||||
});
|
||||
};
|
||||
|
||||
submitAdvancedPermissionsDialog = (newVerbs: string[]) => {
|
||||
@@ -189,9 +192,13 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
this.setState(
|
||||
{
|
||||
showAdvancedDialog: false,
|
||||
permission: { ...permission, role: undefined, verbs: newVerbs }
|
||||
permission: {
|
||||
...permission,
|
||||
role: undefined,
|
||||
verbs: newVerbs,
|
||||
},
|
||||
},
|
||||
() => this.modifyPermissionVerbs(newVerbs)
|
||||
() => this.modifyPermissionVerbs(newVerbs),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -199,9 +206,13 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
const { permission } = this.state;
|
||||
this.setState(
|
||||
{
|
||||
permission: { ...permission, role: role, verbs: undefined }
|
||||
permission: {
|
||||
...permission,
|
||||
role: role,
|
||||
verbs: undefined,
|
||||
},
|
||||
},
|
||||
() => this.modifyPermissionRole(role)
|
||||
() => this.modifyPermissionRole(role),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -216,7 +227,7 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
this.props.modifyPermission(
|
||||
permission,
|
||||
this.props.namespace,
|
||||
this.props.repoName
|
||||
this.props.repoName,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -226,7 +237,7 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
this.props.modifyPermission(
|
||||
permission,
|
||||
this.props.namespace,
|
||||
this.props.repoName
|
||||
this.props.repoName,
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -237,16 +248,19 @@ const mapStateToProps = (state, ownProps) => {
|
||||
state,
|
||||
ownProps.namespace,
|
||||
ownProps.repoName,
|
||||
permission
|
||||
permission,
|
||||
);
|
||||
const deleteLoading = isDeletePermissionPending(
|
||||
state,
|
||||
ownProps.namespace,
|
||||
ownProps.repoName,
|
||||
permission
|
||||
permission,
|
||||
);
|
||||
|
||||
return { loading, deleteLoading };
|
||||
return {
|
||||
loading,
|
||||
deleteLoading,
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
@@ -254,20 +268,20 @@ const mapDispatchToProps = dispatch => {
|
||||
modifyPermission: (
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
) => {
|
||||
dispatch(modifyPermission(permission, namespace, repoName));
|
||||
},
|
||||
deletePermission: (
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
) => {
|
||||
dispatch(deletePermission(permission, namespace, repoName));
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(translate("repos")(SinglePermission));
|
||||
mapDispatchToProps,
|
||||
)(translate('repos')(SinglePermission));
|
||||
@@ -1,783 +0,0 @@
|
||||
// @flow
|
||||
import configureMockStore from "redux-mock-store";
|
||||
import thunk from "redux-thunk";
|
||||
import fetchMock from "fetch-mock";
|
||||
import reducer, {
|
||||
CREATE_PERMISSION,
|
||||
CREATE_PERMISSION_FAILURE,
|
||||
CREATE_PERMISSION_PENDING,
|
||||
CREATE_PERMISSION_SUCCESS,
|
||||
createPermission,
|
||||
createPermissionSuccess,
|
||||
DELETE_PERMISSION,
|
||||
DELETE_PERMISSION_FAILURE,
|
||||
DELETE_PERMISSION_PENDING,
|
||||
DELETE_PERMISSION_SUCCESS,
|
||||
deletePermission,
|
||||
deletePermissionSuccess,
|
||||
FETCH_PERMISSIONS,
|
||||
FETCH_PERMISSIONS_FAILURE,
|
||||
FETCH_PERMISSIONS_PENDING,
|
||||
FETCH_PERMISSIONS_SUCCESS,
|
||||
fetchPermissions,
|
||||
fetchPermissionsSuccess,
|
||||
getCreatePermissionFailure,
|
||||
getDeletePermissionFailure,
|
||||
getDeletePermissionsFailure,
|
||||
getFetchPermissionsFailure,
|
||||
getModifyPermissionFailure,
|
||||
getModifyPermissionsFailure,
|
||||
getPermissionsOfRepo,
|
||||
hasCreatePermission,
|
||||
isCreatePermissionPending,
|
||||
isDeletePermissionPending,
|
||||
isFetchPermissionsPending,
|
||||
isModifyPermissionPending,
|
||||
MODIFY_PERMISSION,
|
||||
MODIFY_PERMISSION_FAILURE,
|
||||
MODIFY_PERMISSION_PENDING,
|
||||
MODIFY_PERMISSION_SUCCESS,
|
||||
modifyPermission,
|
||||
modifyPermissionSuccess
|
||||
} from "./permissions";
|
||||
import type {Permission, PermissionCollection} from "@scm-manager/ui-types";
|
||||
|
||||
const hitchhiker_puzzle42Permission_user_eins: Permission = {
|
||||
name: "user_eins",
|
||||
type: "READ",
|
||||
groupPermission: false,
|
||||
_links: {
|
||||
self: {
|
||||
href:
|
||||
"http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions/user_eins"
|
||||
},
|
||||
delete: {
|
||||
href:
|
||||
"http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions/user_eins"
|
||||
},
|
||||
update: {
|
||||
href:
|
||||
"http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions/user_eins"
|
||||
}
|
||||
},
|
||||
verbs: []
|
||||
};
|
||||
|
||||
const hitchhiker_puzzle42Permission_user_zwei: Permission = {
|
||||
name: "user_zwei",
|
||||
type: "WRITE",
|
||||
groupPermission: true,
|
||||
_links: {
|
||||
self: {
|
||||
href:
|
||||
"http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions/user_zwei"
|
||||
},
|
||||
delete: {
|
||||
href:
|
||||
"http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions/user_zwei"
|
||||
},
|
||||
update: {
|
||||
href:
|
||||
"http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions/user_zwei"
|
||||
}
|
||||
},
|
||||
verbs: []
|
||||
};
|
||||
|
||||
const hitchhiker_puzzle42Permissions: PermissionCollection = [
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
hitchhiker_puzzle42Permission_user_zwei
|
||||
];
|
||||
|
||||
const hitchhiker_puzzle42RepoPermissions = {
|
||||
_embedded: {
|
||||
permissions: hitchhiker_puzzle42Permissions
|
||||
},
|
||||
_links: {
|
||||
create: {
|
||||
href:
|
||||
"http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
describe("permission fetch", () => {
|
||||
const REPOS_URL = "/api/v2/repositories";
|
||||
const URL = "repositories";
|
||||
const mockStore = configureMockStore([thunk]);
|
||||
|
||||
afterEach(() => {
|
||||
fetchMock.reset();
|
||||
fetchMock.restore();
|
||||
});
|
||||
|
||||
it("should successfully fetch permissions to repo hitchhiker/puzzle42", () => {
|
||||
fetchMock.getOnce(
|
||||
REPOS_URL + "/hitchhiker/puzzle42/permissions",
|
||||
hitchhiker_puzzle42RepoPermissions
|
||||
);
|
||||
|
||||
const expectedActions = [
|
||||
{
|
||||
type: FETCH_PERMISSIONS_PENDING,
|
||||
payload: {
|
||||
namespace: "hitchhiker",
|
||||
repoName: "puzzle42"
|
||||
},
|
||||
itemId: "hitchhiker/puzzle42"
|
||||
},
|
||||
{
|
||||
type: FETCH_PERMISSIONS_SUCCESS,
|
||||
payload: hitchhiker_puzzle42RepoPermissions,
|
||||
itemId: "hitchhiker/puzzle42"
|
||||
}
|
||||
];
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
fetchPermissions(
|
||||
URL + "/hitchhiker/puzzle42/permissions",
|
||||
"hitchhiker",
|
||||
"puzzle42"
|
||||
)
|
||||
)
|
||||
.then(() => {
|
||||
expect(store.getActions()).toEqual(expectedActions);
|
||||
});
|
||||
});
|
||||
|
||||
it("should dispatch FETCH_PERMISSIONS_FAILURE, it the request fails", () => {
|
||||
fetchMock.getOnce(REPOS_URL + "/hitchhiker/puzzle42/permissions", {
|
||||
status: 500
|
||||
});
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
fetchPermissions(
|
||||
URL + "/hitchhiker/puzzle42/permissions",
|
||||
"hitchhiker",
|
||||
"puzzle42"
|
||||
)
|
||||
)
|
||||
.then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0].type).toEqual(FETCH_PERMISSIONS_PENDING);
|
||||
expect(actions[1].type).toEqual(FETCH_PERMISSIONS_FAILURE);
|
||||
expect(actions[1].payload).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it("should successfully modify user_eins permission", () => {
|
||||
fetchMock.putOnce(
|
||||
hitchhiker_puzzle42Permission_user_eins._links.update.href,
|
||||
{
|
||||
status: 204
|
||||
}
|
||||
);
|
||||
|
||||
let editedPermission = { ...hitchhiker_puzzle42Permission_user_eins, type: "OWNER" };
|
||||
|
||||
const store = mockStore({});
|
||||
|
||||
return store
|
||||
.dispatch(modifyPermission(editedPermission, "hitchhiker", "puzzle42"))
|
||||
.then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0].type).toEqual(MODIFY_PERMISSION_PENDING);
|
||||
expect(actions[1].type).toEqual(MODIFY_PERMISSION_SUCCESS);
|
||||
});
|
||||
});
|
||||
|
||||
it("should successfully modify user_eins permission and call the callback", () => {
|
||||
fetchMock.putOnce(
|
||||
hitchhiker_puzzle42Permission_user_eins._links.update.href,
|
||||
{
|
||||
status: 204
|
||||
}
|
||||
);
|
||||
|
||||
let editedPermission = { ...hitchhiker_puzzle42Permission_user_eins, type: "OWNER" };
|
||||
|
||||
const store = mockStore({});
|
||||
|
||||
let called = false;
|
||||
const callback = () => {
|
||||
called = true;
|
||||
};
|
||||
|
||||
return store
|
||||
.dispatch(
|
||||
modifyPermission(editedPermission, "hitchhiker", "puzzle42", callback)
|
||||
)
|
||||
.then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0].type).toEqual(MODIFY_PERMISSION_PENDING);
|
||||
expect(actions[1].type).toEqual(MODIFY_PERMISSION_SUCCESS);
|
||||
expect(called).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it("should fail modifying on HTTP 500", () => {
|
||||
fetchMock.putOnce(
|
||||
hitchhiker_puzzle42Permission_user_eins._links.update.href,
|
||||
{
|
||||
status: 500
|
||||
}
|
||||
);
|
||||
|
||||
let editedPermission = { ...hitchhiker_puzzle42Permission_user_eins, type: "OWNER" };
|
||||
|
||||
const store = mockStore({});
|
||||
|
||||
return store
|
||||
.dispatch(modifyPermission(editedPermission, "hitchhiker", "puzzle42"))
|
||||
.then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0].type).toEqual(MODIFY_PERMISSION_PENDING);
|
||||
expect(actions[1].type).toEqual(MODIFY_PERMISSION_FAILURE);
|
||||
expect(actions[1].payload).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it("should add a permission successfully", () => {
|
||||
// unmatched
|
||||
fetchMock.postOnce(REPOS_URL + "/hitchhiker/puzzle42/permissions", {
|
||||
status: 204,
|
||||
headers: {
|
||||
location: "repositories/hitchhiker/puzzle42/permissions/user_eins"
|
||||
}
|
||||
});
|
||||
|
||||
fetchMock.getOnce(
|
||||
REPOS_URL + "/hitchhiker/puzzle42/permissions/user_eins",
|
||||
hitchhiker_puzzle42Permission_user_eins
|
||||
);
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
createPermission(
|
||||
URL + "/hitchhiker/puzzle42/permissions",
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
"hitchhiker",
|
||||
"puzzle42"
|
||||
)
|
||||
)
|
||||
.then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0].type).toEqual(CREATE_PERMISSION_PENDING);
|
||||
expect(actions[1].type).toEqual(CREATE_PERMISSION_SUCCESS);
|
||||
});
|
||||
});
|
||||
|
||||
it("should fail adding a permission on HTTP 500", () => {
|
||||
fetchMock.postOnce(REPOS_URL + "/hitchhiker/puzzle42/permissions", {
|
||||
status: 500
|
||||
});
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
createPermission(
|
||||
URL + "/hitchhiker/puzzle42/permissions",
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
"hitchhiker",
|
||||
"puzzle42"
|
||||
)
|
||||
)
|
||||
.then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0].type).toEqual(CREATE_PERMISSION_PENDING);
|
||||
expect(actions[1].type).toEqual(CREATE_PERMISSION_FAILURE);
|
||||
expect(actions[1].payload).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it("should call the callback after permission successfully created", () => {
|
||||
// unmatched
|
||||
fetchMock.postOnce(REPOS_URL + "/hitchhiker/puzzle42/permissions", {
|
||||
status: 204,
|
||||
headers: {
|
||||
location: "repositories/hitchhiker/puzzle42/permissions/user_eins"
|
||||
}
|
||||
});
|
||||
|
||||
fetchMock.getOnce(
|
||||
REPOS_URL + "/hitchhiker/puzzle42/permissions/user_eins",
|
||||
hitchhiker_puzzle42Permission_user_eins
|
||||
);
|
||||
let callMe = "not yet";
|
||||
|
||||
const callback = () => {
|
||||
callMe = "yeah";
|
||||
};
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
createPermission(
|
||||
URL + "/hitchhiker/puzzle42/permissions",
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
"hitchhiker",
|
||||
"puzzle42",
|
||||
callback
|
||||
)
|
||||
)
|
||||
.then(() => {
|
||||
expect(callMe).toBe("yeah");
|
||||
});
|
||||
});
|
||||
it("should delete successfully permission user_eins", () => {
|
||||
fetchMock.deleteOnce(
|
||||
hitchhiker_puzzle42Permission_user_eins._links.delete.href,
|
||||
{
|
||||
status: 204
|
||||
}
|
||||
);
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
deletePermission(
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
"hitchhiker",
|
||||
"puzzle42"
|
||||
)
|
||||
)
|
||||
.then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions.length).toBe(2);
|
||||
expect(actions[0].type).toEqual(DELETE_PERMISSION_PENDING);
|
||||
expect(actions[0].payload).toBe(
|
||||
hitchhiker_puzzle42Permission_user_eins
|
||||
);
|
||||
expect(actions[1].type).toEqual(DELETE_PERMISSION_SUCCESS);
|
||||
});
|
||||
});
|
||||
|
||||
it("should call the callback, after successful delete", () => {
|
||||
fetchMock.deleteOnce(
|
||||
hitchhiker_puzzle42Permission_user_eins._links.delete.href,
|
||||
{
|
||||
status: 204
|
||||
}
|
||||
);
|
||||
|
||||
let called = false;
|
||||
const callMe = () => {
|
||||
called = true;
|
||||
};
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
deletePermission(
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
"hitchhiker",
|
||||
"puzzle42",
|
||||
callMe
|
||||
)
|
||||
)
|
||||
.then(() => {
|
||||
expect(called).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
it("should fail to delete permission", () => {
|
||||
fetchMock.deleteOnce(
|
||||
hitchhiker_puzzle42Permission_user_eins._links.delete.href,
|
||||
{
|
||||
status: 500
|
||||
}
|
||||
);
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
deletePermission(
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
"hitchhiker",
|
||||
"puzzle42"
|
||||
)
|
||||
)
|
||||
.then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0].type).toEqual(DELETE_PERMISSION_PENDING);
|
||||
expect(actions[0].payload).toBe(
|
||||
hitchhiker_puzzle42Permission_user_eins
|
||||
);
|
||||
expect(actions[1].type).toEqual(DELETE_PERMISSION_FAILURE);
|
||||
expect(actions[1].payload).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("permissions reducer", () => {
|
||||
it("should return empty object, if state and action is undefined", () => {
|
||||
expect(reducer()).toEqual({});
|
||||
});
|
||||
|
||||
it("should return the same state, if the action is undefined", () => {
|
||||
const state = { x: true };
|
||||
expect(reducer(state)).toBe(state);
|
||||
});
|
||||
|
||||
it("should return the same state, if the action is unknown to the reducer", () => {
|
||||
const state = { x: true };
|
||||
expect(reducer(state, { type: "EL_SPECIALE" })).toBe(state);
|
||||
});
|
||||
|
||||
it("should store the permissions on FETCH_PERMISSION_SUCCESS", () => {
|
||||
const newState = reducer(
|
||||
{},
|
||||
fetchPermissionsSuccess(
|
||||
hitchhiker_puzzle42RepoPermissions,
|
||||
"hitchhiker",
|
||||
"puzzle42"
|
||||
)
|
||||
);
|
||||
|
||||
expect(newState["hitchhiker/puzzle42"].entries).toBe(
|
||||
hitchhiker_puzzle42Permissions
|
||||
);
|
||||
});
|
||||
|
||||
it("should update permission", () => {
|
||||
const oldState = {
|
||||
"hitchhiker/puzzle42": {
|
||||
entries: [hitchhiker_puzzle42Permission_user_eins]
|
||||
}
|
||||
};
|
||||
let permissionEdited = { ...hitchhiker_puzzle42Permission_user_eins, type: "OWNER" };
|
||||
let expectedState = {
|
||||
"hitchhiker/puzzle42": {
|
||||
entries: [permissionEdited]
|
||||
}
|
||||
};
|
||||
const newState = reducer(
|
||||
oldState,
|
||||
modifyPermissionSuccess(permissionEdited, "hitchhiker", "puzzle42")
|
||||
);
|
||||
expect(newState["hitchhiker/puzzle42"]).toEqual(
|
||||
expectedState["hitchhiker/puzzle42"]
|
||||
);
|
||||
});
|
||||
|
||||
it("should remove permission from state when delete succeeds", () => {
|
||||
const state = {
|
||||
"hitchhiker/puzzle42": {
|
||||
entries: [
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
hitchhiker_puzzle42Permission_user_zwei
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
const expectedState = {
|
||||
"hitchhiker/puzzle42": {
|
||||
entries: [hitchhiker_puzzle42Permission_user_zwei]
|
||||
}
|
||||
};
|
||||
|
||||
const newState = reducer(
|
||||
state,
|
||||
deletePermissionSuccess(
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
"hitchhiker",
|
||||
"puzzle42"
|
||||
)
|
||||
);
|
||||
expect(newState["hitchhiker/puzzle42"]).toEqual(
|
||||
expectedState["hitchhiker/puzzle42"]
|
||||
);
|
||||
});
|
||||
|
||||
it("should add permission", () => {
|
||||
//changing state had to be removed because of errors
|
||||
const oldState = {
|
||||
"hitchhiker/puzzle42": {
|
||||
entries: [hitchhiker_puzzle42Permission_user_eins]
|
||||
}
|
||||
};
|
||||
let expectedState = {
|
||||
"hitchhiker/puzzle42": {
|
||||
entries: [
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
hitchhiker_puzzle42Permission_user_zwei
|
||||
]
|
||||
}
|
||||
};
|
||||
const newState = reducer(
|
||||
oldState,
|
||||
createPermissionSuccess(
|
||||
hitchhiker_puzzle42Permission_user_zwei,
|
||||
"hitchhiker",
|
||||
"puzzle42"
|
||||
)
|
||||
);
|
||||
expect(newState["hitchhiker/puzzle42"]).toEqual(
|
||||
expectedState["hitchhiker/puzzle42"]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("permissions selectors", () => {
|
||||
const error = new Error("something goes wrong");
|
||||
|
||||
it("should return the permissions of one repository", () => {
|
||||
const state = {
|
||||
permissions: {
|
||||
"hitchhiker/puzzle42": {
|
||||
entries: hitchhiker_puzzle42Permissions
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const repoPermissions = getPermissionsOfRepo(
|
||||
state,
|
||||
"hitchhiker",
|
||||
"puzzle42"
|
||||
);
|
||||
expect(repoPermissions).toEqual(hitchhiker_puzzle42Permissions);
|
||||
});
|
||||
|
||||
it("should return true, when fetch permissions is pending", () => {
|
||||
const state = {
|
||||
pending: {
|
||||
[FETCH_PERMISSIONS + "/hitchhiker/puzzle42"]: true
|
||||
}
|
||||
};
|
||||
expect(isFetchPermissionsPending(state, "hitchhiker", "puzzle42")).toEqual(
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
it("should return false, when fetch permissions is not pending", () => {
|
||||
expect(isFetchPermissionsPending({}, "hitchiker", "puzzle42")).toEqual(
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
it("should return error when fetch permissions did fail", () => {
|
||||
const state = {
|
||||
failure: {
|
||||
[FETCH_PERMISSIONS + "/hitchhiker/puzzle42"]: error
|
||||
}
|
||||
};
|
||||
expect(getFetchPermissionsFailure(state, "hitchhiker", "puzzle42")).toEqual(
|
||||
error
|
||||
);
|
||||
});
|
||||
|
||||
it("should return undefined when fetch permissions did not fail", () => {
|
||||
expect(getFetchPermissionsFailure({}, "hitchhiker", "puzzle42")).toBe(
|
||||
undefined
|
||||
);
|
||||
});
|
||||
|
||||
it("should return true, when modify permission is pending", () => {
|
||||
const state = {
|
||||
pending: {
|
||||
[MODIFY_PERMISSION + "/hitchhiker/puzzle42/user_eins"]: true
|
||||
}
|
||||
};
|
||||
expect(
|
||||
isModifyPermissionPending(
|
||||
state,
|
||||
"hitchhiker",
|
||||
"puzzle42",
|
||||
hitchhiker_puzzle42Permission_user_eins
|
||||
)
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it("should return false, when modify permission is not pending", () => {
|
||||
expect(
|
||||
isModifyPermissionPending(
|
||||
{},
|
||||
"hitchiker",
|
||||
"puzzle42",
|
||||
hitchhiker_puzzle42Permission_user_eins
|
||||
)
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
it("should return error when modify permission did fail", () => {
|
||||
const state = {
|
||||
failure: {
|
||||
[MODIFY_PERMISSION + "/hitchhiker/puzzle42/user_eins"]: error
|
||||
}
|
||||
};
|
||||
expect(
|
||||
getModifyPermissionFailure(
|
||||
state,
|
||||
"hitchhiker",
|
||||
"puzzle42",
|
||||
hitchhiker_puzzle42Permission_user_eins
|
||||
)
|
||||
).toEqual(error);
|
||||
});
|
||||
|
||||
it("should return undefined when modify permission did not fail", () => {
|
||||
expect(
|
||||
getModifyPermissionFailure(
|
||||
{},
|
||||
"hitchhiker",
|
||||
"puzzle42",
|
||||
hitchhiker_puzzle42Permission_user_eins
|
||||
)
|
||||
).toBe(undefined);
|
||||
});
|
||||
|
||||
it("should return error when one of the modify permissions did fail", () => {
|
||||
const state = {
|
||||
permissions: {
|
||||
"hitchhiker/puzzle42": { entries: hitchhiker_puzzle42Permissions }
|
||||
},
|
||||
failure: {
|
||||
[MODIFY_PERMISSION + "/hitchhiker/puzzle42/user_eins"]: error
|
||||
}
|
||||
};
|
||||
expect(
|
||||
getModifyPermissionsFailure(state, "hitchhiker", "puzzle42")
|
||||
).toEqual(error);
|
||||
});
|
||||
|
||||
it("should return undefined when no modify permissions did not fail", () => {
|
||||
expect(getModifyPermissionsFailure({}, "hitchhiker", "puzzle42")).toBe(
|
||||
undefined
|
||||
);
|
||||
});
|
||||
|
||||
it("should return true, when createPermission is true", () => {
|
||||
const state = {
|
||||
permissions: {
|
||||
"hitchhiker/puzzle42": {
|
||||
createPermission: true
|
||||
}
|
||||
}
|
||||
};
|
||||
expect(hasCreatePermission(state, "hitchhiker", "puzzle42")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false, when createPermission is false", () => {
|
||||
const state = {
|
||||
permissions: {
|
||||
"hitchhiker/puzzle42": {
|
||||
createPermission: false
|
||||
}
|
||||
}
|
||||
};
|
||||
expect(hasCreatePermission(state, "hitchhiker", "puzzle42")).toEqual(false);
|
||||
});
|
||||
|
||||
it("should return true, when delete permission is pending", () => {
|
||||
const state = {
|
||||
pending: {
|
||||
[DELETE_PERMISSION + "/hitchhiker/puzzle42/user_eins"]: true
|
||||
}
|
||||
};
|
||||
expect(
|
||||
isDeletePermissionPending(
|
||||
state,
|
||||
"hitchhiker",
|
||||
"puzzle42",
|
||||
hitchhiker_puzzle42Permission_user_eins
|
||||
)
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it("should return false, when delete permission is not pending", () => {
|
||||
expect(
|
||||
isDeletePermissionPending(
|
||||
{},
|
||||
"hitchiker",
|
||||
"puzzle42",
|
||||
hitchhiker_puzzle42Permission_user_eins
|
||||
)
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
it("should return error when delete permission did fail", () => {
|
||||
const state = {
|
||||
failure: {
|
||||
[DELETE_PERMISSION + "/hitchhiker/puzzle42/user_eins"]: error
|
||||
}
|
||||
};
|
||||
expect(
|
||||
getDeletePermissionFailure(
|
||||
state,
|
||||
"hitchhiker",
|
||||
"puzzle42",
|
||||
hitchhiker_puzzle42Permission_user_eins
|
||||
)
|
||||
).toEqual(error);
|
||||
});
|
||||
|
||||
it("should return undefined when delete permission did not fail", () => {
|
||||
expect(
|
||||
getDeletePermissionFailure(
|
||||
{},
|
||||
"hitchhiker",
|
||||
"puzzle42",
|
||||
hitchhiker_puzzle42Permission_user_eins
|
||||
)
|
||||
).toBe(undefined);
|
||||
});
|
||||
|
||||
it("should return error when one of the delete permissions did fail", () => {
|
||||
const state = {
|
||||
permissions: {
|
||||
"hitchhiker/puzzle42": { entries: hitchhiker_puzzle42Permissions }
|
||||
},
|
||||
failure: {
|
||||
[DELETE_PERMISSION + "/hitchhiker/puzzle42/user_eins"]: error
|
||||
}
|
||||
};
|
||||
expect(
|
||||
getDeletePermissionsFailure(state, "hitchhiker", "puzzle42")
|
||||
).toEqual(error);
|
||||
});
|
||||
|
||||
it("should return undefined when no delete permissions did not fail", () => {
|
||||
expect(getDeletePermissionsFailure({}, "hitchhiker", "puzzle42")).toBe(
|
||||
undefined
|
||||
);
|
||||
});
|
||||
|
||||
it("should return true, when create permission is pending", () => {
|
||||
const state = {
|
||||
pending: {
|
||||
[CREATE_PERMISSION + "/hitchhiker/puzzle42"]: true
|
||||
}
|
||||
};
|
||||
expect(isCreatePermissionPending(state, "hitchhiker", "puzzle42")).toEqual(
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
it("should return false, when create permissions is not pending", () => {
|
||||
expect(isCreatePermissionPending({}, "hitchiker", "puzzle42")).toEqual(
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
it("should return error when create permissions did fail", () => {
|
||||
const state = {
|
||||
failure: {
|
||||
[CREATE_PERMISSION + "/hitchhiker/puzzle42"]: error
|
||||
}
|
||||
};
|
||||
expect(getCreatePermissionFailure(state, "hitchhiker", "puzzle42")).toEqual(
|
||||
error
|
||||
);
|
||||
});
|
||||
|
||||
it("should return undefined when create permissions did not fail", () => {
|
||||
expect(getCreatePermissionFailure({}, "hitchhiker", "puzzle42")).toBe(
|
||||
undefined
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,806 @@
|
||||
import configureMockStore from 'redux-mock-store';
|
||||
import thunk from 'redux-thunk';
|
||||
import fetchMock from 'fetch-mock';
|
||||
import reducer, {
|
||||
CREATE_PERMISSION,
|
||||
CREATE_PERMISSION_FAILURE,
|
||||
CREATE_PERMISSION_PENDING,
|
||||
CREATE_PERMISSION_SUCCESS,
|
||||
createPermission,
|
||||
createPermissionSuccess,
|
||||
DELETE_PERMISSION,
|
||||
DELETE_PERMISSION_FAILURE,
|
||||
DELETE_PERMISSION_PENDING,
|
||||
DELETE_PERMISSION_SUCCESS,
|
||||
deletePermission,
|
||||
deletePermissionSuccess,
|
||||
FETCH_PERMISSIONS,
|
||||
FETCH_PERMISSIONS_FAILURE,
|
||||
FETCH_PERMISSIONS_PENDING,
|
||||
FETCH_PERMISSIONS_SUCCESS,
|
||||
fetchPermissions,
|
||||
fetchPermissionsSuccess,
|
||||
getCreatePermissionFailure,
|
||||
getDeletePermissionFailure,
|
||||
getDeletePermissionsFailure,
|
||||
getFetchPermissionsFailure,
|
||||
getModifyPermissionFailure,
|
||||
getModifyPermissionsFailure,
|
||||
getPermissionsOfRepo,
|
||||
hasCreatePermission,
|
||||
isCreatePermissionPending,
|
||||
isDeletePermissionPending,
|
||||
isFetchPermissionsPending,
|
||||
isModifyPermissionPending,
|
||||
MODIFY_PERMISSION,
|
||||
MODIFY_PERMISSION_FAILURE,
|
||||
MODIFY_PERMISSION_PENDING,
|
||||
MODIFY_PERMISSION_SUCCESS,
|
||||
modifyPermission,
|
||||
modifyPermissionSuccess,
|
||||
} from './permissions';
|
||||
import { Permission, PermissionCollection } from '@scm-manager/ui-types';
|
||||
|
||||
const hitchhiker_puzzle42Permission_user_eins: Permission = {
|
||||
name: 'user_eins',
|
||||
type: 'READ',
|
||||
groupPermission: false,
|
||||
_links: {
|
||||
self: {
|
||||
href:
|
||||
'http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions/user_eins',
|
||||
},
|
||||
delete: {
|
||||
href:
|
||||
'http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions/user_eins',
|
||||
},
|
||||
update: {
|
||||
href:
|
||||
'http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions/user_eins',
|
||||
},
|
||||
},
|
||||
verbs: [],
|
||||
};
|
||||
|
||||
const hitchhiker_puzzle42Permission_user_zwei: Permission = {
|
||||
name: 'user_zwei',
|
||||
type: 'WRITE',
|
||||
groupPermission: true,
|
||||
_links: {
|
||||
self: {
|
||||
href:
|
||||
'http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions/user_zwei',
|
||||
},
|
||||
delete: {
|
||||
href:
|
||||
'http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions/user_zwei',
|
||||
},
|
||||
update: {
|
||||
href:
|
||||
'http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions/user_zwei',
|
||||
},
|
||||
},
|
||||
verbs: [],
|
||||
};
|
||||
|
||||
const hitchhiker_puzzle42Permissions: PermissionCollection = [
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
hitchhiker_puzzle42Permission_user_zwei,
|
||||
];
|
||||
|
||||
const hitchhiker_puzzle42RepoPermissions = {
|
||||
_embedded: {
|
||||
permissions: hitchhiker_puzzle42Permissions,
|
||||
},
|
||||
_links: {
|
||||
create: {
|
||||
href:
|
||||
'http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
describe('permission fetch', () => {
|
||||
const REPOS_URL = '/api/v2/repositories';
|
||||
const URL = 'repositories';
|
||||
const mockStore = configureMockStore([thunk]);
|
||||
|
||||
afterEach(() => {
|
||||
fetchMock.reset();
|
||||
fetchMock.restore();
|
||||
});
|
||||
|
||||
it('should successfully fetch permissions to repo hitchhiker/puzzle42', () => {
|
||||
fetchMock.getOnce(
|
||||
REPOS_URL + '/hitchhiker/puzzle42/permissions',
|
||||
hitchhiker_puzzle42RepoPermissions,
|
||||
);
|
||||
|
||||
const expectedActions = [
|
||||
{
|
||||
type: FETCH_PERMISSIONS_PENDING,
|
||||
payload: {
|
||||
namespace: 'hitchhiker',
|
||||
repoName: 'puzzle42',
|
||||
},
|
||||
itemId: 'hitchhiker/puzzle42',
|
||||
},
|
||||
{
|
||||
type: FETCH_PERMISSIONS_SUCCESS,
|
||||
payload: hitchhiker_puzzle42RepoPermissions,
|
||||
itemId: 'hitchhiker/puzzle42',
|
||||
},
|
||||
];
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
fetchPermissions(
|
||||
URL + '/hitchhiker/puzzle42/permissions',
|
||||
'hitchhiker',
|
||||
'puzzle42',
|
||||
),
|
||||
)
|
||||
.then(() => {
|
||||
expect(store.getActions()).toEqual(expectedActions);
|
||||
});
|
||||
});
|
||||
|
||||
it('should dispatch FETCH_PERMISSIONS_FAILURE, it the request fails', () => {
|
||||
fetchMock.getOnce(REPOS_URL + '/hitchhiker/puzzle42/permissions', {
|
||||
status: 500,
|
||||
});
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
fetchPermissions(
|
||||
URL + '/hitchhiker/puzzle42/permissions',
|
||||
'hitchhiker',
|
||||
'puzzle42',
|
||||
),
|
||||
)
|
||||
.then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0].type).toEqual(FETCH_PERMISSIONS_PENDING);
|
||||
expect(actions[1].type).toEqual(FETCH_PERMISSIONS_FAILURE);
|
||||
expect(actions[1].payload).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('should successfully modify user_eins permission', () => {
|
||||
fetchMock.putOnce(
|
||||
hitchhiker_puzzle42Permission_user_eins._links.update.href,
|
||||
{
|
||||
status: 204,
|
||||
},
|
||||
);
|
||||
|
||||
let editedPermission = {
|
||||
...hitchhiker_puzzle42Permission_user_eins,
|
||||
type: 'OWNER',
|
||||
};
|
||||
|
||||
const store = mockStore({});
|
||||
|
||||
return store
|
||||
.dispatch(modifyPermission(editedPermission, 'hitchhiker', 'puzzle42'))
|
||||
.then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0].type).toEqual(MODIFY_PERMISSION_PENDING);
|
||||
expect(actions[1].type).toEqual(MODIFY_PERMISSION_SUCCESS);
|
||||
});
|
||||
});
|
||||
|
||||
it('should successfully modify user_eins permission and call the callback', () => {
|
||||
fetchMock.putOnce(
|
||||
hitchhiker_puzzle42Permission_user_eins._links.update.href,
|
||||
{
|
||||
status: 204,
|
||||
},
|
||||
);
|
||||
|
||||
let editedPermission = {
|
||||
...hitchhiker_puzzle42Permission_user_eins,
|
||||
type: 'OWNER',
|
||||
};
|
||||
|
||||
const store = mockStore({});
|
||||
|
||||
let called = false;
|
||||
const callback = () => {
|
||||
called = true;
|
||||
};
|
||||
|
||||
return store
|
||||
.dispatch(
|
||||
modifyPermission(editedPermission, 'hitchhiker', 'puzzle42', callback),
|
||||
)
|
||||
.then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0].type).toEqual(MODIFY_PERMISSION_PENDING);
|
||||
expect(actions[1].type).toEqual(MODIFY_PERMISSION_SUCCESS);
|
||||
expect(called).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail modifying on HTTP 500', () => {
|
||||
fetchMock.putOnce(
|
||||
hitchhiker_puzzle42Permission_user_eins._links.update.href,
|
||||
{
|
||||
status: 500,
|
||||
},
|
||||
);
|
||||
|
||||
let editedPermission = {
|
||||
...hitchhiker_puzzle42Permission_user_eins,
|
||||
type: 'OWNER',
|
||||
};
|
||||
|
||||
const store = mockStore({});
|
||||
|
||||
return store
|
||||
.dispatch(modifyPermission(editedPermission, 'hitchhiker', 'puzzle42'))
|
||||
.then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0].type).toEqual(MODIFY_PERMISSION_PENDING);
|
||||
expect(actions[1].type).toEqual(MODIFY_PERMISSION_FAILURE);
|
||||
expect(actions[1].payload).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('should add a permission successfully', () => {
|
||||
// unmatched
|
||||
fetchMock.postOnce(REPOS_URL + '/hitchhiker/puzzle42/permissions', {
|
||||
status: 204,
|
||||
headers: {
|
||||
location: 'repositories/hitchhiker/puzzle42/permissions/user_eins',
|
||||
},
|
||||
});
|
||||
|
||||
fetchMock.getOnce(
|
||||
REPOS_URL + '/hitchhiker/puzzle42/permissions/user_eins',
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
);
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
createPermission(
|
||||
URL + '/hitchhiker/puzzle42/permissions',
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
'hitchhiker',
|
||||
'puzzle42',
|
||||
),
|
||||
)
|
||||
.then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0].type).toEqual(CREATE_PERMISSION_PENDING);
|
||||
expect(actions[1].type).toEqual(CREATE_PERMISSION_SUCCESS);
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail adding a permission on HTTP 500', () => {
|
||||
fetchMock.postOnce(REPOS_URL + '/hitchhiker/puzzle42/permissions', {
|
||||
status: 500,
|
||||
});
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
createPermission(
|
||||
URL + '/hitchhiker/puzzle42/permissions',
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
'hitchhiker',
|
||||
'puzzle42',
|
||||
),
|
||||
)
|
||||
.then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0].type).toEqual(CREATE_PERMISSION_PENDING);
|
||||
expect(actions[1].type).toEqual(CREATE_PERMISSION_FAILURE);
|
||||
expect(actions[1].payload).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('should call the callback after permission successfully created', () => {
|
||||
// unmatched
|
||||
fetchMock.postOnce(REPOS_URL + '/hitchhiker/puzzle42/permissions', {
|
||||
status: 204,
|
||||
headers: {
|
||||
location: 'repositories/hitchhiker/puzzle42/permissions/user_eins',
|
||||
},
|
||||
});
|
||||
|
||||
fetchMock.getOnce(
|
||||
REPOS_URL + '/hitchhiker/puzzle42/permissions/user_eins',
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
);
|
||||
let callMe = 'not yet';
|
||||
|
||||
const callback = () => {
|
||||
callMe = 'yeah';
|
||||
};
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
createPermission(
|
||||
URL + '/hitchhiker/puzzle42/permissions',
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
'hitchhiker',
|
||||
'puzzle42',
|
||||
callback,
|
||||
),
|
||||
)
|
||||
.then(() => {
|
||||
expect(callMe).toBe('yeah');
|
||||
});
|
||||
});
|
||||
it('should delete successfully permission user_eins', () => {
|
||||
fetchMock.deleteOnce(
|
||||
hitchhiker_puzzle42Permission_user_eins._links.delete.href,
|
||||
{
|
||||
status: 204,
|
||||
},
|
||||
);
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
deletePermission(
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
'hitchhiker',
|
||||
'puzzle42',
|
||||
),
|
||||
)
|
||||
.then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions.length).toBe(2);
|
||||
expect(actions[0].type).toEqual(DELETE_PERMISSION_PENDING);
|
||||
expect(actions[0].payload).toBe(
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
);
|
||||
expect(actions[1].type).toEqual(DELETE_PERMISSION_SUCCESS);
|
||||
});
|
||||
});
|
||||
|
||||
it('should call the callback, after successful delete', () => {
|
||||
fetchMock.deleteOnce(
|
||||
hitchhiker_puzzle42Permission_user_eins._links.delete.href,
|
||||
{
|
||||
status: 204,
|
||||
},
|
||||
);
|
||||
|
||||
let called = false;
|
||||
const callMe = () => {
|
||||
called = true;
|
||||
};
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
deletePermission(
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
'hitchhiker',
|
||||
'puzzle42',
|
||||
callMe,
|
||||
),
|
||||
)
|
||||
.then(() => {
|
||||
expect(called).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail to delete permission', () => {
|
||||
fetchMock.deleteOnce(
|
||||
hitchhiker_puzzle42Permission_user_eins._links.delete.href,
|
||||
{
|
||||
status: 500,
|
||||
},
|
||||
);
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
deletePermission(
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
'hitchhiker',
|
||||
'puzzle42',
|
||||
),
|
||||
)
|
||||
.then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0].type).toEqual(DELETE_PERMISSION_PENDING);
|
||||
expect(actions[0].payload).toBe(
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
);
|
||||
expect(actions[1].type).toEqual(DELETE_PERMISSION_FAILURE);
|
||||
expect(actions[1].payload).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('permissions reducer', () => {
|
||||
it('should return empty object, if state and action is undefined', () => {
|
||||
expect(reducer()).toEqual({});
|
||||
});
|
||||
|
||||
it('should return the same state, if the action is undefined', () => {
|
||||
const state = {
|
||||
x: true,
|
||||
};
|
||||
expect(reducer(state)).toBe(state);
|
||||
});
|
||||
|
||||
it('should return the same state, if the action is unknown to the reducer', () => {
|
||||
const state = {
|
||||
x: true,
|
||||
};
|
||||
expect(
|
||||
reducer(state, {
|
||||
type: 'EL_SPECIALE',
|
||||
}),
|
||||
).toBe(state);
|
||||
});
|
||||
|
||||
it('should store the permissions on FETCH_PERMISSION_SUCCESS', () => {
|
||||
const newState = reducer(
|
||||
{},
|
||||
fetchPermissionsSuccess(
|
||||
hitchhiker_puzzle42RepoPermissions,
|
||||
'hitchhiker',
|
||||
'puzzle42',
|
||||
),
|
||||
);
|
||||
|
||||
expect(newState['hitchhiker/puzzle42'].entries).toBe(
|
||||
hitchhiker_puzzle42Permissions,
|
||||
);
|
||||
});
|
||||
|
||||
it('should update permission', () => {
|
||||
const oldState = {
|
||||
'hitchhiker/puzzle42': {
|
||||
entries: [hitchhiker_puzzle42Permission_user_eins],
|
||||
},
|
||||
};
|
||||
let permissionEdited = {
|
||||
...hitchhiker_puzzle42Permission_user_eins,
|
||||
type: 'OWNER',
|
||||
};
|
||||
let expectedState = {
|
||||
'hitchhiker/puzzle42': {
|
||||
entries: [permissionEdited],
|
||||
},
|
||||
};
|
||||
const newState = reducer(
|
||||
oldState,
|
||||
modifyPermissionSuccess(permissionEdited, 'hitchhiker', 'puzzle42'),
|
||||
);
|
||||
expect(newState['hitchhiker/puzzle42']).toEqual(
|
||||
expectedState['hitchhiker/puzzle42'],
|
||||
);
|
||||
});
|
||||
|
||||
it('should remove permission from state when delete succeeds', () => {
|
||||
const state = {
|
||||
'hitchhiker/puzzle42': {
|
||||
entries: [
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
hitchhiker_puzzle42Permission_user_zwei,
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const expectedState = {
|
||||
'hitchhiker/puzzle42': {
|
||||
entries: [hitchhiker_puzzle42Permission_user_zwei],
|
||||
},
|
||||
};
|
||||
|
||||
const newState = reducer(
|
||||
state,
|
||||
deletePermissionSuccess(
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
'hitchhiker',
|
||||
'puzzle42',
|
||||
),
|
||||
);
|
||||
expect(newState['hitchhiker/puzzle42']).toEqual(
|
||||
expectedState['hitchhiker/puzzle42'],
|
||||
);
|
||||
});
|
||||
|
||||
it('should add permission', () => {
|
||||
//changing state had to be removed because of errors
|
||||
const oldState = {
|
||||
'hitchhiker/puzzle42': {
|
||||
entries: [hitchhiker_puzzle42Permission_user_eins],
|
||||
},
|
||||
};
|
||||
let expectedState = {
|
||||
'hitchhiker/puzzle42': {
|
||||
entries: [
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
hitchhiker_puzzle42Permission_user_zwei,
|
||||
],
|
||||
},
|
||||
};
|
||||
const newState = reducer(
|
||||
oldState,
|
||||
createPermissionSuccess(
|
||||
hitchhiker_puzzle42Permission_user_zwei,
|
||||
'hitchhiker',
|
||||
'puzzle42',
|
||||
),
|
||||
);
|
||||
expect(newState['hitchhiker/puzzle42']).toEqual(
|
||||
expectedState['hitchhiker/puzzle42'],
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('permissions selectors', () => {
|
||||
const error = new Error('something goes wrong');
|
||||
|
||||
it('should return the permissions of one repository', () => {
|
||||
const state = {
|
||||
permissions: {
|
||||
'hitchhiker/puzzle42': {
|
||||
entries: hitchhiker_puzzle42Permissions,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const repoPermissions = getPermissionsOfRepo(
|
||||
state,
|
||||
'hitchhiker',
|
||||
'puzzle42',
|
||||
);
|
||||
expect(repoPermissions).toEqual(hitchhiker_puzzle42Permissions);
|
||||
});
|
||||
|
||||
it('should return true, when fetch permissions is pending', () => {
|
||||
const state = {
|
||||
pending: {
|
||||
[FETCH_PERMISSIONS + '/hitchhiker/puzzle42']: true,
|
||||
},
|
||||
};
|
||||
expect(isFetchPermissionsPending(state, 'hitchhiker', 'puzzle42')).toEqual(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return false, when fetch permissions is not pending', () => {
|
||||
expect(isFetchPermissionsPending({}, 'hitchiker', 'puzzle42')).toEqual(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return error when fetch permissions did fail', () => {
|
||||
const state = {
|
||||
failure: {
|
||||
[FETCH_PERMISSIONS + '/hitchhiker/puzzle42']: error,
|
||||
},
|
||||
};
|
||||
expect(getFetchPermissionsFailure(state, 'hitchhiker', 'puzzle42')).toEqual(
|
||||
error,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return undefined when fetch permissions did not fail', () => {
|
||||
expect(getFetchPermissionsFailure({}, 'hitchhiker', 'puzzle42')).toBe(
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return true, when modify permission is pending', () => {
|
||||
const state = {
|
||||
pending: {
|
||||
[MODIFY_PERMISSION + '/hitchhiker/puzzle42/user_eins']: true,
|
||||
},
|
||||
};
|
||||
expect(
|
||||
isModifyPermissionPending(
|
||||
state,
|
||||
'hitchhiker',
|
||||
'puzzle42',
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
),
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('should return false, when modify permission is not pending', () => {
|
||||
expect(
|
||||
isModifyPermissionPending(
|
||||
{},
|
||||
'hitchiker',
|
||||
'puzzle42',
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
),
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
it('should return error when modify permission did fail', () => {
|
||||
const state = {
|
||||
failure: {
|
||||
[MODIFY_PERMISSION + '/hitchhiker/puzzle42/user_eins']: error,
|
||||
},
|
||||
};
|
||||
expect(
|
||||
getModifyPermissionFailure(
|
||||
state,
|
||||
'hitchhiker',
|
||||
'puzzle42',
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
),
|
||||
).toEqual(error);
|
||||
});
|
||||
|
||||
it('should return undefined when modify permission did not fail', () => {
|
||||
expect(
|
||||
getModifyPermissionFailure(
|
||||
{},
|
||||
'hitchhiker',
|
||||
'puzzle42',
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
),
|
||||
).toBe(undefined);
|
||||
});
|
||||
|
||||
it('should return error when one of the modify permissions did fail', () => {
|
||||
const state = {
|
||||
permissions: {
|
||||
'hitchhiker/puzzle42': {
|
||||
entries: hitchhiker_puzzle42Permissions,
|
||||
},
|
||||
},
|
||||
failure: {
|
||||
[MODIFY_PERMISSION + '/hitchhiker/puzzle42/user_eins']: error,
|
||||
},
|
||||
};
|
||||
expect(
|
||||
getModifyPermissionsFailure(state, 'hitchhiker', 'puzzle42'),
|
||||
).toEqual(error);
|
||||
});
|
||||
|
||||
it('should return undefined when no modify permissions did not fail', () => {
|
||||
expect(getModifyPermissionsFailure({}, 'hitchhiker', 'puzzle42')).toBe(
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return true, when createPermission is true', () => {
|
||||
const state = {
|
||||
permissions: {
|
||||
'hitchhiker/puzzle42': {
|
||||
createPermission: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
expect(hasCreatePermission(state, 'hitchhiker', 'puzzle42')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false, when createPermission is false', () => {
|
||||
const state = {
|
||||
permissions: {
|
||||
'hitchhiker/puzzle42': {
|
||||
createPermission: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
expect(hasCreatePermission(state, 'hitchhiker', 'puzzle42')).toEqual(false);
|
||||
});
|
||||
|
||||
it('should return true, when delete permission is pending', () => {
|
||||
const state = {
|
||||
pending: {
|
||||
[DELETE_PERMISSION + '/hitchhiker/puzzle42/user_eins']: true,
|
||||
},
|
||||
};
|
||||
expect(
|
||||
isDeletePermissionPending(
|
||||
state,
|
||||
'hitchhiker',
|
||||
'puzzle42',
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
),
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('should return false, when delete permission is not pending', () => {
|
||||
expect(
|
||||
isDeletePermissionPending(
|
||||
{},
|
||||
'hitchiker',
|
||||
'puzzle42',
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
),
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
it('should return error when delete permission did fail', () => {
|
||||
const state = {
|
||||
failure: {
|
||||
[DELETE_PERMISSION + '/hitchhiker/puzzle42/user_eins']: error,
|
||||
},
|
||||
};
|
||||
expect(
|
||||
getDeletePermissionFailure(
|
||||
state,
|
||||
'hitchhiker',
|
||||
'puzzle42',
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
),
|
||||
).toEqual(error);
|
||||
});
|
||||
|
||||
it('should return undefined when delete permission did not fail', () => {
|
||||
expect(
|
||||
getDeletePermissionFailure(
|
||||
{},
|
||||
'hitchhiker',
|
||||
'puzzle42',
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
),
|
||||
).toBe(undefined);
|
||||
});
|
||||
|
||||
it('should return error when one of the delete permissions did fail', () => {
|
||||
const state = {
|
||||
permissions: {
|
||||
'hitchhiker/puzzle42': {
|
||||
entries: hitchhiker_puzzle42Permissions,
|
||||
},
|
||||
},
|
||||
failure: {
|
||||
[DELETE_PERMISSION + '/hitchhiker/puzzle42/user_eins']: error,
|
||||
},
|
||||
};
|
||||
expect(
|
||||
getDeletePermissionsFailure(state, 'hitchhiker', 'puzzle42'),
|
||||
).toEqual(error);
|
||||
});
|
||||
|
||||
it('should return undefined when no delete permissions did not fail', () => {
|
||||
expect(getDeletePermissionsFailure({}, 'hitchhiker', 'puzzle42')).toBe(
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return true, when create permission is pending', () => {
|
||||
const state = {
|
||||
pending: {
|
||||
[CREATE_PERMISSION + '/hitchhiker/puzzle42']: true,
|
||||
},
|
||||
};
|
||||
expect(isCreatePermissionPending(state, 'hitchhiker', 'puzzle42')).toEqual(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return false, when create permissions is not pending', () => {
|
||||
expect(isCreatePermissionPending({}, 'hitchiker', 'puzzle42')).toEqual(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return error when create permissions did fail', () => {
|
||||
const state = {
|
||||
failure: {
|
||||
[CREATE_PERMISSION + '/hitchhiker/puzzle42']: error,
|
||||
},
|
||||
};
|
||||
expect(getCreatePermissionFailure(state, 'hitchhiker', 'puzzle42')).toEqual(
|
||||
error,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return undefined when create permissions did not fail', () => {
|
||||
expect(getCreatePermissionFailure({}, 'hitchhiker', 'puzzle42')).toBe(
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,93 +1,55 @@
|
||||
// @flow
|
||||
|
||||
import type { Action } from "@scm-manager/ui-components";
|
||||
import { apiClient } from "@scm-manager/ui-components";
|
||||
import * as types from "../../../modules/types";
|
||||
import type {
|
||||
import { Action } from '@scm-manager/ui-components';
|
||||
import { apiClient } from '@scm-manager/ui-components';
|
||||
import * as types from '../../../modules/types';
|
||||
import {
|
||||
RepositoryRole,
|
||||
Permission,
|
||||
PermissionCollection,
|
||||
PermissionCreateEntry
|
||||
} from "@scm-manager/ui-types";
|
||||
import { isPending } from "../../../modules/pending";
|
||||
import { getFailure } from "../../../modules/failure";
|
||||
import { Dispatch } from "redux";
|
||||
PermissionCreateEntry,
|
||||
} from '@scm-manager/ui-types';
|
||||
import { isPending } from '../../../modules/pending';
|
||||
import { getFailure } from '../../../modules/failure';
|
||||
import { Dispatch } from 'redux';
|
||||
|
||||
export const FETCH_AVAILABLE = "scm/permissions/FETCH_AVAILABLE";
|
||||
export const FETCH_AVAILABLE_PENDING = `${FETCH_AVAILABLE}_${
|
||||
types.PENDING_SUFFIX
|
||||
}`;
|
||||
export const FETCH_AVAILABLE_SUCCESS = `${FETCH_AVAILABLE}_${
|
||||
types.SUCCESS_SUFFIX
|
||||
}`;
|
||||
export const FETCH_AVAILABLE_FAILURE = `${FETCH_AVAILABLE}_${
|
||||
types.FAILURE_SUFFIX
|
||||
}`;
|
||||
export const FETCH_PERMISSIONS = "scm/permissions/FETCH_PERMISSIONS";
|
||||
export const FETCH_PERMISSIONS_PENDING = `${FETCH_PERMISSIONS}_${
|
||||
types.PENDING_SUFFIX
|
||||
}`;
|
||||
export const FETCH_PERMISSIONS_SUCCESS = `${FETCH_PERMISSIONS}_${
|
||||
types.SUCCESS_SUFFIX
|
||||
}`;
|
||||
export const FETCH_PERMISSIONS_FAILURE = `${FETCH_PERMISSIONS}_${
|
||||
types.FAILURE_SUFFIX
|
||||
}`;
|
||||
export const MODIFY_PERMISSION = "scm/permissions/MODFIY_PERMISSION";
|
||||
export const MODIFY_PERMISSION_PENDING = `${MODIFY_PERMISSION}_${
|
||||
types.PENDING_SUFFIX
|
||||
}`;
|
||||
export const MODIFY_PERMISSION_SUCCESS = `${MODIFY_PERMISSION}_${
|
||||
types.SUCCESS_SUFFIX
|
||||
}`;
|
||||
export const MODIFY_PERMISSION_FAILURE = `${MODIFY_PERMISSION}_${
|
||||
types.FAILURE_SUFFIX
|
||||
}`;
|
||||
export const MODIFY_PERMISSION_RESET = `${MODIFY_PERMISSION}_${
|
||||
types.RESET_SUFFIX
|
||||
}`;
|
||||
export const CREATE_PERMISSION = "scm/permissions/CREATE_PERMISSION";
|
||||
export const CREATE_PERMISSION_PENDING = `${CREATE_PERMISSION}_${
|
||||
types.PENDING_SUFFIX
|
||||
}`;
|
||||
export const CREATE_PERMISSION_SUCCESS = `${CREATE_PERMISSION}_${
|
||||
types.SUCCESS_SUFFIX
|
||||
}`;
|
||||
export const CREATE_PERMISSION_FAILURE = `${CREATE_PERMISSION}_${
|
||||
types.FAILURE_SUFFIX
|
||||
}`;
|
||||
export const CREATE_PERMISSION_RESET = `${CREATE_PERMISSION}_${
|
||||
types.RESET_SUFFIX
|
||||
}`;
|
||||
export const DELETE_PERMISSION = "scm/permissions/DELETE_PERMISSION";
|
||||
export const DELETE_PERMISSION_PENDING = `${DELETE_PERMISSION}_${
|
||||
types.PENDING_SUFFIX
|
||||
}`;
|
||||
export const DELETE_PERMISSION_SUCCESS = `${DELETE_PERMISSION}_${
|
||||
types.SUCCESS_SUFFIX
|
||||
}`;
|
||||
export const DELETE_PERMISSION_FAILURE = `${DELETE_PERMISSION}_${
|
||||
types.FAILURE_SUFFIX
|
||||
}`;
|
||||
export const DELETE_PERMISSION_RESET = `${DELETE_PERMISSION}_${
|
||||
types.RESET_SUFFIX
|
||||
}`;
|
||||
export const FETCH_AVAILABLE = 'scm/permissions/FETCH_AVAILABLE';
|
||||
export const FETCH_AVAILABLE_PENDING = `${FETCH_AVAILABLE}_${types.PENDING_SUFFIX}`;
|
||||
export const FETCH_AVAILABLE_SUCCESS = `${FETCH_AVAILABLE}_${types.SUCCESS_SUFFIX}`;
|
||||
export const FETCH_AVAILABLE_FAILURE = `${FETCH_AVAILABLE}_${types.FAILURE_SUFFIX}`;
|
||||
export const FETCH_PERMISSIONS = 'scm/permissions/FETCH_PERMISSIONS';
|
||||
export const FETCH_PERMISSIONS_PENDING = `${FETCH_PERMISSIONS}_${types.PENDING_SUFFIX}`;
|
||||
export const FETCH_PERMISSIONS_SUCCESS = `${FETCH_PERMISSIONS}_${types.SUCCESS_SUFFIX}`;
|
||||
export const FETCH_PERMISSIONS_FAILURE = `${FETCH_PERMISSIONS}_${types.FAILURE_SUFFIX}`;
|
||||
export const MODIFY_PERMISSION = 'scm/permissions/MODFIY_PERMISSION';
|
||||
export const MODIFY_PERMISSION_PENDING = `${MODIFY_PERMISSION}_${types.PENDING_SUFFIX}`;
|
||||
export const MODIFY_PERMISSION_SUCCESS = `${MODIFY_PERMISSION}_${types.SUCCESS_SUFFIX}`;
|
||||
export const MODIFY_PERMISSION_FAILURE = `${MODIFY_PERMISSION}_${types.FAILURE_SUFFIX}`;
|
||||
export const MODIFY_PERMISSION_RESET = `${MODIFY_PERMISSION}_${types.RESET_SUFFIX}`;
|
||||
export const CREATE_PERMISSION = 'scm/permissions/CREATE_PERMISSION';
|
||||
export const CREATE_PERMISSION_PENDING = `${CREATE_PERMISSION}_${types.PENDING_SUFFIX}`;
|
||||
export const CREATE_PERMISSION_SUCCESS = `${CREATE_PERMISSION}_${types.SUCCESS_SUFFIX}`;
|
||||
export const CREATE_PERMISSION_FAILURE = `${CREATE_PERMISSION}_${types.FAILURE_SUFFIX}`;
|
||||
export const CREATE_PERMISSION_RESET = `${CREATE_PERMISSION}_${types.RESET_SUFFIX}`;
|
||||
export const DELETE_PERMISSION = 'scm/permissions/DELETE_PERMISSION';
|
||||
export const DELETE_PERMISSION_PENDING = `${DELETE_PERMISSION}_${types.PENDING_SUFFIX}`;
|
||||
export const DELETE_PERMISSION_SUCCESS = `${DELETE_PERMISSION}_${types.SUCCESS_SUFFIX}`;
|
||||
export const DELETE_PERMISSION_FAILURE = `${DELETE_PERMISSION}_${types.FAILURE_SUFFIX}`;
|
||||
export const DELETE_PERMISSION_RESET = `${DELETE_PERMISSION}_${types.RESET_SUFFIX}`;
|
||||
|
||||
const CONTENT_TYPE = "application/vnd.scmm-repositoryPermission+json";
|
||||
const CONTENT_TYPE = 'application/vnd.scmm-repositoryPermission+json';
|
||||
|
||||
// fetch available permissions
|
||||
|
||||
export function fetchAvailablePermissionsIfNeeded(
|
||||
repositoryRolesLink: string,
|
||||
repositoryVerbsLink: string
|
||||
repositoryVerbsLink: string,
|
||||
) {
|
||||
return function(dispatch: any, getState: () => Object) {
|
||||
return function(dispatch: any, getState: () => object) {
|
||||
if (shouldFetchAvailablePermissions(getState())) {
|
||||
return fetchAvailablePermissions(
|
||||
dispatch,
|
||||
getState,
|
||||
repositoryRolesLink,
|
||||
repositoryVerbsLink
|
||||
repositoryVerbsLink,
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -95,9 +57,9 @@ export function fetchAvailablePermissionsIfNeeded(
|
||||
|
||||
export function fetchAvailablePermissions(
|
||||
dispatch: any,
|
||||
getState: () => Object,
|
||||
getState: () => object,
|
||||
repositoryRolesLink: string,
|
||||
repositoryVerbsLink: string
|
||||
repositoryVerbsLink: string,
|
||||
) {
|
||||
dispatch(fetchAvailablePending());
|
||||
return apiClient
|
||||
@@ -112,7 +74,7 @@ export function fetchAvailablePermissions(
|
||||
.then(repositoryVerbs => {
|
||||
return {
|
||||
repositoryVerbs,
|
||||
repositoryRoles
|
||||
repositoryRoles,
|
||||
};
|
||||
});
|
||||
})
|
||||
@@ -124,7 +86,7 @@ export function fetchAvailablePermissions(
|
||||
});
|
||||
}
|
||||
|
||||
export function shouldFetchAvailablePermissions(state: Object) {
|
||||
export function shouldFetchAvailablePermissions(state: object) {
|
||||
if (
|
||||
isFetchAvailablePermissionsPending(state) ||
|
||||
getFetchAvailablePermissionsFailure(state)
|
||||
@@ -138,17 +100,17 @@ export function fetchAvailablePending(): Action {
|
||||
return {
|
||||
type: FETCH_AVAILABLE_PENDING,
|
||||
payload: {},
|
||||
itemId: "available"
|
||||
itemId: 'available',
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchAvailableSuccess(
|
||||
available: [RepositoryRole[], string[]]
|
||||
available: [RepositoryRole[], string[]],
|
||||
): Action {
|
||||
return {
|
||||
type: FETCH_AVAILABLE_SUCCESS,
|
||||
payload: available,
|
||||
itemId: "available"
|
||||
itemId: 'available',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -156,9 +118,9 @@ export function fetchAvailableFailure(error: Error): Action {
|
||||
return {
|
||||
type: FETCH_AVAILABLE_FAILURE,
|
||||
payload: {
|
||||
error
|
||||
error,
|
||||
},
|
||||
itemId: "available"
|
||||
itemId: 'available',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -167,7 +129,7 @@ export function fetchAvailableFailure(error: Error): Action {
|
||||
export function fetchPermissions(
|
||||
link: string,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
) {
|
||||
return function(dispatch: any) {
|
||||
dispatch(fetchPermissionsPending(namespace, repoName));
|
||||
@@ -185,43 +147,43 @@ export function fetchPermissions(
|
||||
|
||||
export function fetchPermissionsPending(
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
): Action {
|
||||
return {
|
||||
type: FETCH_PERMISSIONS_PENDING,
|
||||
payload: {
|
||||
namespace,
|
||||
repoName
|
||||
repoName,
|
||||
},
|
||||
itemId: namespace + "/" + repoName
|
||||
itemId: namespace + '/' + repoName,
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchPermissionsSuccess(
|
||||
permissions: any,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
): Action {
|
||||
return {
|
||||
type: FETCH_PERMISSIONS_SUCCESS,
|
||||
payload: permissions,
|
||||
itemId: namespace + "/" + repoName
|
||||
itemId: namespace + '/' + repoName,
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchPermissionsFailure(
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
error: Error
|
||||
error: Error,
|
||||
): Action {
|
||||
return {
|
||||
type: FETCH_PERMISSIONS_FAILURE,
|
||||
payload: {
|
||||
namespace,
|
||||
repoName,
|
||||
error
|
||||
error,
|
||||
},
|
||||
itemId: namespace + "/" + repoName
|
||||
itemId: namespace + '/' + repoName,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -231,7 +193,7 @@ export function modifyPermission(
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
callback?: () => void
|
||||
callback?: () => void,
|
||||
) {
|
||||
return function(dispatch: any) {
|
||||
dispatch(modifyPermissionPending(permission, namespace, repoName));
|
||||
@@ -252,27 +214,27 @@ export function modifyPermission(
|
||||
export function modifyPermissionPending(
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
): Action {
|
||||
return {
|
||||
type: MODIFY_PERMISSION_PENDING,
|
||||
payload: permission,
|
||||
itemId: createItemId(permission, namespace, repoName)
|
||||
itemId: createItemId(permission, namespace, repoName),
|
||||
};
|
||||
}
|
||||
|
||||
export function modifyPermissionSuccess(
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
): Action {
|
||||
return {
|
||||
type: MODIFY_PERMISSION_SUCCESS,
|
||||
payload: {
|
||||
permission,
|
||||
position: namespace + "/" + repoName
|
||||
position: namespace + '/' + repoName,
|
||||
},
|
||||
itemId: createItemId(permission, namespace, repoName)
|
||||
itemId: createItemId(permission, namespace, repoName),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -280,18 +242,21 @@ export function modifyPermissionFailure(
|
||||
permission: Permission,
|
||||
error: Error,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
): Action {
|
||||
return {
|
||||
type: MODIFY_PERMISSION_FAILURE,
|
||||
payload: { error, permission },
|
||||
itemId: createItemId(permission, namespace, repoName)
|
||||
payload: {
|
||||
error,
|
||||
permission,
|
||||
},
|
||||
itemId: createItemId(permission, namespace, repoName),
|
||||
};
|
||||
}
|
||||
|
||||
function newPermissions(
|
||||
oldPermissions: PermissionCollection,
|
||||
newPermission: Permission
|
||||
newPermission: Permission,
|
||||
) {
|
||||
for (let i = 0; i < oldPermissions.length; i++) {
|
||||
if (oldPermissions[i].name === newPermission.name) {
|
||||
@@ -306,9 +271,9 @@ export function modifyPermissionReset(namespace: string, repoName: string) {
|
||||
type: MODIFY_PERMISSION_RESET,
|
||||
payload: {
|
||||
namespace,
|
||||
repoName
|
||||
repoName,
|
||||
},
|
||||
itemId: namespace + "/" + repoName
|
||||
itemId: namespace + '/' + repoName,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -318,27 +283,27 @@ export function createPermission(
|
||||
permission: PermissionCreateEntry,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
callback?: () => void
|
||||
callback?: () => void,
|
||||
) {
|
||||
return function(dispatch: Dispatch) {
|
||||
dispatch(createPermissionPending(permission, namespace, repoName));
|
||||
return apiClient
|
||||
.post(link, permission, CONTENT_TYPE)
|
||||
.then(response => {
|
||||
const location = response.headers.get("Location");
|
||||
const location = response.headers.get('Location');
|
||||
return apiClient.get(location);
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(createdPermission => {
|
||||
dispatch(
|
||||
createPermissionSuccess(createdPermission, namespace, repoName)
|
||||
createPermissionSuccess(createdPermission, namespace, repoName),
|
||||
);
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
})
|
||||
.catch(err =>
|
||||
dispatch(createPermissionFailure(err, namespace, repoName))
|
||||
dispatch(createPermissionFailure(err, namespace, repoName)),
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -346,46 +311,46 @@ export function createPermission(
|
||||
export function createPermissionPending(
|
||||
permission: PermissionCreateEntry,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
): Action {
|
||||
return {
|
||||
type: CREATE_PERMISSION_PENDING,
|
||||
payload: permission,
|
||||
itemId: namespace + "/" + repoName
|
||||
itemId: namespace + '/' + repoName,
|
||||
};
|
||||
}
|
||||
|
||||
export function createPermissionSuccess(
|
||||
permission: PermissionCreateEntry,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
): Action {
|
||||
return {
|
||||
type: CREATE_PERMISSION_SUCCESS,
|
||||
payload: {
|
||||
permission,
|
||||
position: namespace + "/" + repoName
|
||||
position: namespace + '/' + repoName,
|
||||
},
|
||||
itemId: namespace + "/" + repoName
|
||||
itemId: namespace + '/' + repoName,
|
||||
};
|
||||
}
|
||||
|
||||
export function createPermissionFailure(
|
||||
error: Error,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
): Action {
|
||||
return {
|
||||
type: CREATE_PERMISSION_FAILURE,
|
||||
payload: error,
|
||||
itemId: namespace + "/" + repoName
|
||||
itemId: namespace + '/' + repoName,
|
||||
};
|
||||
}
|
||||
|
||||
export function createPermissionReset(namespace: string, repoName: string) {
|
||||
return {
|
||||
type: CREATE_PERMISSION_RESET,
|
||||
itemId: namespace + "/" + repoName
|
||||
itemId: namespace + '/' + repoName,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -395,7 +360,7 @@ export function deletePermission(
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
callback?: () => void
|
||||
callback?: () => void,
|
||||
) {
|
||||
return function(dispatch: any) {
|
||||
dispatch(deletePermissionPending(permission, namespace, repoName));
|
||||
@@ -416,27 +381,27 @@ export function deletePermission(
|
||||
export function deletePermissionPending(
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
): Action {
|
||||
return {
|
||||
type: DELETE_PERMISSION_PENDING,
|
||||
payload: permission,
|
||||
itemId: createItemId(permission, namespace, repoName)
|
||||
itemId: createItemId(permission, namespace, repoName),
|
||||
};
|
||||
}
|
||||
|
||||
export function deletePermissionSuccess(
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
): Action {
|
||||
return {
|
||||
type: DELETE_PERMISSION_SUCCESS,
|
||||
payload: {
|
||||
permission,
|
||||
position: namespace + "/" + repoName
|
||||
position: namespace + '/' + repoName,
|
||||
},
|
||||
itemId: createItemId(permission, namespace, repoName)
|
||||
itemId: createItemId(permission, namespace, repoName),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -444,15 +409,15 @@ export function deletePermissionFailure(
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
error: Error
|
||||
error: Error,
|
||||
): Action {
|
||||
return {
|
||||
type: DELETE_PERMISSION_FAILURE,
|
||||
payload: {
|
||||
error,
|
||||
permission
|
||||
permission,
|
||||
},
|
||||
itemId: createItemId(permission, namespace, repoName)
|
||||
itemId: createItemId(permission, namespace, repoName),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -461,15 +426,15 @@ export function deletePermissionReset(namespace: string, repoName: string) {
|
||||
type: DELETE_PERMISSION_RESET,
|
||||
payload: {
|
||||
namespace,
|
||||
repoName
|
||||
repoName,
|
||||
},
|
||||
itemId: namespace + "/" + repoName
|
||||
itemId: namespace + '/' + repoName,
|
||||
};
|
||||
}
|
||||
|
||||
function deletePermissionFromState(
|
||||
oldPermissions: PermissionCollection,
|
||||
permission: Permission
|
||||
permission: Permission,
|
||||
) {
|
||||
let newPermission = [];
|
||||
for (let i = 0; i < oldPermissions.length; i++) {
|
||||
@@ -486,17 +451,19 @@ function deletePermissionFromState(
|
||||
function createItemId(
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
) {
|
||||
let groupPermission = permission.groupPermission ? "@" : "";
|
||||
return namespace + "/" + repoName + "/" + groupPermission + permission.name;
|
||||
let groupPermission = permission.groupPermission ? '@' : '';
|
||||
return namespace + '/' + repoName + '/' + groupPermission + permission.name;
|
||||
}
|
||||
|
||||
// reducer
|
||||
export default function reducer(
|
||||
state: Object = {},
|
||||
action: Action = { type: "UNKNOWN" }
|
||||
): Object {
|
||||
state: object = {},
|
||||
action: Action = {
|
||||
type: 'UNKNOWN',
|
||||
},
|
||||
): object {
|
||||
if (!action.payload) {
|
||||
return state;
|
||||
}
|
||||
@@ -504,28 +471,28 @@ export default function reducer(
|
||||
case FETCH_AVAILABLE_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
available: action.payload
|
||||
available: action.payload,
|
||||
};
|
||||
case FETCH_PERMISSIONS_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
[action.itemId]: {
|
||||
entries: action.payload._embedded.permissions,
|
||||
createPermission: !!action.payload._links.create
|
||||
}
|
||||
createPermission: !!action.payload._links.create,
|
||||
},
|
||||
};
|
||||
case MODIFY_PERMISSION_SUCCESS:
|
||||
const positionOfPermission = action.payload.position;
|
||||
const newPermission = newPermissions(
|
||||
state[action.payload.position].entries,
|
||||
action.payload.permission
|
||||
action.payload.permission,
|
||||
);
|
||||
return {
|
||||
...state,
|
||||
[positionOfPermission]: {
|
||||
...state[positionOfPermission],
|
||||
entries: newPermission
|
||||
}
|
||||
entries: newPermission,
|
||||
},
|
||||
};
|
||||
case CREATE_PERMISSION_SUCCESS:
|
||||
// return state;
|
||||
@@ -536,21 +503,21 @@ export default function reducer(
|
||||
...state,
|
||||
[position]: {
|
||||
...state[position],
|
||||
entries: permissions
|
||||
}
|
||||
entries: permissions,
|
||||
},
|
||||
};
|
||||
case DELETE_PERMISSION_SUCCESS:
|
||||
const permissionPosition = action.payload.position;
|
||||
const new_Permissions = deletePermissionFromState(
|
||||
state[action.payload.position].entries,
|
||||
action.payload.permission
|
||||
action.payload.permission,
|
||||
);
|
||||
return {
|
||||
...state,
|
||||
[permissionPosition]: {
|
||||
...state[permissionPosition],
|
||||
entries: new_Permissions
|
||||
}
|
||||
entries: new_Permissions,
|
||||
},
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
@@ -559,21 +526,21 @@ export default function reducer(
|
||||
|
||||
// selectors
|
||||
|
||||
export function getAvailablePermissions(state: Object) {
|
||||
export function getAvailablePermissions(state: object) {
|
||||
if (state.permissions) {
|
||||
return state.permissions.available;
|
||||
}
|
||||
}
|
||||
|
||||
export function getAvailableRepositoryRoles(state: Object) {
|
||||
export function getAvailableRepositoryRoles(state: object) {
|
||||
return available(state).repositoryRoles;
|
||||
}
|
||||
|
||||
export function getAvailableRepositoryVerbs(state: Object) {
|
||||
export function getAvailableRepositoryVerbs(state: object) {
|
||||
return available(state).repositoryVerbs;
|
||||
}
|
||||
|
||||
function available(state: Object) {
|
||||
function available(state: object) {
|
||||
if (state.permissions && state.permissions.available) {
|
||||
return state.permissions.available;
|
||||
}
|
||||
@@ -581,125 +548,125 @@ function available(state: Object) {
|
||||
}
|
||||
|
||||
export function getPermissionsOfRepo(
|
||||
state: Object,
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
) {
|
||||
if (state.permissions && state.permissions[namespace + "/" + repoName]) {
|
||||
return state.permissions[namespace + "/" + repoName].entries;
|
||||
if (state.permissions && state.permissions[namespace + '/' + repoName]) {
|
||||
return state.permissions[namespace + '/' + repoName].entries;
|
||||
}
|
||||
}
|
||||
|
||||
export function isFetchAvailablePermissionsPending(state: Object) {
|
||||
return isPending(state, FETCH_AVAILABLE, "available");
|
||||
export function isFetchAvailablePermissionsPending(state: object) {
|
||||
return isPending(state, FETCH_AVAILABLE, 'available');
|
||||
}
|
||||
|
||||
export function isFetchPermissionsPending(
|
||||
state: Object,
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
) {
|
||||
return isPending(state, FETCH_PERMISSIONS, namespace + "/" + repoName);
|
||||
return isPending(state, FETCH_PERMISSIONS, namespace + '/' + repoName);
|
||||
}
|
||||
|
||||
export function getFetchAvailablePermissionsFailure(state: Object) {
|
||||
return getFailure(state, FETCH_AVAILABLE, "available");
|
||||
export function getFetchAvailablePermissionsFailure(state: object) {
|
||||
return getFailure(state, FETCH_AVAILABLE, 'available');
|
||||
}
|
||||
|
||||
export function getFetchPermissionsFailure(
|
||||
state: Object,
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
) {
|
||||
return getFailure(state, FETCH_PERMISSIONS, namespace + "/" + repoName);
|
||||
return getFailure(state, FETCH_PERMISSIONS, namespace + '/' + repoName);
|
||||
}
|
||||
|
||||
export function isModifyPermissionPending(
|
||||
state: Object,
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
permission: Permission
|
||||
permission: Permission,
|
||||
) {
|
||||
return isPending(
|
||||
state,
|
||||
MODIFY_PERMISSION,
|
||||
createItemId(permission, namespace, repoName)
|
||||
createItemId(permission, namespace, repoName),
|
||||
);
|
||||
}
|
||||
|
||||
export function getModifyPermissionFailure(
|
||||
state: Object,
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
permission: Permission
|
||||
permission: Permission,
|
||||
) {
|
||||
return getFailure(
|
||||
state,
|
||||
MODIFY_PERMISSION,
|
||||
createItemId(permission, namespace, repoName)
|
||||
createItemId(permission, namespace, repoName),
|
||||
);
|
||||
}
|
||||
|
||||
export function hasCreatePermission(
|
||||
state: Object,
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
) {
|
||||
if (state.permissions && state.permissions[namespace + "/" + repoName])
|
||||
return state.permissions[namespace + "/" + repoName].createPermission;
|
||||
if (state.permissions && state.permissions[namespace + '/' + repoName])
|
||||
return state.permissions[namespace + '/' + repoName].createPermission;
|
||||
else return null;
|
||||
}
|
||||
|
||||
export function isCreatePermissionPending(
|
||||
state: Object,
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
) {
|
||||
return isPending(state, CREATE_PERMISSION, namespace + "/" + repoName);
|
||||
return isPending(state, CREATE_PERMISSION, namespace + '/' + repoName);
|
||||
}
|
||||
|
||||
export function getCreatePermissionFailure(
|
||||
state: Object,
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
) {
|
||||
return getFailure(state, CREATE_PERMISSION, namespace + "/" + repoName);
|
||||
return getFailure(state, CREATE_PERMISSION, namespace + '/' + repoName);
|
||||
}
|
||||
|
||||
export function isDeletePermissionPending(
|
||||
state: Object,
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
permission: Permission
|
||||
permission: Permission,
|
||||
) {
|
||||
return isPending(
|
||||
state,
|
||||
DELETE_PERMISSION,
|
||||
createItemId(permission, namespace, repoName)
|
||||
createItemId(permission, namespace, repoName),
|
||||
);
|
||||
}
|
||||
|
||||
export function getDeletePermissionFailure(
|
||||
state: Object,
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
permission: Permission
|
||||
permission: Permission,
|
||||
) {
|
||||
return getFailure(
|
||||
state,
|
||||
DELETE_PERMISSION,
|
||||
createItemId(permission, namespace, repoName)
|
||||
createItemId(permission, namespace, repoName),
|
||||
);
|
||||
}
|
||||
|
||||
export function getDeletePermissionsFailure(
|
||||
state: Object,
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
) {
|
||||
const permissions =
|
||||
state.permissions && state.permissions[namespace + "/" + repoName]
|
||||
? state.permissions[namespace + "/" + repoName].entries
|
||||
state.permissions && state.permissions[namespace + '/' + repoName]
|
||||
? state.permissions[namespace + '/' + repoName].entries
|
||||
: null;
|
||||
if (permissions == null) return undefined;
|
||||
for (let i = 0; i < permissions.length; i++) {
|
||||
@@ -709,7 +676,7 @@ export function getDeletePermissionsFailure(
|
||||
return getFailure(
|
||||
state,
|
||||
DELETE_PERMISSION,
|
||||
createItemId(permissions[i], namespace, repoName)
|
||||
createItemId(permissions[i], namespace, repoName),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -717,13 +684,13 @@ export function getDeletePermissionsFailure(
|
||||
}
|
||||
|
||||
export function getModifyPermissionsFailure(
|
||||
state: Object,
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
repoName: string,
|
||||
) {
|
||||
const permissions =
|
||||
state.permissions && state.permissions[namespace + "/" + repoName]
|
||||
? state.permissions[namespace + "/" + repoName].entries
|
||||
state.permissions && state.permissions[namespace + '/' + repoName]
|
||||
? state.permissions[namespace + '/' + repoName].entries
|
||||
: null;
|
||||
if (permissions == null) return undefined;
|
||||
for (let i = 0; i < permissions.length; i++) {
|
||||
@@ -733,7 +700,7 @@ export function getModifyPermissionsFailure(
|
||||
return getFailure(
|
||||
state,
|
||||
MODIFY_PERMISSION,
|
||||
createItemId(permissions[i], namespace, repoName)
|
||||
createItemId(permissions[i], namespace, repoName),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -742,10 +709,10 @@ export function getModifyPermissionsFailure(
|
||||
|
||||
export function findVerbsForRole(
|
||||
availableRepositoryRoles: RepositoryRole[],
|
||||
roleName: string
|
||||
roleName: string,
|
||||
) {
|
||||
const matchingRole = availableRepositoryRoles.find(
|
||||
role => roleName === role.name
|
||||
role => roleName === role.name,
|
||||
);
|
||||
if (matchingRole) {
|
||||
return matchingRole.verbs;
|
||||
Reference in New Issue
Block a user