mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
apply prettier, removed flow related config and added tsconfig
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import { Checkbox } from '@scm-manager/ui-components';
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import { Checkbox } from "@scm-manager/ui-components";
|
||||
|
||||
type Props = {
|
||||
t: (p: string) => string;
|
||||
@@ -17,8 +17,8 @@ class PermissionCheckbox extends React.Component<Props> {
|
||||
<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')}
|
||||
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}
|
||||
@@ -27,4 +27,4 @@ class PermissionCheckbox extends React.Component<Props> {
|
||||
}
|
||||
}
|
||||
|
||||
export default translate('plugins')(PermissionCheckbox);
|
||||
export default translate("plugins")(PermissionCheckbox);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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: (p: string) => string;
|
||||
@@ -20,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}
|
||||
@@ -45,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,76 +1,75 @@
|
||||
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 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', () => ({
|
||||
import { confirmAlert } from "@scm-manager/ui-components";
|
||||
jest.mock("@scm-manager/ui-components", () => ({
|
||||
confirmAlert: jest.fn(),
|
||||
DeleteButton: require.requireActual('@scm-manager/ui-components')
|
||||
.DeleteButton,
|
||||
DeleteButton: require.requireActual("@scm-manager/ui-components").DeleteButton
|
||||
}));
|
||||
|
||||
describe('DeletePermissionButton', () => {
|
||||
it('should render nothing, if the delete link is missing', () => {
|
||||
describe("DeletePermissionButton", () => {
|
||||
it("should render nothing, if the delete link is missing", () => {
|
||||
const permission = {
|
||||
_links: {},
|
||||
_links: {}
|
||||
};
|
||||
|
||||
const navLink = shallow(
|
||||
<DeletePermissionButton
|
||||
permission={permission}
|
||||
deletePermission={() => {}}
|
||||
/>,
|
||||
/>
|
||||
);
|
||||
expect(navLink.text()).toBe('');
|
||||
expect(navLink.text()).toBe("");
|
||||
});
|
||||
|
||||
it('should render the delete icon', () => {
|
||||
it("should render the delete icon", () => {
|
||||
const permission = {
|
||||
_links: {
|
||||
delete: {
|
||||
href: '/permission',
|
||||
},
|
||||
},
|
||||
href: "/permission"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const deleteIcon = mount(
|
||||
<DeletePermissionButton
|
||||
permission={permission}
|
||||
deletePermission={() => {}}
|
||||
/>,
|
||||
/>
|
||||
);
|
||||
expect(deleteIcon.html()).not.toBe('');
|
||||
expect(deleteIcon.html()).not.toBe("");
|
||||
});
|
||||
|
||||
it('should open the confirm dialog on button click', () => {
|
||||
it("should open the confirm dialog on button click", () => {
|
||||
const permission = {
|
||||
_links: {
|
||||
delete: {
|
||||
href: '/permission',
|
||||
},
|
||||
},
|
||||
href: "/permission"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const button = mount(
|
||||
<DeletePermissionButton
|
||||
permission={permission}
|
||||
deletePermission={() => {}}
|
||||
/>,
|
||||
/>
|
||||
);
|
||||
button.find('.fa-trash').simulate('click');
|
||||
button.find(".fa-trash").simulate("click");
|
||||
|
||||
expect(confirmAlert.mock.calls.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should call the delete permission function with delete url', () => {
|
||||
it("should call the delete permission function with delete url", () => {
|
||||
const permission = {
|
||||
_links: {
|
||||
delete: {
|
||||
href: '/permission',
|
||||
},
|
||||
},
|
||||
href: "/permission"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let calledUrl = null;
|
||||
@@ -83,10 +82,10 @@ describe('DeletePermissionButton', () => {
|
||||
permission={permission}
|
||||
confirmDialog={false}
|
||||
deletePermission={capture}
|
||||
/>,
|
||||
/>
|
||||
);
|
||||
button.find('.fa-trash').simulate('click');
|
||||
button.find(".fa-trash").simulate("click");
|
||||
|
||||
expect(calledUrl).toBe('/permission');
|
||||
expect(calledUrl).toBe("/permission");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import { 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;
|
||||
@@ -12,39 +12,39 @@ type Props = {
|
||||
deletePermission: (
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
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
|
||||
}
|
||||
]
|
||||
});
|
||||
};
|
||||
|
||||
@@ -69,4 +69,4 @@ class DeletePermissionButton extends React.Component<Props> {
|
||||
}
|
||||
}
|
||||
|
||||
export default translate('repos')(DeletePermissionButton);
|
||||
export default translate("repos")(DeletePermissionButton);
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
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,5 +1,5 @@
|
||||
import { validation } from '@scm-manager/ui-components';
|
||||
import { PermissionCollection } from '@scm-manager/ui-types';
|
||||
import { validation } from "@scm-manager/ui-components";
|
||||
import { PermissionCollection } from "@scm-manager/ui-types";
|
||||
|
||||
const isNameValid = validation.isNameValid;
|
||||
|
||||
@@ -8,7 +8,7 @@ export { isNameValid };
|
||||
export const isPermissionValid = (
|
||||
name: string,
|
||||
groupPermission: boolean,
|
||||
permissions: PermissionCollection,
|
||||
permissions: PermissionCollection
|
||||
) => {
|
||||
return (
|
||||
isNameValid(name) &&
|
||||
@@ -19,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,12 +1,12 @@
|
||||
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;
|
||||
@@ -32,10 +32,10 @@ class AdvancedPermissionsDialog extends React.Component<Props, State> {
|
||||
verb =>
|
||||
(verbs[verb] = props.selectedVerbs
|
||||
? props.selectedVerbs.includes(verb)
|
||||
: false),
|
||||
: false)
|
||||
);
|
||||
this.state = {
|
||||
verbs,
|
||||
verbs
|
||||
};
|
||||
}
|
||||
|
||||
@@ -54,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}</>;
|
||||
@@ -64,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>
|
||||
@@ -73,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}
|
||||
@@ -86,10 +86,10 @@ class AdvancedPermissionsDialog extends React.Component<Props, State> {
|
||||
const { verbs } = this.state;
|
||||
const newVerbs = {
|
||||
...verbs,
|
||||
[name]: value,
|
||||
[name]: value
|
||||
};
|
||||
this.setState({
|
||||
verbs: newVerbs,
|
||||
verbs: newVerbs
|
||||
});
|
||||
};
|
||||
|
||||
@@ -97,9 +97,9 @@ class AdvancedPermissionsDialog extends React.Component<Props, State> {
|
||||
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,11 +1,11 @@
|
||||
import React from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import {
|
||||
PermissionCollection,
|
||||
PermissionCreateEntry,
|
||||
RepositoryRole,
|
||||
SelectValue,
|
||||
} from '@scm-manager/ui-types';
|
||||
SelectValue
|
||||
} from "@scm-manager/ui-types";
|
||||
import {
|
||||
Button,
|
||||
GroupAutocomplete,
|
||||
@@ -13,12 +13,12 @@ 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[];
|
||||
@@ -48,13 +48,13 @@ 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
|
||||
};
|
||||
}
|
||||
|
||||
@@ -73,9 +73,9 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
permissionScopeChanged = (groupPermission: boolean) => {
|
||||
this.setState({
|
||||
value: undefined,
|
||||
name: '',
|
||||
name: "",
|
||||
groupPermission,
|
||||
valid: false,
|
||||
valid: false
|
||||
});
|
||||
};
|
||||
|
||||
@@ -86,7 +86,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 : ""}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -94,7 +94,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 : ""}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -106,8 +106,8 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
valid: validator.isPermissionValid(
|
||||
value.value.id,
|
||||
this.state.groupPermission,
|
||||
this.props.currentPermissions,
|
||||
),
|
||||
this.props.currentPermissions
|
||||
)
|
||||
});
|
||||
};
|
||||
|
||||
@@ -132,7 +132,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}>
|
||||
@@ -142,14 +142,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.userPermissionScopeChanged}
|
||||
/>
|
||||
<Radio
|
||||
name="permission_scope"
|
||||
value="GROUP_PERMISSION"
|
||||
checked={this.state.groupPermission}
|
||||
label={t('permission.group-permission')}
|
||||
label={t("permission.group-permission")}
|
||||
onChange={this.groupPermissionScopeChanged}
|
||||
/>
|
||||
</div>
|
||||
@@ -163,19 +163,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>
|
||||
@@ -185,9 +185,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>
|
||||
@@ -198,7 +198,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
|
||||
toggleAdvancedPermissionsDialog = () => {
|
||||
this.setState(prevState => ({
|
||||
showAdvancedDialog: !prevState.showAdvancedDialog,
|
||||
showAdvancedDialog: !prevState.showAdvancedDialog
|
||||
}));
|
||||
};
|
||||
|
||||
@@ -206,7 +206,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
this.setState({
|
||||
showAdvancedDialog: false,
|
||||
role: undefined,
|
||||
verbs: newVerbs,
|
||||
verbs: newVerbs
|
||||
});
|
||||
};
|
||||
|
||||
@@ -215,7 +215,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();
|
||||
@@ -223,11 +223,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
|
||||
});
|
||||
};
|
||||
|
||||
@@ -238,7 +238,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
}
|
||||
this.setState({
|
||||
role: selectedRole.name,
|
||||
verbs: [],
|
||||
verbs: []
|
||||
});
|
||||
};
|
||||
|
||||
@@ -247,4 +247,4 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
};
|
||||
}
|
||||
|
||||
export default translate('repos')(CreatePermissionForm);
|
||||
export default translate("repos")(CreatePermissionForm);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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,
|
||||
@@ -20,30 +20,30 @@ import {
|
||||
isCreatePermissionPending,
|
||||
isFetchAvailablePermissionsPending,
|
||||
isFetchPermissionsPending,
|
||||
modifyPermissionReset,
|
||||
} from '../modules/permissions';
|
||||
modifyPermissionReset
|
||||
} from "../modules/permissions";
|
||||
import {
|
||||
ErrorPage,
|
||||
LabelWithHelpIcon,
|
||||
Loading,
|
||||
Subtitle,
|
||||
} from '@scm-manager/ui-components';
|
||||
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';
|
||||
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;
|
||||
@@ -65,7 +65,7 @@ type Props = {
|
||||
//dispatch functions
|
||||
fetchAvailablePermissionsIfNeeded: (
|
||||
repositoryRolesLink: string,
|
||||
repositoryVerbsLink: string,
|
||||
repositoryVerbsLink: string
|
||||
) => void;
|
||||
fetchPermissions: (link: string, namespace: string, repoName: string) => void;
|
||||
createPermission: (
|
||||
@@ -73,7 +73,7 @@ type Props = {
|
||||
permission: PermissionCreateEntry,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
callback?: () => void,
|
||||
callback?: () => void
|
||||
) => void;
|
||||
createPermissionReset: (p1: string, p2: string) => void;
|
||||
modifyPermissionReset: (p1: string, p2: string) => void;
|
||||
@@ -96,7 +96,7 @@ class Permissions extends React.Component<Props> {
|
||||
deletePermissionReset,
|
||||
permissionsLink,
|
||||
repositoryRolesLink,
|
||||
repositoryVerbsLink,
|
||||
repositoryVerbsLink
|
||||
} = this.props;
|
||||
|
||||
createPermissionReset(namespace, repoName);
|
||||
@@ -111,7 +111,7 @@ class Permissions extends React.Component<Props> {
|
||||
this.props.permissionsLink,
|
||||
permission,
|
||||
this.props.namespace,
|
||||
this.props.repoName,
|
||||
this.props.repoName
|
||||
);
|
||||
};
|
||||
|
||||
@@ -129,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}
|
||||
/>
|
||||
);
|
||||
@@ -159,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 />
|
||||
@@ -221,7 +221,7 @@ const mapStateToProps = (state, ownProps) => {
|
||||
const loadingCreatePermission = isCreatePermissionPending(
|
||||
state,
|
||||
namespace,
|
||||
repoName,
|
||||
repoName
|
||||
);
|
||||
const hasPermissionToCreate = hasCreatePermission(state, namespace, repoName);
|
||||
const repositoryRolesLink = getRepositoryRolesLink(state);
|
||||
@@ -248,7 +248,7 @@ const mapStateToProps = (state, ownProps) => {
|
||||
loadingCreatePermission,
|
||||
permissionsLink,
|
||||
groupAutocompleteLink,
|
||||
userAutocompleteLink,
|
||||
userAutocompleteLink
|
||||
};
|
||||
};
|
||||
|
||||
@@ -259,13 +259,13 @@ const mapDispatchToProps = dispatch => {
|
||||
},
|
||||
fetchAvailablePermissionsIfNeeded: (
|
||||
repositoryRolesLink: string,
|
||||
repositoryVerbsLink: string,
|
||||
repositoryVerbsLink: string
|
||||
) => {
|
||||
dispatch(
|
||||
fetchAvailablePermissionsIfNeeded(
|
||||
repositoryRolesLink,
|
||||
repositoryVerbsLink,
|
||||
),
|
||||
repositoryVerbsLink
|
||||
)
|
||||
);
|
||||
},
|
||||
createPermission: (
|
||||
@@ -273,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) => {
|
||||
@@ -287,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,20 +1,20 @@
|
||||
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 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[];
|
||||
@@ -23,7 +23,7 @@ type Props = {
|
||||
modifyPermission: (
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
name: string,
|
||||
name: string
|
||||
) => void;
|
||||
permission: Permission;
|
||||
t: (p: string) => string;
|
||||
@@ -35,7 +35,7 @@ type Props = {
|
||||
deletePermission: (
|
||||
permission: Permission,
|
||||
namespace: string,
|
||||
name: string,
|
||||
name: string
|
||||
) => void;
|
||||
deleteLoading: boolean;
|
||||
};
|
||||
@@ -64,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
|
||||
};
|
||||
}
|
||||
|
||||
@@ -84,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
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -94,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
|
||||
);
|
||||
};
|
||||
|
||||
@@ -105,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
|
||||
@@ -140,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 (
|
||||
@@ -153,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,13 +177,13 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
|
||||
handleDetailedPermissionsPressed = () => {
|
||||
this.setState({
|
||||
showAdvancedDialog: true,
|
||||
showAdvancedDialog: true
|
||||
});
|
||||
};
|
||||
|
||||
closeAdvancedPermissionsDialog = () => {
|
||||
this.setState({
|
||||
showAdvancedDialog: false,
|
||||
showAdvancedDialog: false
|
||||
});
|
||||
};
|
||||
|
||||
@@ -195,10 +195,10 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
permission: {
|
||||
...permission,
|
||||
role: undefined,
|
||||
verbs: newVerbs,
|
||||
},
|
||||
verbs: newVerbs
|
||||
}
|
||||
},
|
||||
() => this.modifyPermissionVerbs(newVerbs),
|
||||
() => this.modifyPermissionVerbs(newVerbs)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -209,10 +209,10 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
permission: {
|
||||
...permission,
|
||||
role: role,
|
||||
verbs: undefined,
|
||||
},
|
||||
verbs: undefined
|
||||
}
|
||||
},
|
||||
() => this.modifyPermissionRole(role),
|
||||
() => this.modifyPermissionRole(role)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -227,7 +227,7 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
this.props.modifyPermission(
|
||||
permission,
|
||||
this.props.namespace,
|
||||
this.props.repoName,
|
||||
this.props.repoName
|
||||
);
|
||||
};
|
||||
|
||||
@@ -237,7 +237,7 @@ class SinglePermission extends React.Component<Props, State> {
|
||||
this.props.modifyPermission(
|
||||
permission,
|
||||
this.props.namespace,
|
||||
this.props.repoName,
|
||||
this.props.repoName
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -248,18 +248,18 @@ const mapStateToProps = (state, ownProps) => {
|
||||
state,
|
||||
ownProps.namespace,
|
||||
ownProps.repoName,
|
||||
permission,
|
||||
permission
|
||||
);
|
||||
const deleteLoading = isDeletePermissionPending(
|
||||
state,
|
||||
ownProps.namespace,
|
||||
ownProps.repoName,
|
||||
permission,
|
||||
permission
|
||||
);
|
||||
|
||||
return {
|
||||
loading,
|
||||
deleteLoading,
|
||||
deleteLoading
|
||||
};
|
||||
};
|
||||
|
||||
@@ -268,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));
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,47 +1,47 @@
|
||||
import { Action } from '@scm-manager/ui-components';
|
||||
import { apiClient } from '@scm-manager/ui-components';
|
||||
import * as types from '../../../modules/types';
|
||||
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 = "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 = "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 = "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 = "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 = "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) {
|
||||
if (shouldFetchAvailablePermissions(getState())) {
|
||||
@@ -49,7 +49,7 @@ export function fetchAvailablePermissionsIfNeeded(
|
||||
dispatch,
|
||||
getState,
|
||||
repositoryRolesLink,
|
||||
repositoryVerbsLink,
|
||||
repositoryVerbsLink
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -59,7 +59,7 @@ export function fetchAvailablePermissions(
|
||||
dispatch: any,
|
||||
getState: () => object,
|
||||
repositoryRolesLink: string,
|
||||
repositoryVerbsLink: string,
|
||||
repositoryVerbsLink: string
|
||||
) {
|
||||
dispatch(fetchAvailablePending());
|
||||
return apiClient
|
||||
@@ -74,7 +74,7 @@ export function fetchAvailablePermissions(
|
||||
.then(repositoryVerbs => {
|
||||
return {
|
||||
repositoryVerbs,
|
||||
repositoryRoles,
|
||||
repositoryRoles
|
||||
};
|
||||
});
|
||||
})
|
||||
@@ -100,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"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -118,9 +118,9 @@ export function fetchAvailableFailure(error: Error): Action {
|
||||
return {
|
||||
type: FETCH_AVAILABLE_FAILURE,
|
||||
payload: {
|
||||
error,
|
||||
error
|
||||
},
|
||||
itemId: 'available',
|
||||
itemId: "available"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -129,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));
|
||||
@@ -147,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
|
||||
};
|
||||
}
|
||||
|
||||
@@ -193,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));
|
||||
@@ -214,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)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -242,21 +242,21 @@ export function modifyPermissionFailure(
|
||||
permission: Permission,
|
||||
error: Error,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
repoName: string
|
||||
): Action {
|
||||
return {
|
||||
type: MODIFY_PERMISSION_FAILURE,
|
||||
payload: {
|
||||
error,
|
||||
permission,
|
||||
permission
|
||||
},
|
||||
itemId: createItemId(permission, namespace, repoName),
|
||||
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) {
|
||||
@@ -271,9 +271,9 @@ export function modifyPermissionReset(namespace: string, repoName: string) {
|
||||
type: MODIFY_PERMISSION_RESET,
|
||||
payload: {
|
||||
namespace,
|
||||
repoName,
|
||||
repoName
|
||||
},
|
||||
itemId: namespace + '/' + repoName,
|
||||
itemId: namespace + "/" + repoName
|
||||
};
|
||||
}
|
||||
|
||||
@@ -283,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))
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -311,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
|
||||
};
|
||||
}
|
||||
|
||||
@@ -360,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));
|
||||
@@ -381,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)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -409,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)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -426,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++) {
|
||||
@@ -451,18 +451,18 @@ 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',
|
||||
},
|
||||
type: "UNKNOWN"
|
||||
}
|
||||
): object {
|
||||
if (!action.payload) {
|
||||
return state;
|
||||
@@ -471,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;
|
||||
@@ -503,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;
|
||||
@@ -550,47 +550,47 @@ function available(state: object) {
|
||||
export function getPermissionsOfRepo(
|
||||
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');
|
||||
return isPending(state, FETCH_AVAILABLE, "available");
|
||||
}
|
||||
|
||||
export function isFetchPermissionsPending(
|
||||
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');
|
||||
return getFailure(state, FETCH_AVAILABLE, "available");
|
||||
}
|
||||
|
||||
export function getFetchPermissionsFailure(
|
||||
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,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
permission: Permission,
|
||||
permission: Permission
|
||||
) {
|
||||
return isPending(
|
||||
state,
|
||||
MODIFY_PERMISSION,
|
||||
createItemId(permission, namespace, repoName),
|
||||
createItemId(permission, namespace, repoName)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -598,51 +598,51 @@ export function getModifyPermissionFailure(
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
permission: Permission,
|
||||
permission: Permission
|
||||
) {
|
||||
return isPending(
|
||||
state,
|
||||
DELETE_PERMISSION,
|
||||
createItemId(permission, namespace, repoName),
|
||||
createItemId(permission, namespace, repoName)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -650,23 +650,23 @@ export function getDeletePermissionFailure(
|
||||
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,
|
||||
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++) {
|
||||
@@ -676,7 +676,7 @@ export function getDeletePermissionsFailure(
|
||||
return getFailure(
|
||||
state,
|
||||
DELETE_PERMISSION,
|
||||
createItemId(permissions[i], namespace, repoName),
|
||||
createItemId(permissions[i], namespace, repoName)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -686,11 +686,11 @@ export function getDeletePermissionsFailure(
|
||||
export function getModifyPermissionsFailure(
|
||||
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++) {
|
||||
@@ -700,7 +700,7 @@ export function getModifyPermissionsFailure(
|
||||
return getFailure(
|
||||
state,
|
||||
MODIFY_PERMISSION,
|
||||
createItemId(permissions[i], namespace, repoName),
|
||||
createItemId(permissions[i], namespace, repoName)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -709,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