mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
apply eslint and prettier rules
This commit is contained in:
@@ -14,20 +14,11 @@ type Props = {
|
||||
|
||||
class RoleSelector extends React.Component<Props> {
|
||||
render() {
|
||||
const {
|
||||
availableRoles,
|
||||
role,
|
||||
handleRoleChange,
|
||||
loading,
|
||||
label,
|
||||
helpText
|
||||
} = this.props;
|
||||
const { availableRoles, role, handleRoleChange, loading, label, helpText } = this.props;
|
||||
|
||||
if (!availableRoles) return null;
|
||||
|
||||
const options = role
|
||||
? this.createSelectOptions(availableRoles)
|
||||
: ["", ...this.createSelectOptions(availableRoles)];
|
||||
const options = role ? this.createSelectOptions(availableRoles) : ["", ...this.createSelectOptions(availableRoles)];
|
||||
|
||||
return (
|
||||
<Select
|
||||
|
||||
@@ -16,12 +16,7 @@ describe("DeletePermissionButton", () => {
|
||||
_links: {}
|
||||
};
|
||||
|
||||
const navLink = shallow(
|
||||
<DeletePermissionButton
|
||||
permission={permission}
|
||||
deletePermission={() => {}}
|
||||
/>
|
||||
);
|
||||
const navLink = shallow(<DeletePermissionButton permission={permission} deletePermission={() => {}} />);
|
||||
expect(navLink.text()).toBe("");
|
||||
});
|
||||
|
||||
@@ -34,12 +29,7 @@ describe("DeletePermissionButton", () => {
|
||||
}
|
||||
};
|
||||
|
||||
const deleteIcon = mount(
|
||||
<DeletePermissionButton
|
||||
permission={permission}
|
||||
deletePermission={() => {}}
|
||||
/>
|
||||
);
|
||||
const deleteIcon = mount(<DeletePermissionButton permission={permission} deletePermission={() => {}} />);
|
||||
expect(deleteIcon.html()).not.toBe("");
|
||||
});
|
||||
|
||||
@@ -52,12 +42,7 @@ describe("DeletePermissionButton", () => {
|
||||
}
|
||||
};
|
||||
|
||||
const button = mount(
|
||||
<DeletePermissionButton
|
||||
permission={permission}
|
||||
deletePermission={() => {}}
|
||||
/>
|
||||
);
|
||||
const button = mount(<DeletePermissionButton permission={permission} deletePermission={() => {}} />);
|
||||
button.find(".fa-trash").simulate("click");
|
||||
|
||||
expect(confirmAlert.mock.calls.length).toBe(1);
|
||||
@@ -78,11 +63,7 @@ describe("DeletePermissionButton", () => {
|
||||
}
|
||||
|
||||
const button = mount(
|
||||
<DeletePermissionButton
|
||||
permission={permission}
|
||||
confirmDialog={false}
|
||||
deletePermission={capture}
|
||||
/>
|
||||
<DeletePermissionButton permission={permission} confirmDialog={false} deletePermission={capture} />
|
||||
);
|
||||
button.find(".fa-trash").simulate("click");
|
||||
|
||||
|
||||
@@ -9,11 +9,7 @@ type Props = {
|
||||
repoName: string;
|
||||
confirmDialog?: boolean;
|
||||
t: (p: string) => string;
|
||||
deletePermission: (
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
) => void;
|
||||
deletePermission: (permission: Permission, namespace: string, repoName: string) => void;
|
||||
loading: boolean;
|
||||
};
|
||||
|
||||
@@ -23,11 +19,7 @@ class DeletePermissionButton extends React.Component<Props> {
|
||||
};
|
||||
|
||||
deletePermission = () => {
|
||||
this.props.deletePermission(
|
||||
this.props.permission,
|
||||
this.props.namespace,
|
||||
this.props.repoName
|
||||
);
|
||||
this.props.deletePermission(this.props.permission, this.props.namespace, this.props.repoName);
|
||||
};
|
||||
|
||||
confirmDelete = () => {
|
||||
|
||||
@@ -6,9 +6,7 @@ describe("permission validation", () => {
|
||||
const name = "PermissionName";
|
||||
const groupPermission = false;
|
||||
|
||||
expect(
|
||||
validator.isPermissionValid(name, groupPermission, permissions)
|
||||
).toBe(true);
|
||||
expect(validator.isPermissionValid(name, groupPermission, permissions)).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true if permission is valid and does not exists with same group permission", () => {
|
||||
@@ -24,9 +22,7 @@ describe("permission validation", () => {
|
||||
const name = "PermissionName";
|
||||
const groupPermission = false;
|
||||
|
||||
expect(
|
||||
validator.isPermissionValid(name, groupPermission, permissions)
|
||||
).toBe(true);
|
||||
expect(validator.isPermissionValid(name, groupPermission, permissions)).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false if permission is valid but exists", () => {
|
||||
@@ -42,9 +38,7 @@ describe("permission validation", () => {
|
||||
const name = "PermissionName";
|
||||
const groupPermission = false;
|
||||
|
||||
expect(
|
||||
validator.isPermissionValid(name, groupPermission, permissions)
|
||||
).toBe(false);
|
||||
expect(validator.isPermissionValid(name, groupPermission, permissions)).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false if permission does not exist but is invalid", () => {
|
||||
@@ -52,9 +46,7 @@ describe("permission validation", () => {
|
||||
const name = "@PermissionName";
|
||||
const groupPermission = false;
|
||||
|
||||
expect(
|
||||
validator.isPermissionValid(name, groupPermission, permissions)
|
||||
).toBe(false);
|
||||
expect(validator.isPermissionValid(name, groupPermission, permissions)).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false if permission is not valid and does not exist", () => {
|
||||
@@ -62,8 +54,6 @@ describe("permission validation", () => {
|
||||
const name = "@PermissionName";
|
||||
const groupPermission = false;
|
||||
|
||||
expect(
|
||||
validator.isPermissionValid(name, groupPermission, permissions)
|
||||
).toBe(false);
|
||||
expect(validator.isPermissionValid(name, groupPermission, permissions)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,28 +5,13 @@ const isNameValid = validation.isNameValid;
|
||||
|
||||
export { isNameValid };
|
||||
|
||||
export const isPermissionValid = (
|
||||
name: string,
|
||||
groupPermission: boolean,
|
||||
permissions: PermissionCollection
|
||||
) => {
|
||||
return (
|
||||
isNameValid(name) &&
|
||||
!currentPermissionIncludeName(name, groupPermission, permissions)
|
||||
);
|
||||
export const isPermissionValid = (name: string, groupPermission: boolean, permissions: PermissionCollection) => {
|
||||
return isNameValid(name) && !currentPermissionIncludeName(name, groupPermission, permissions);
|
||||
};
|
||||
|
||||
const currentPermissionIncludeName = (
|
||||
name: string,
|
||||
groupPermission: boolean,
|
||||
permissions: PermissionCollection
|
||||
) => {
|
||||
const currentPermissionIncludeName = (name: string, groupPermission: boolean, permissions: PermissionCollection) => {
|
||||
for (let i = 0; i < permissions.length; i++) {
|
||||
if (
|
||||
permissions[i].name === name &&
|
||||
permissions[i].groupPermission === groupPermission
|
||||
)
|
||||
return true;
|
||||
if (permissions[i].name === name && permissions[i].groupPermission === groupPermission) return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
import React from "react";
|
||||
import {
|
||||
ButtonGroup,
|
||||
Button,
|
||||
SubmitButton,
|
||||
Modal
|
||||
} from "@scm-manager/ui-components";
|
||||
import { ButtonGroup, Button, SubmitButton, Modal } from "@scm-manager/ui-components";
|
||||
import { translate } from "react-i18next";
|
||||
import PermissionCheckbox from "../components/PermissionCheckbox";
|
||||
|
||||
@@ -29,10 +24,7 @@ class AdvancedPermissionsDialog extends React.Component<Props, State> {
|
||||
|
||||
const verbs = {};
|
||||
props.availableVerbs.forEach(
|
||||
verb =>
|
||||
(verbs[verb] = props.selectedVerbs
|
||||
? props.selectedVerbs.includes(verb)
|
||||
: false)
|
||||
verb => (verbs[verb] = props.selectedVerbs ? props.selectedVerbs.includes(verb) : false)
|
||||
);
|
||||
this.state = {
|
||||
verbs
|
||||
@@ -44,18 +36,10 @@ class AdvancedPermissionsDialog extends React.Component<Props, State> {
|
||||
const { verbs } = this.state;
|
||||
|
||||
const verbSelectBoxes = Object.entries(verbs).map(e => (
|
||||
<PermissionCheckbox
|
||||
key={e[0]}
|
||||
disabled={readOnly}
|
||||
name={e[0]}
|
||||
checked={e[1]}
|
||||
onChange={this.handleChange}
|
||||
/>
|
||||
<PermissionCheckbox key={e[0]} disabled={readOnly} name={e[0]} checked={e[1]} onChange={this.handleChange} />
|
||||
));
|
||||
|
||||
const submitButton = !readOnly ? (
|
||||
<SubmitButton label={t("permission.advanced.dialog.submit")} />
|
||||
) : null;
|
||||
const submitButton = !readOnly ? <SubmitButton label={t("permission.advanced.dialog.submit")} /> : null;
|
||||
|
||||
const body = <>{verbSelectBoxes}</>;
|
||||
|
||||
@@ -63,10 +47,7 @@ class AdvancedPermissionsDialog extends React.Component<Props, State> {
|
||||
<form onSubmit={this.onSubmit}>
|
||||
<ButtonGroup>
|
||||
{submitButton}
|
||||
<Button
|
||||
label={t("permission.advanced.dialog.abort")}
|
||||
action={onClose}
|
||||
/>
|
||||
<Button label={t("permission.advanced.dialog.abort")} action={onClose} />
|
||||
</ButtonGroup>
|
||||
</form>
|
||||
);
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import {
|
||||
PermissionCollection,
|
||||
PermissionCreateEntry,
|
||||
RepositoryRole,
|
||||
SelectValue
|
||||
} from "@scm-manager/ui-types";
|
||||
import { PermissionCollection, PermissionCreateEntry, RepositoryRole, SelectValue } from "@scm-manager/ui-types";
|
||||
import {
|
||||
Button,
|
||||
GroupAutocomplete,
|
||||
@@ -103,11 +98,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
this.setState({
|
||||
value,
|
||||
name: value.value.id,
|
||||
valid: validator.isPermissionValid(
|
||||
value.value.id,
|
||||
this.state.groupPermission,
|
||||
this.props.currentPermissions
|
||||
)
|
||||
valid: validator.isPermissionValid(value.value.id, this.state.groupPermission, this.props.currentPermissions)
|
||||
});
|
||||
};
|
||||
|
||||
@@ -131,9 +122,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
return (
|
||||
<>
|
||||
<hr />
|
||||
<Subtitle
|
||||
subtitle={t("permission.add-permission.add-permission-heading")}
|
||||
/>
|
||||
<Subtitle subtitle={t("permission.add-permission.add-permission-heading")} />
|
||||
{advancedDialog}
|
||||
<form onSubmit={this.submit}>
|
||||
<div className="field is-grouped">
|
||||
@@ -155,9 +144,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
</div>
|
||||
</div>
|
||||
<div className="columns">
|
||||
<div className="column is-three-fifths">
|
||||
{this.renderAutocompletionField()}
|
||||
</div>
|
||||
<div className="column is-three-fifths">{this.renderAutocompletionField()}</div>
|
||||
<div className="column is-two-fifths">
|
||||
<div className="columns">
|
||||
<div className="column is-narrow">
|
||||
@@ -174,10 +161,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
label={t("permission.permissions")}
|
||||
helpText={t("permission.help.permissionsHelpText")}
|
||||
/>
|
||||
<Button
|
||||
label={t("permission.advanced-button.label")}
|
||||
action={this.toggleAdvancedPermissionsDialog}
|
||||
/>
|
||||
<Button label={t("permission.advanced-button.label")} action={this.toggleAdvancedPermissionsDialog} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -22,18 +22,8 @@ import {
|
||||
isFetchPermissionsPending,
|
||||
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 { 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";
|
||||
@@ -63,10 +53,7 @@ type Props = {
|
||||
userAutocompleteLink: string;
|
||||
|
||||
//dispatch functions
|
||||
fetchAvailablePermissionsIfNeeded: (
|
||||
repositoryRolesLink: string,
|
||||
repositoryVerbsLink: string
|
||||
) => void;
|
||||
fetchAvailablePermissionsIfNeeded: (repositoryRolesLink: string, repositoryVerbsLink: string) => void;
|
||||
fetchPermissions: (link: string, namespace: string, repoName: string) => void;
|
||||
createPermission: (
|
||||
link: string,
|
||||
@@ -107,12 +94,7 @@ class Permissions extends React.Component<Props> {
|
||||
}
|
||||
|
||||
createPermission = (permission: Permission) => {
|
||||
this.props.createPermission(
|
||||
this.props.permissionsLink,
|
||||
permission,
|
||||
this.props.namespace,
|
||||
this.props.repoName
|
||||
);
|
||||
this.props.createPermission(this.props.permissionsLink, permission, this.props.namespace, this.props.repoName);
|
||||
};
|
||||
|
||||
render() {
|
||||
@@ -132,13 +114,7 @@ class Permissions extends React.Component<Props> {
|
||||
groupAutocompleteLink
|
||||
} = this.props;
|
||||
if (error) {
|
||||
return (
|
||||
<ErrorPage
|
||||
title={t("permission.error-title")}
|
||||
subtitle={t("permission.error-subtitle")}
|
||||
error={error}
|
||||
/>
|
||||
);
|
||||
return <ErrorPage title={t("permission.error-title")} subtitle={t("permission.error-subtitle")} error={error} />;
|
||||
}
|
||||
|
||||
if (loading || !permissions || !availablePermissions) {
|
||||
@@ -164,16 +140,10 @@ class Permissions extends React.Component<Props> {
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<LabelWithHelpIcon
|
||||
label={t("permission.name")}
|
||||
helpText={t("permission.help.nameHelpText")}
|
||||
/>
|
||||
<LabelWithHelpIcon label={t("permission.name")} helpText={t("permission.help.nameHelpText")} />
|
||||
</th>
|
||||
<th>
|
||||
<LabelWithHelpIcon
|
||||
label={t("permission.role")}
|
||||
helpText={t("permission.help.roleHelpText")}
|
||||
/>
|
||||
<LabelWithHelpIcon label={t("permission.role")} helpText={t("permission.help.roleHelpText")} />
|
||||
</th>
|
||||
<th>
|
||||
<LabelWithHelpIcon
|
||||
@@ -214,15 +184,9 @@ const mapStateToProps = (state, ownProps) => {
|
||||
getDeletePermissionsFailure(state, namespace, repoName) ||
|
||||
getModifyPermissionsFailure(state, namespace, repoName) ||
|
||||
getFetchAvailablePermissionsFailure(state);
|
||||
const loading =
|
||||
isFetchPermissionsPending(state, namespace, repoName) ||
|
||||
isFetchAvailablePermissionsPending(state);
|
||||
const loading = isFetchPermissionsPending(state, namespace, repoName) || isFetchAvailablePermissionsPending(state);
|
||||
const permissions = getPermissionsOfRepo(state, namespace, repoName);
|
||||
const loadingCreatePermission = isCreatePermissionPending(
|
||||
state,
|
||||
namespace,
|
||||
repoName
|
||||
);
|
||||
const loadingCreatePermission = isCreatePermissionPending(state, namespace, repoName);
|
||||
const hasPermissionToCreate = hasCreatePermission(state, namespace, repoName);
|
||||
const repositoryRolesLink = getRepositoryRolesLink(state);
|
||||
const repositoryVerbsLink = getRepositoryVerbsLink(state);
|
||||
@@ -257,16 +221,8 @@ const mapDispatchToProps = dispatch => {
|
||||
fetchPermissions: (link: string, namespace: string, repoName: string) => {
|
||||
dispatch(fetchPermissions(link, namespace, repoName));
|
||||
},
|
||||
fetchAvailablePermissionsIfNeeded: (
|
||||
repositoryRolesLink: string,
|
||||
repositoryVerbsLink: string
|
||||
) => {
|
||||
dispatch(
|
||||
fetchAvailablePermissionsIfNeeded(
|
||||
repositoryRolesLink,
|
||||
repositoryVerbsLink
|
||||
)
|
||||
);
|
||||
fetchAvailablePermissionsIfNeeded: (repositoryRolesLink: string, repositoryVerbsLink: string) => {
|
||||
dispatch(fetchAvailablePermissionsIfNeeded(repositoryRolesLink, repositoryVerbsLink));
|
||||
},
|
||||
createPermission: (
|
||||
link: string,
|
||||
@@ -275,9 +231,7 @@ const mapDispatchToProps = dispatch => {
|
||||
repoName: string,
|
||||
callback?: () => void
|
||||
) => {
|
||||
dispatch(
|
||||
createPermission(link, permission, namespace, repoName, callback)
|
||||
);
|
||||
dispatch(createPermission(link, permission, namespace, repoName, callback));
|
||||
},
|
||||
createPermissionReset: (namespace: string, repoName: string) => {
|
||||
dispatch(createPermissionReset(namespace, repoName));
|
||||
|
||||
@@ -20,11 +20,7 @@ type Props = {
|
||||
availableRepositoryRoles: RepositoryRole[];
|
||||
availableRepositoryVerbs: string[];
|
||||
submitForm: (p: Permission) => void;
|
||||
modifyPermission: (
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
name: string
|
||||
) => void;
|
||||
modifyPermission: (permission: Permission, namespace: string, name: string) => void;
|
||||
permission: Permission;
|
||||
t: (p: string) => string;
|
||||
namespace: string;
|
||||
@@ -32,11 +28,7 @@ type Props = {
|
||||
match: any;
|
||||
history: History;
|
||||
loading: boolean;
|
||||
deletePermission: (
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
name: string
|
||||
) => void;
|
||||
deletePermission: (permission: Permission, namespace: string, name: string) => void;
|
||||
deleteLoading: boolean;
|
||||
};
|
||||
|
||||
@@ -58,9 +50,7 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
|
||||
const defaultPermission = props.availableRepositoryRoles
|
||||
? props.availableRepositoryRoles[0]
|
||||
: {};
|
||||
const defaultPermission = props.availableRepositoryRoles ? props.availableRepositoryRoles[0] : {};
|
||||
|
||||
this.state = {
|
||||
permission: {
|
||||
@@ -91,25 +81,13 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
}
|
||||
|
||||
deletePermission = () => {
|
||||
this.props.deletePermission(
|
||||
this.props.permission,
|
||||
this.props.namespace,
|
||||
this.props.repoName
|
||||
);
|
||||
this.props.deletePermission(this.props.permission, this.props.namespace, this.props.repoName);
|
||||
};
|
||||
|
||||
render() {
|
||||
const {
|
||||
availableRepositoryRoles,
|
||||
availableRepositoryVerbs,
|
||||
loading,
|
||||
namespace,
|
||||
repoName,
|
||||
t
|
||||
} = this.props;
|
||||
const { availableRepositoryRoles, availableRepositoryVerbs, loading, namespace, repoName, t } = this.props;
|
||||
const { permission, showAdvancedDialog } = this.state;
|
||||
const availableRoleNames =
|
||||
!!availableRepositoryRoles && availableRepositoryRoles.map(r => r.name);
|
||||
const availableRoleNames = !!availableRepositoryRoles && availableRepositoryRoles.map(r => r.name);
|
||||
const readOnly = !this.mayChangePermissions();
|
||||
const roleSelector = readOnly ? (
|
||||
<td>{permission.role ? permission.role : t("permission.custom")}</td>
|
||||
@@ -152,10 +130,7 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
</VCenteredTd>
|
||||
{roleSelector}
|
||||
<VCenteredTd>
|
||||
<Button
|
||||
label={t("permission.advanced-button.label")}
|
||||
action={this.handleDetailedPermissionsPressed}
|
||||
/>
|
||||
<Button label={t("permission.advanced-button.label")} action={this.handleDetailedPermissionsPressed} />
|
||||
</VCenteredTd>
|
||||
<VCenteredTd className="is-darker">
|
||||
<DeletePermissionButton
|
||||
@@ -222,40 +197,22 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
};
|
||||
|
||||
modifyPermissionRole = (role: string) => {
|
||||
let permission = this.state.permission;
|
||||
const permission = this.state.permission;
|
||||
permission.role = role;
|
||||
this.props.modifyPermission(
|
||||
permission,
|
||||
this.props.namespace,
|
||||
this.props.repoName
|
||||
);
|
||||
this.props.modifyPermission(permission, this.props.namespace, this.props.repoName);
|
||||
};
|
||||
|
||||
modifyPermissionVerbs = (verbs: string[]) => {
|
||||
let permission = this.state.permission;
|
||||
const permission = this.state.permission;
|
||||
permission.verbs = verbs;
|
||||
this.props.modifyPermission(
|
||||
permission,
|
||||
this.props.namespace,
|
||||
this.props.repoName
|
||||
);
|
||||
this.props.modifyPermission(permission, this.props.namespace, this.props.repoName);
|
||||
};
|
||||
}
|
||||
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
const permission = ownProps.permission;
|
||||
const loading = isModifyPermissionPending(
|
||||
state,
|
||||
ownProps.namespace,
|
||||
ownProps.repoName,
|
||||
permission
|
||||
);
|
||||
const deleteLoading = isDeletePermissionPending(
|
||||
state,
|
||||
ownProps.namespace,
|
||||
ownProps.repoName,
|
||||
permission
|
||||
);
|
||||
const loading = isModifyPermissionPending(state, ownProps.namespace, ownProps.repoName, permission);
|
||||
const deleteLoading = isDeletePermissionPending(state, ownProps.namespace, ownProps.repoName, permission);
|
||||
|
||||
return {
|
||||
loading,
|
||||
@@ -265,18 +222,10 @@ const mapStateToProps = (state, ownProps) => {
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
modifyPermission: (
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
) => {
|
||||
modifyPermission: (permission: Permission, namespace: string, repoName: string) => {
|
||||
dispatch(modifyPermission(permission, namespace, repoName));
|
||||
},
|
||||
deletePermission: (
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
) => {
|
||||
deletePermission: (permission: Permission, namespace: string, repoName: string) => {
|
||||
dispatch(deletePermission(permission, namespace, repoName));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -47,16 +47,13 @@ const hitchhiker_puzzle42Permission_user_eins: Permission = {
|
||||
groupPermission: false,
|
||||
_links: {
|
||||
self: {
|
||||
href:
|
||||
"http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions/user_eins"
|
||||
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"
|
||||
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"
|
||||
href: "http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions/user_eins"
|
||||
}
|
||||
},
|
||||
verbs: []
|
||||
@@ -68,16 +65,13 @@ const hitchhiker_puzzle42Permission_user_zwei: Permission = {
|
||||
groupPermission: true,
|
||||
_links: {
|
||||
self: {
|
||||
href:
|
||||
"http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions/user_zwei"
|
||||
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"
|
||||
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"
|
||||
href: "http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions/user_zwei"
|
||||
}
|
||||
},
|
||||
verbs: []
|
||||
@@ -94,8 +88,7 @@ const hitchhiker_puzzle42RepoPermissions = {
|
||||
},
|
||||
_links: {
|
||||
create: {
|
||||
href:
|
||||
"http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions"
|
||||
href: "http://localhost:8081/scm/api/rest/v2/repositories/hitchhiker/puzzle42/permissions"
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -111,10 +104,7 @@ describe("permission fetch", () => {
|
||||
});
|
||||
|
||||
it("should successfully fetch permissions to repo hitchhiker/puzzle42", () => {
|
||||
fetchMock.getOnce(
|
||||
REPOS_URL + "/hitchhiker/puzzle42/permissions",
|
||||
hitchhiker_puzzle42RepoPermissions
|
||||
);
|
||||
fetchMock.getOnce(REPOS_URL + "/hitchhiker/puzzle42/permissions", hitchhiker_puzzle42RepoPermissions);
|
||||
|
||||
const expectedActions = [
|
||||
{
|
||||
@@ -134,13 +124,7 @@ describe("permission fetch", () => {
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
fetchPermissions(
|
||||
URL + "/hitchhiker/puzzle42/permissions",
|
||||
"hitchhiker",
|
||||
"puzzle42"
|
||||
)
|
||||
)
|
||||
.dispatch(fetchPermissions(URL + "/hitchhiker/puzzle42/permissions", "hitchhiker", "puzzle42"))
|
||||
.then(() => {
|
||||
expect(store.getActions()).toEqual(expectedActions);
|
||||
});
|
||||
@@ -153,13 +137,7 @@ describe("permission fetch", () => {
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
fetchPermissions(
|
||||
URL + "/hitchhiker/puzzle42/permissions",
|
||||
"hitchhiker",
|
||||
"puzzle42"
|
||||
)
|
||||
)
|
||||
.dispatch(fetchPermissions(URL + "/hitchhiker/puzzle42/permissions", "hitchhiker", "puzzle42"))
|
||||
.then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0].type).toEqual(FETCH_PERMISSIONS_PENDING);
|
||||
@@ -169,38 +147,30 @@ describe("permission fetch", () => {
|
||||
});
|
||||
|
||||
it("should successfully modify user_eins permission", () => {
|
||||
fetchMock.putOnce(
|
||||
hitchhiker_puzzle42Permission_user_eins._links.update.href,
|
||||
{
|
||||
status: 204
|
||||
}
|
||||
);
|
||||
fetchMock.putOnce(hitchhiker_puzzle42Permission_user_eins._links.update.href, {
|
||||
status: 204
|
||||
});
|
||||
|
||||
let editedPermission = {
|
||||
const 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);
|
||||
});
|
||||
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
|
||||
}
|
||||
);
|
||||
fetchMock.putOnce(hitchhiker_puzzle42Permission_user_eins._links.update.href, {
|
||||
status: 204
|
||||
});
|
||||
|
||||
let editedPermission = {
|
||||
const editedPermission = {
|
||||
...hitchhiker_puzzle42Permission_user_eins,
|
||||
type: "OWNER"
|
||||
};
|
||||
@@ -212,41 +182,32 @@ describe("permission fetch", () => {
|
||||
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);
|
||||
});
|
||||
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
|
||||
}
|
||||
);
|
||||
fetchMock.putOnce(hitchhiker_puzzle42Permission_user_eins._links.update.href, {
|
||||
status: 500
|
||||
});
|
||||
|
||||
let editedPermission = {
|
||||
const 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();
|
||||
});
|
||||
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", () => {
|
||||
@@ -338,40 +299,26 @@ describe("permission fetch", () => {
|
||||
});
|
||||
});
|
||||
it("should delete successfully permission user_eins", () => {
|
||||
fetchMock.deleteOnce(
|
||||
hitchhiker_puzzle42Permission_user_eins._links.delete.href,
|
||||
{
|
||||
status: 204
|
||||
}
|
||||
);
|
||||
fetchMock.deleteOnce(hitchhiker_puzzle42Permission_user_eins._links.delete.href, {
|
||||
status: 204
|
||||
});
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
deletePermission(
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
"hitchhiker",
|
||||
"puzzle42"
|
||||
)
|
||||
)
|
||||
.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[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
|
||||
}
|
||||
);
|
||||
fetchMock.deleteOnce(hitchhiker_puzzle42Permission_user_eins._links.delete.href, {
|
||||
status: 204
|
||||
});
|
||||
|
||||
let called = false;
|
||||
const callMe = () => {
|
||||
@@ -380,42 +327,24 @@ describe("permission fetch", () => {
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
deletePermission(
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
"hitchhiker",
|
||||
"puzzle42",
|
||||
callMe
|
||||
)
|
||||
)
|
||||
.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
|
||||
}
|
||||
);
|
||||
fetchMock.deleteOnce(hitchhiker_puzzle42Permission_user_eins._links.delete.href, {
|
||||
status: 500
|
||||
});
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(
|
||||
deletePermission(
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
"hitchhiker",
|
||||
"puzzle42"
|
||||
)
|
||||
)
|
||||
.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[0].payload).toBe(hitchhiker_puzzle42Permission_user_eins);
|
||||
expect(actions[1].type).toEqual(DELETE_PERMISSION_FAILURE);
|
||||
expect(actions[1].payload).toBeDefined();
|
||||
});
|
||||
@@ -446,18 +375,9 @@ describe("permissions reducer", () => {
|
||||
});
|
||||
|
||||
it("should store the permissions on FETCH_PERMISSION_SUCCESS", () => {
|
||||
const newState = reducer(
|
||||
{},
|
||||
fetchPermissionsSuccess(
|
||||
hitchhiker_puzzle42RepoPermissions,
|
||||
"hitchhiker",
|
||||
"puzzle42"
|
||||
)
|
||||
);
|
||||
const newState = reducer({}, fetchPermissionsSuccess(hitchhiker_puzzle42RepoPermissions, "hitchhiker", "puzzle42"));
|
||||
|
||||
expect(newState["hitchhiker/puzzle42"].entries).toBe(
|
||||
hitchhiker_puzzle42Permissions
|
||||
);
|
||||
expect(newState["hitchhiker/puzzle42"].entries).toBe(hitchhiker_puzzle42Permissions);
|
||||
});
|
||||
|
||||
it("should update permission", () => {
|
||||
@@ -466,31 +386,23 @@ describe("permissions reducer", () => {
|
||||
entries: [hitchhiker_puzzle42Permission_user_eins]
|
||||
}
|
||||
};
|
||||
let permissionEdited = {
|
||||
const permissionEdited = {
|
||||
...hitchhiker_puzzle42Permission_user_eins,
|
||||
type: "OWNER"
|
||||
};
|
||||
let expectedState = {
|
||||
const expectedState = {
|
||||
"hitchhiker/puzzle42": {
|
||||
entries: [permissionEdited]
|
||||
}
|
||||
};
|
||||
const newState = reducer(
|
||||
oldState,
|
||||
modifyPermissionSuccess(permissionEdited, "hitchhiker", "puzzle42")
|
||||
);
|
||||
expect(newState["hitchhiker/puzzle42"]).toEqual(
|
||||
expectedState["hitchhiker/puzzle42"]
|
||||
);
|
||||
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
|
||||
]
|
||||
entries: [hitchhiker_puzzle42Permission_user_eins, hitchhiker_puzzle42Permission_user_zwei]
|
||||
}
|
||||
};
|
||||
|
||||
@@ -502,15 +414,9 @@ describe("permissions reducer", () => {
|
||||
|
||||
const newState = reducer(
|
||||
state,
|
||||
deletePermissionSuccess(
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
"hitchhiker",
|
||||
"puzzle42"
|
||||
)
|
||||
);
|
||||
expect(newState["hitchhiker/puzzle42"]).toEqual(
|
||||
expectedState["hitchhiker/puzzle42"]
|
||||
deletePermissionSuccess(hitchhiker_puzzle42Permission_user_eins, "hitchhiker", "puzzle42")
|
||||
);
|
||||
expect(newState["hitchhiker/puzzle42"]).toEqual(expectedState["hitchhiker/puzzle42"]);
|
||||
});
|
||||
|
||||
it("should add permission", () => {
|
||||
@@ -520,25 +426,16 @@ describe("permissions reducer", () => {
|
||||
entries: [hitchhiker_puzzle42Permission_user_eins]
|
||||
}
|
||||
};
|
||||
let expectedState = {
|
||||
const expectedState = {
|
||||
"hitchhiker/puzzle42": {
|
||||
entries: [
|
||||
hitchhiker_puzzle42Permission_user_eins,
|
||||
hitchhiker_puzzle42Permission_user_zwei
|
||||
]
|
||||
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"]
|
||||
createPermissionSuccess(hitchhiker_puzzle42Permission_user_zwei, "hitchhiker", "puzzle42")
|
||||
);
|
||||
expect(newState["hitchhiker/puzzle42"]).toEqual(expectedState["hitchhiker/puzzle42"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -554,11 +451,7 @@ describe("permissions selectors", () => {
|
||||
}
|
||||
};
|
||||
|
||||
const repoPermissions = getPermissionsOfRepo(
|
||||
state,
|
||||
"hitchhiker",
|
||||
"puzzle42"
|
||||
);
|
||||
const repoPermissions = getPermissionsOfRepo(state, "hitchhiker", "puzzle42");
|
||||
expect(repoPermissions).toEqual(hitchhiker_puzzle42Permissions);
|
||||
});
|
||||
|
||||
@@ -568,15 +461,11 @@ describe("permissions selectors", () => {
|
||||
[FETCH_PERMISSIONS + "/hitchhiker/puzzle42"]: true
|
||||
}
|
||||
};
|
||||
expect(isFetchPermissionsPending(state, "hitchhiker", "puzzle42")).toEqual(
|
||||
true
|
||||
);
|
||||
expect(isFetchPermissionsPending(state, "hitchhiker", "puzzle42")).toEqual(true);
|
||||
});
|
||||
|
||||
it("should return false, when fetch permissions is not pending", () => {
|
||||
expect(isFetchPermissionsPending({}, "hitchiker", "puzzle42")).toEqual(
|
||||
false
|
||||
);
|
||||
expect(isFetchPermissionsPending({}, "hitchiker", "puzzle42")).toEqual(false);
|
||||
});
|
||||
|
||||
it("should return error when fetch permissions did fail", () => {
|
||||
@@ -585,15 +474,11 @@ describe("permissions selectors", () => {
|
||||
[FETCH_PERMISSIONS + "/hitchhiker/puzzle42"]: error
|
||||
}
|
||||
};
|
||||
expect(getFetchPermissionsFailure(state, "hitchhiker", "puzzle42")).toEqual(
|
||||
error
|
||||
);
|
||||
expect(getFetchPermissionsFailure(state, "hitchhiker", "puzzle42")).toEqual(error);
|
||||
});
|
||||
|
||||
it("should return undefined when fetch permissions did not fail", () => {
|
||||
expect(getFetchPermissionsFailure({}, "hitchhiker", "puzzle42")).toBe(
|
||||
undefined
|
||||
);
|
||||
expect(getFetchPermissionsFailure({}, "hitchhiker", "puzzle42")).toBe(undefined);
|
||||
});
|
||||
|
||||
it("should return true, when modify permission is pending", () => {
|
||||
@@ -602,25 +487,15 @@ describe("permissions selectors", () => {
|
||||
[MODIFY_PERMISSION + "/hitchhiker/puzzle42/user_eins"]: true
|
||||
}
|
||||
};
|
||||
expect(
|
||||
isModifyPermissionPending(
|
||||
state,
|
||||
"hitchhiker",
|
||||
"puzzle42",
|
||||
hitchhiker_puzzle42Permission_user_eins
|
||||
)
|
||||
).toEqual(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);
|
||||
expect(isModifyPermissionPending({}, "hitchiker", "puzzle42", hitchhiker_puzzle42Permission_user_eins)).toEqual(
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
it("should return error when modify permission did fail", () => {
|
||||
@@ -630,24 +505,14 @@ describe("permissions selectors", () => {
|
||||
}
|
||||
};
|
||||
expect(
|
||||
getModifyPermissionFailure(
|
||||
state,
|
||||
"hitchhiker",
|
||||
"puzzle42",
|
||||
hitchhiker_puzzle42Permission_user_eins
|
||||
)
|
||||
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);
|
||||
expect(getModifyPermissionFailure({}, "hitchhiker", "puzzle42", hitchhiker_puzzle42Permission_user_eins)).toBe(
|
||||
undefined
|
||||
);
|
||||
});
|
||||
|
||||
it("should return error when one of the modify permissions did fail", () => {
|
||||
@@ -661,15 +526,11 @@ describe("permissions selectors", () => {
|
||||
[MODIFY_PERMISSION + "/hitchhiker/puzzle42/user_eins"]: error
|
||||
}
|
||||
};
|
||||
expect(
|
||||
getModifyPermissionsFailure(state, "hitchhiker", "puzzle42")
|
||||
).toEqual(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
|
||||
);
|
||||
expect(getModifyPermissionsFailure({}, "hitchhiker", "puzzle42")).toBe(undefined);
|
||||
});
|
||||
|
||||
it("should return true, when createPermission is true", () => {
|
||||
@@ -700,25 +561,15 @@ describe("permissions selectors", () => {
|
||||
[DELETE_PERMISSION + "/hitchhiker/puzzle42/user_eins"]: true
|
||||
}
|
||||
};
|
||||
expect(
|
||||
isDeletePermissionPending(
|
||||
state,
|
||||
"hitchhiker",
|
||||
"puzzle42",
|
||||
hitchhiker_puzzle42Permission_user_eins
|
||||
)
|
||||
).toEqual(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);
|
||||
expect(isDeletePermissionPending({}, "hitchiker", "puzzle42", hitchhiker_puzzle42Permission_user_eins)).toEqual(
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
it("should return error when delete permission did fail", () => {
|
||||
@@ -728,24 +579,14 @@ describe("permissions selectors", () => {
|
||||
}
|
||||
};
|
||||
expect(
|
||||
getDeletePermissionFailure(
|
||||
state,
|
||||
"hitchhiker",
|
||||
"puzzle42",
|
||||
hitchhiker_puzzle42Permission_user_eins
|
||||
)
|
||||
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);
|
||||
expect(getDeletePermissionFailure({}, "hitchhiker", "puzzle42", hitchhiker_puzzle42Permission_user_eins)).toBe(
|
||||
undefined
|
||||
);
|
||||
});
|
||||
|
||||
it("should return error when one of the delete permissions did fail", () => {
|
||||
@@ -759,15 +600,11 @@ describe("permissions selectors", () => {
|
||||
[DELETE_PERMISSION + "/hitchhiker/puzzle42/user_eins"]: error
|
||||
}
|
||||
};
|
||||
expect(
|
||||
getDeletePermissionsFailure(state, "hitchhiker", "puzzle42")
|
||||
).toEqual(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
|
||||
);
|
||||
expect(getDeletePermissionsFailure({}, "hitchhiker", "puzzle42")).toBe(undefined);
|
||||
});
|
||||
|
||||
it("should return true, when create permission is pending", () => {
|
||||
@@ -776,15 +613,11 @@ describe("permissions selectors", () => {
|
||||
[CREATE_PERMISSION + "/hitchhiker/puzzle42"]: true
|
||||
}
|
||||
};
|
||||
expect(isCreatePermissionPending(state, "hitchhiker", "puzzle42")).toEqual(
|
||||
true
|
||||
);
|
||||
expect(isCreatePermissionPending(state, "hitchhiker", "puzzle42")).toEqual(true);
|
||||
});
|
||||
|
||||
it("should return false, when create permissions is not pending", () => {
|
||||
expect(isCreatePermissionPending({}, "hitchiker", "puzzle42")).toEqual(
|
||||
false
|
||||
);
|
||||
expect(isCreatePermissionPending({}, "hitchiker", "puzzle42")).toEqual(false);
|
||||
});
|
||||
|
||||
it("should return error when create permissions did fail", () => {
|
||||
@@ -793,14 +626,10 @@ describe("permissions selectors", () => {
|
||||
[CREATE_PERMISSION + "/hitchhiker/puzzle42"]: error
|
||||
}
|
||||
};
|
||||
expect(getCreatePermissionFailure(state, "hitchhiker", "puzzle42")).toEqual(
|
||||
error
|
||||
);
|
||||
expect(getCreatePermissionFailure(state, "hitchhiker", "puzzle42")).toEqual(error);
|
||||
});
|
||||
|
||||
it("should return undefined when create permissions did not fail", () => {
|
||||
expect(getCreatePermissionFailure({}, "hitchhiker", "puzzle42")).toBe(
|
||||
undefined
|
||||
);
|
||||
expect(getCreatePermissionFailure({}, "hitchhiker", "puzzle42")).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
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 { RepositoryRole, Permission, PermissionCollection, PermissionCreateEntry } from "@scm-manager/ui-types";
|
||||
import { isPending } from "../../../modules/pending";
|
||||
import { getFailure } from "../../../modules/failure";
|
||||
import { Dispatch } from "redux";
|
||||
@@ -39,18 +34,10 @@ const CONTENT_TYPE = "application/vnd.scmm-repositoryPermission+json";
|
||||
|
||||
// fetch available permissions
|
||||
|
||||
export function fetchAvailablePermissionsIfNeeded(
|
||||
repositoryRolesLink: string,
|
||||
repositoryVerbsLink: string
|
||||
) {
|
||||
export function fetchAvailablePermissionsIfNeeded(repositoryRolesLink: string, repositoryVerbsLink: string) {
|
||||
return function(dispatch: any, getState: () => object) {
|
||||
if (shouldFetchAvailablePermissions(getState())) {
|
||||
return fetchAvailablePermissions(
|
||||
dispatch,
|
||||
getState,
|
||||
repositoryRolesLink,
|
||||
repositoryVerbsLink
|
||||
);
|
||||
return fetchAvailablePermissions(dispatch, getState, repositoryRolesLink, repositoryVerbsLink);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -87,10 +74,7 @@ export function fetchAvailablePermissions(
|
||||
}
|
||||
|
||||
export function shouldFetchAvailablePermissions(state: object) {
|
||||
if (
|
||||
isFetchAvailablePermissionsPending(state) ||
|
||||
getFetchAvailablePermissionsFailure(state)
|
||||
) {
|
||||
if (isFetchAvailablePermissionsPending(state) || getFetchAvailablePermissionsFailure(state)) {
|
||||
return false;
|
||||
}
|
||||
return !state.available;
|
||||
@@ -104,9 +88,7 @@ export function fetchAvailablePending(): Action {
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchAvailableSuccess(
|
||||
available: [RepositoryRole[], string[]]
|
||||
): Action {
|
||||
export function fetchAvailableSuccess(available: [RepositoryRole[], string[]]): Action {
|
||||
return {
|
||||
type: FETCH_AVAILABLE_SUCCESS,
|
||||
payload: available,
|
||||
@@ -126,11 +108,7 @@ export function fetchAvailableFailure(error: Error): Action {
|
||||
|
||||
// fetch permissions
|
||||
|
||||
export function fetchPermissions(
|
||||
link: string,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
) {
|
||||
export function fetchPermissions(link: string, namespace: string, repoName: string) {
|
||||
return function(dispatch: any) {
|
||||
dispatch(fetchPermissionsPending(namespace, repoName));
|
||||
return apiClient
|
||||
@@ -145,10 +123,7 @@ export function fetchPermissions(
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchPermissionsPending(
|
||||
namespace: string,
|
||||
repoName: string
|
||||
): Action {
|
||||
export function fetchPermissionsPending(namespace: string, repoName: string): Action {
|
||||
return {
|
||||
type: FETCH_PERMISSIONS_PENDING,
|
||||
payload: {
|
||||
@@ -159,11 +134,7 @@ export function fetchPermissionsPending(
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchPermissionsSuccess(
|
||||
permissions: any,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
): Action {
|
||||
export function fetchPermissionsSuccess(permissions: any, namespace: string, repoName: string): Action {
|
||||
return {
|
||||
type: FETCH_PERMISSIONS_SUCCESS,
|
||||
payload: permissions,
|
||||
@@ -171,11 +142,7 @@ export function fetchPermissionsSuccess(
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchPermissionsFailure(
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
error: Error
|
||||
): Action {
|
||||
export function fetchPermissionsFailure(namespace: string, repoName: string, error: Error): Action {
|
||||
return {
|
||||
type: FETCH_PERMISSIONS_FAILURE,
|
||||
payload: {
|
||||
@@ -189,12 +156,7 @@ export function fetchPermissionsFailure(
|
||||
|
||||
// modify permission
|
||||
|
||||
export function modifyPermission(
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
callback?: () => void
|
||||
) {
|
||||
export function modifyPermission(permission: Permission, namespace: string, repoName: string, callback?: () => void) {
|
||||
return function(dispatch: any) {
|
||||
dispatch(modifyPermissionPending(permission, namespace, repoName));
|
||||
return apiClient
|
||||
@@ -211,11 +173,7 @@ export function modifyPermission(
|
||||
};
|
||||
}
|
||||
|
||||
export function modifyPermissionPending(
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
): Action {
|
||||
export function modifyPermissionPending(permission: Permission, namespace: string, repoName: string): Action {
|
||||
return {
|
||||
type: MODIFY_PERMISSION_PENDING,
|
||||
payload: permission,
|
||||
@@ -223,11 +181,7 @@ export function modifyPermissionPending(
|
||||
};
|
||||
}
|
||||
|
||||
export function modifyPermissionSuccess(
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
): Action {
|
||||
export function modifyPermissionSuccess(permission: Permission, namespace: string, repoName: string): Action {
|
||||
return {
|
||||
type: MODIFY_PERMISSION_SUCCESS,
|
||||
payload: {
|
||||
@@ -254,10 +208,7 @@ export function modifyPermissionFailure(
|
||||
};
|
||||
}
|
||||
|
||||
function newPermissions(
|
||||
oldPermissions: PermissionCollection,
|
||||
newPermission: Permission
|
||||
) {
|
||||
function newPermissions(oldPermissions: PermissionCollection, newPermission: Permission) {
|
||||
for (let i = 0; i < oldPermissions.length; i++) {
|
||||
if (oldPermissions[i].name === newPermission.name) {
|
||||
oldPermissions.splice(i, 1, newPermission);
|
||||
@@ -295,16 +246,12 @@ export function createPermission(
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(createdPermission => {
|
||||
dispatch(
|
||||
createPermissionSuccess(createdPermission, namespace, repoName)
|
||||
);
|
||||
dispatch(createPermissionSuccess(createdPermission, namespace, repoName));
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
})
|
||||
.catch(err =>
|
||||
dispatch(createPermissionFailure(err, namespace, repoName))
|
||||
);
|
||||
.catch(err => dispatch(createPermissionFailure(err, namespace, repoName)));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -335,11 +282,7 @@ export function createPermissionSuccess(
|
||||
};
|
||||
}
|
||||
|
||||
export function createPermissionFailure(
|
||||
error: Error,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
): Action {
|
||||
export function createPermissionFailure(error: Error, namespace: string, repoName: string): Action {
|
||||
return {
|
||||
type: CREATE_PERMISSION_FAILURE,
|
||||
payload: error,
|
||||
@@ -356,12 +299,7 @@ export function createPermissionReset(namespace: string, repoName: string) {
|
||||
|
||||
// delete permission
|
||||
|
||||
export function deletePermission(
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
callback?: () => void
|
||||
) {
|
||||
export function deletePermission(permission: Permission, namespace: string, repoName: string, callback?: () => void) {
|
||||
return function(dispatch: any) {
|
||||
dispatch(deletePermissionPending(permission, namespace, repoName));
|
||||
return apiClient
|
||||
@@ -378,11 +316,7 @@ export function deletePermission(
|
||||
};
|
||||
}
|
||||
|
||||
export function deletePermissionPending(
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
): Action {
|
||||
export function deletePermissionPending(permission: Permission, namespace: string, repoName: string): Action {
|
||||
return {
|
||||
type: DELETE_PERMISSION_PENDING,
|
||||
payload: permission,
|
||||
@@ -390,11 +324,7 @@ export function deletePermissionPending(
|
||||
};
|
||||
}
|
||||
|
||||
export function deletePermissionSuccess(
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
): Action {
|
||||
export function deletePermissionSuccess(permission: Permission, namespace: string, repoName: string): Action {
|
||||
return {
|
||||
type: DELETE_PERMISSION_SUCCESS,
|
||||
payload: {
|
||||
@@ -432,11 +362,8 @@ export function deletePermissionReset(namespace: string, repoName: string) {
|
||||
};
|
||||
}
|
||||
|
||||
function deletePermissionFromState(
|
||||
oldPermissions: PermissionCollection,
|
||||
permission: Permission
|
||||
) {
|
||||
let newPermission = [];
|
||||
function deletePermissionFromState(oldPermissions: PermissionCollection, permission: Permission) {
|
||||
const newPermission = [];
|
||||
for (let i = 0; i < oldPermissions.length; i++) {
|
||||
if (
|
||||
oldPermissions[i].name !== permission.name ||
|
||||
@@ -448,12 +375,8 @@ function deletePermissionFromState(
|
||||
return newPermission;
|
||||
}
|
||||
|
||||
function createItemId(
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
) {
|
||||
let groupPermission = permission.groupPermission ? "@" : "";
|
||||
function createItemId(permission: Permission, namespace: string, repoName: string) {
|
||||
const groupPermission = permission.groupPermission ? "@" : "";
|
||||
return namespace + "/" + repoName + "/" + groupPermission + permission.name;
|
||||
}
|
||||
|
||||
@@ -483,10 +406,7 @@ export default function reducer(
|
||||
};
|
||||
case MODIFY_PERMISSION_SUCCESS:
|
||||
const positionOfPermission = action.payload.position;
|
||||
const newPermission = newPermissions(
|
||||
state[action.payload.position].entries,
|
||||
action.payload.permission
|
||||
);
|
||||
const newPermission = newPermissions(state[action.payload.position].entries, action.payload.permission);
|
||||
return {
|
||||
...state,
|
||||
[positionOfPermission]: {
|
||||
@@ -547,11 +467,7 @@ function available(state: object) {
|
||||
return {};
|
||||
}
|
||||
|
||||
export function getPermissionsOfRepo(
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
) {
|
||||
export function getPermissionsOfRepo(state: object, namespace: string, repoName: string) {
|
||||
if (state.permissions && state.permissions[namespace + "/" + repoName]) {
|
||||
return state.permissions[namespace + "/" + repoName].entries;
|
||||
}
|
||||
@@ -561,11 +477,7 @@ export function isFetchAvailablePermissionsPending(state: object) {
|
||||
return isPending(state, FETCH_AVAILABLE, "available");
|
||||
}
|
||||
|
||||
export function isFetchPermissionsPending(
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
) {
|
||||
export function isFetchPermissionsPending(state: object, namespace: string, repoName: string) {
|
||||
return isPending(state, FETCH_PERMISSIONS, namespace + "/" + repoName);
|
||||
}
|
||||
|
||||
@@ -573,147 +485,70 @@ export function getFetchAvailablePermissionsFailure(state: object) {
|
||||
return getFailure(state, FETCH_AVAILABLE, "available");
|
||||
}
|
||||
|
||||
export function getFetchPermissionsFailure(
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
) {
|
||||
export function getFetchPermissionsFailure(state: object, namespace: string, repoName: string) {
|
||||
return getFailure(state, FETCH_PERMISSIONS, namespace + "/" + repoName);
|
||||
}
|
||||
|
||||
export function isModifyPermissionPending(
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
permission: Permission
|
||||
) {
|
||||
return isPending(
|
||||
state,
|
||||
MODIFY_PERMISSION,
|
||||
createItemId(permission, namespace, repoName)
|
||||
);
|
||||
export function isModifyPermissionPending(state: object, namespace: string, repoName: string, permission: Permission) {
|
||||
return isPending(state, MODIFY_PERMISSION, createItemId(permission, namespace, repoName));
|
||||
}
|
||||
|
||||
export function getModifyPermissionFailure(
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
permission: Permission
|
||||
) {
|
||||
return getFailure(
|
||||
state,
|
||||
MODIFY_PERMISSION,
|
||||
createItemId(permission, namespace, repoName)
|
||||
);
|
||||
export function getModifyPermissionFailure(state: object, namespace: string, repoName: string, permission: Permission) {
|
||||
return getFailure(state, MODIFY_PERMISSION, createItemId(permission, namespace, repoName));
|
||||
}
|
||||
|
||||
export function hasCreatePermission(
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
) {
|
||||
export function hasCreatePermission(state: object, namespace: string, repoName: string) {
|
||||
if (state.permissions && state.permissions[namespace + "/" + repoName])
|
||||
return state.permissions[namespace + "/" + repoName].createPermission;
|
||||
else return null;
|
||||
}
|
||||
|
||||
export function isCreatePermissionPending(
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
) {
|
||||
export function isCreatePermissionPending(state: object, namespace: string, repoName: string) {
|
||||
return isPending(state, CREATE_PERMISSION, namespace + "/" + repoName);
|
||||
}
|
||||
|
||||
export function getCreatePermissionFailure(
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
) {
|
||||
export function getCreatePermissionFailure(state: object, namespace: string, repoName: string) {
|
||||
return getFailure(state, CREATE_PERMISSION, namespace + "/" + repoName);
|
||||
}
|
||||
|
||||
export function isDeletePermissionPending(
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
permission: Permission
|
||||
) {
|
||||
return isPending(
|
||||
state,
|
||||
DELETE_PERMISSION,
|
||||
createItemId(permission, namespace, repoName)
|
||||
);
|
||||
export function isDeletePermissionPending(state: object, namespace: string, repoName: string, permission: Permission) {
|
||||
return isPending(state, DELETE_PERMISSION, createItemId(permission, namespace, repoName));
|
||||
}
|
||||
|
||||
export function getDeletePermissionFailure(
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
permission: Permission
|
||||
) {
|
||||
return getFailure(
|
||||
state,
|
||||
DELETE_PERMISSION,
|
||||
createItemId(permission, namespace, repoName)
|
||||
);
|
||||
export function getDeletePermissionFailure(state: object, namespace: string, repoName: string, permission: Permission) {
|
||||
return getFailure(state, DELETE_PERMISSION, createItemId(permission, namespace, repoName));
|
||||
}
|
||||
|
||||
export function getDeletePermissionsFailure(
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
) {
|
||||
export function getDeletePermissionsFailure(state: object, namespace: string, repoName: string) {
|
||||
const permissions =
|
||||
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++) {
|
||||
if (
|
||||
getDeletePermissionFailure(state, namespace, repoName, permissions[i])
|
||||
) {
|
||||
return getFailure(
|
||||
state,
|
||||
DELETE_PERMISSION,
|
||||
createItemId(permissions[i], namespace, repoName)
|
||||
);
|
||||
if (getDeletePermissionFailure(state, namespace, repoName, permissions[i])) {
|
||||
return getFailure(state, DELETE_PERMISSION, createItemId(permissions[i], namespace, repoName));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getModifyPermissionsFailure(
|
||||
state: object,
|
||||
namespace: string,
|
||||
repoName: string
|
||||
) {
|
||||
export function getModifyPermissionsFailure(state: object, namespace: string, repoName: string) {
|
||||
const permissions =
|
||||
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++) {
|
||||
if (
|
||||
getModifyPermissionFailure(state, namespace, repoName, permissions[i])
|
||||
) {
|
||||
return getFailure(
|
||||
state,
|
||||
MODIFY_PERMISSION,
|
||||
createItemId(permissions[i], namespace, repoName)
|
||||
);
|
||||
if (getModifyPermissionFailure(state, namespace, repoName, permissions[i])) {
|
||||
return getFailure(state, MODIFY_PERMISSION, createItemId(permissions[i], namespace, repoName));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function findVerbsForRole(
|
||||
availableRepositoryRoles: RepositoryRole[],
|
||||
roleName: string
|
||||
) {
|
||||
const matchingRole = availableRepositoryRoles.find(
|
||||
role => roleName === role.name
|
||||
);
|
||||
export function findVerbsForRole(availableRepositoryRoles: RepositoryRole[], roleName: string) {
|
||||
const matchingRole = availableRepositoryRoles.find(role => roleName === role.name);
|
||||
if (matchingRole) {
|
||||
return matchingRole.verbs;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user