mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-03 12:05:52 +01:00
renaming: name to repoName if repo name is meant; usage of create loading
This commit is contained in:
@@ -8,7 +8,8 @@ import { SubmitButton } from "../../components/buttons";
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
t: string => string,
|
t: string => string,
|
||||||
createPermission: (permission: Permission) => void
|
createPermission: (permission: Permission) => void,
|
||||||
|
loading: boolean
|
||||||
};
|
};
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
@@ -29,7 +30,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { t } = this.props;
|
const { t, loading } = this.props;
|
||||||
const { name, type, groupPermission } = this.state;
|
const { name, type, groupPermission } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -71,6 +72,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
|||||||
<SubmitButton
|
<SubmitButton
|
||||||
label={t("add-permission.submit-button")}
|
label={t("add-permission.submit-button")}
|
||||||
action={this.submit}
|
action={this.submit}
|
||||||
|
loading={loading}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ import { DeleteButton } from "../../../components/buttons/index";
|
|||||||
type Props = {
|
type Props = {
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string,
|
repoName: string,
|
||||||
confirmDialog?: boolean,
|
confirmDialog?: boolean,
|
||||||
t: string => string,
|
t: string => string,
|
||||||
deletePermission: (
|
deletePermission: (
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
) => void,
|
) => void,
|
||||||
loading: boolean
|
loading: boolean
|
||||||
};
|
};
|
||||||
@@ -28,7 +28,7 @@ class DeletePermissionButton extends React.Component<Props> {
|
|||||||
this.props.deletePermission(
|
this.props.deletePermission(
|
||||||
this.props.permission,
|
this.props.permission,
|
||||||
this.props.namespace,
|
this.props.namespace,
|
||||||
this.props.name
|
this.props.repoName
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ import {
|
|||||||
isFetchPermissionsPending,
|
isFetchPermissionsPending,
|
||||||
getPermissionsOfRepo,
|
getPermissionsOfRepo,
|
||||||
hasCreatePermission,
|
hasCreatePermission,
|
||||||
createPermission
|
createPermission,
|
||||||
|
isCreatePermissionPending
|
||||||
} from "../modules/permissions";
|
} from "../modules/permissions";
|
||||||
import Loading from "../../components/Loading";
|
import Loading from "../../components/Loading";
|
||||||
import ErrorPage from "../../components/ErrorPage";
|
import ErrorPage from "../../components/ErrorPage";
|
||||||
@@ -18,18 +19,19 @@ import CreatePermissionForm from "../components/CreatePermissionForm";
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string,
|
repoName: string,
|
||||||
loading: boolean,
|
loading: boolean,
|
||||||
error: Error,
|
error: Error,
|
||||||
permissions: PermissionCollection,
|
permissions: PermissionCollection,
|
||||||
createPermission: boolean,
|
hasPermissionToCreate: boolean,
|
||||||
|
loadingCreatePermission: boolean,
|
||||||
|
|
||||||
//dispatch functions
|
//dispatch functions
|
||||||
fetchPermissions: (namespace: string, name: string) => void,
|
fetchPermissions: (namespace: string, repoName: string) => void,
|
||||||
createPermission: (
|
createPermission: (
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
) => void,
|
) => void,
|
||||||
|
|
||||||
// context props
|
// context props
|
||||||
@@ -39,9 +41,9 @@ type Props = {
|
|||||||
|
|
||||||
class Permissions extends React.Component<Props> {
|
class Permissions extends React.Component<Props> {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { fetchPermissions, namespace, name } = this.props;
|
const { fetchPermissions, namespace, repoName } = this.props;
|
||||||
|
|
||||||
fetchPermissions(namespace, name);
|
fetchPermissions(namespace, repoName);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -51,8 +53,9 @@ class Permissions extends React.Component<Props> {
|
|||||||
permissions,
|
permissions,
|
||||||
t,
|
t,
|
||||||
namespace,
|
namespace,
|
||||||
name,
|
repoName,
|
||||||
createPermission
|
loadingCreatePermission,
|
||||||
|
hasPermissionToCreate
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -69,11 +72,12 @@ class Permissions extends React.Component<Props> {
|
|||||||
return <Loading />;
|
return <Loading />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const createPermissionForm = createPermission ? (
|
const createPermissionForm = hasPermissionToCreate ? (
|
||||||
<CreatePermissionForm
|
<CreatePermissionForm
|
||||||
createPermission={permission =>
|
createPermission={permission =>
|
||||||
this.props.createPermission(permission, namespace, name)
|
this.props.createPermission(permission, namespace, repoName)
|
||||||
}
|
}
|
||||||
|
loading={loadingCreatePermission}
|
||||||
/>
|
/>
|
||||||
) : null;
|
) : null;
|
||||||
|
|
||||||
@@ -94,7 +98,7 @@ class Permissions extends React.Component<Props> {
|
|||||||
<SinglePermission
|
<SinglePermission
|
||||||
key={index}
|
key={index}
|
||||||
namespace={namespace}
|
namespace={namespace}
|
||||||
name={name}
|
repoName={repoName}
|
||||||
permission={permission}
|
permission={permission}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -111,33 +115,39 @@ class Permissions extends React.Component<Props> {
|
|||||||
|
|
||||||
const mapStateToProps = (state, ownProps) => {
|
const mapStateToProps = (state, ownProps) => {
|
||||||
const namespace = ownProps.namespace;
|
const namespace = ownProps.namespace;
|
||||||
const name = ownProps.name;
|
const repoName = ownProps.repoName;
|
||||||
const error = getFetchPermissionsFailure(state, namespace, name);
|
const error = getFetchPermissionsFailure(state, namespace, repoName);
|
||||||
const loading = isFetchPermissionsPending(state, namespace, name);
|
const loading = isFetchPermissionsPending(state, namespace, repoName);
|
||||||
const permissions = getPermissionsOfRepo(state, namespace, name);
|
const permissions = getPermissionsOfRepo(state, namespace, repoName);
|
||||||
|
const loadingCreatePermission = isCreatePermissionPending(
|
||||||
|
state,
|
||||||
|
namespace,
|
||||||
|
repoName
|
||||||
|
);
|
||||||
console.log(permissions);
|
console.log(permissions);
|
||||||
const createPermission = hasCreatePermission(state, namespace, name);
|
const hasPermissionToCreate = hasCreatePermission(state, namespace, repoName);
|
||||||
return {
|
return {
|
||||||
namespace,
|
namespace,
|
||||||
name,
|
repoName,
|
||||||
error,
|
error,
|
||||||
loading,
|
loading,
|
||||||
permissions,
|
permissions,
|
||||||
createPermission
|
hasPermissionToCreate,
|
||||||
|
loadingCreatePermission
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => {
|
const mapDispatchToProps = dispatch => {
|
||||||
return {
|
return {
|
||||||
fetchPermissions: (namespace: string, name: string) => {
|
fetchPermissions: (namespace: string, repoName: string) => {
|
||||||
dispatch(fetchPermissions(namespace, name));
|
dispatch(fetchPermissions(namespace, repoName));
|
||||||
},
|
},
|
||||||
createPermission: (
|
createPermission: (
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
) => {
|
) => {
|
||||||
dispatch(createPermission(permission, namespace, name));
|
dispatch(createPermission(permission, namespace, repoName));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import React from "react";
|
|||||||
import type { Permission } from "../types/Permissions";
|
import type { Permission } from "../types/Permissions";
|
||||||
import { Checkbox } from "../../components/forms/index";
|
import { Checkbox } from "../../components/forms/index";
|
||||||
import { translate } from "react-i18next";
|
import { translate } from "react-i18next";
|
||||||
import { Select } from "../../components/forms/index";
|
|
||||||
import {
|
import {
|
||||||
modifyPermission,
|
modifyPermission,
|
||||||
isModifyPermissionPending,
|
isModifyPermissionPending,
|
||||||
@@ -26,7 +25,7 @@ type Props = {
|
|||||||
permission: Permission,
|
permission: Permission,
|
||||||
t: string => string,
|
t: string => string,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string,
|
repoName: string,
|
||||||
match: any,
|
match: any,
|
||||||
history: History,
|
history: History,
|
||||||
loading: boolean,
|
loading: boolean,
|
||||||
@@ -58,7 +57,7 @@ class SinglePermission extends React.Component<Props, State> {
|
|||||||
const { permission } = this.props;
|
const { permission } = this.props;
|
||||||
this.props.permissionReset(
|
this.props.permissionReset(
|
||||||
this.props.namespace,
|
this.props.namespace,
|
||||||
this.props.name,
|
this.props.repoName,
|
||||||
permission.name
|
permission.name
|
||||||
);
|
);
|
||||||
if (permission) {
|
if (permission) {
|
||||||
@@ -77,15 +76,13 @@ class SinglePermission extends React.Component<Props, State> {
|
|||||||
this.props.deletePermission(
|
this.props.deletePermission(
|
||||||
this.props.permission,
|
this.props.permission,
|
||||||
this.props.namespace,
|
this.props.namespace,
|
||||||
this.props.name
|
this.props.repoName
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { permission } = this.state;
|
const { permission } = this.state;
|
||||||
const { t, loading, error, namespace, name } = this.props;
|
const { loading, error, namespace, repoName } = this.props;
|
||||||
const types = ["READ", "OWNER", "WRITE"];
|
|
||||||
|
|
||||||
const typeSelector = this.props.permission._links.update ? (
|
const typeSelector = this.props.permission._links.update ? (
|
||||||
<td>
|
<td>
|
||||||
<TypeSelector
|
<TypeSelector
|
||||||
@@ -113,7 +110,7 @@ class SinglePermission extends React.Component<Props, State> {
|
|||||||
<DeletePermissionButton
|
<DeletePermissionButton
|
||||||
permission={permission}
|
permission={permission}
|
||||||
namespace={namespace}
|
namespace={namespace}
|
||||||
name={name}
|
repoName={repoName}
|
||||||
deletePermission={this.deletePermission}
|
deletePermission={this.deletePermission}
|
||||||
loading={this.props.deleteLoading}
|
loading={this.props.deleteLoading}
|
||||||
/>
|
/>
|
||||||
@@ -139,7 +136,7 @@ class SinglePermission extends React.Component<Props, State> {
|
|||||||
this.props.modifyPermission(
|
this.props.modifyPermission(
|
||||||
permission,
|
permission,
|
||||||
this.props.namespace,
|
this.props.namespace,
|
||||||
this.props.name
|
this.props.repoName
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -159,26 +156,26 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
const loading = isModifyPermissionPending(
|
const loading = isModifyPermissionPending(
|
||||||
state,
|
state,
|
||||||
ownProps.namespace,
|
ownProps.namespace,
|
||||||
ownProps.name,
|
ownProps.repoName,
|
||||||
permission.name
|
permission.name
|
||||||
);
|
);
|
||||||
const error =
|
const error =
|
||||||
getModifyPermissionFailure(
|
getModifyPermissionFailure(
|
||||||
state,
|
state,
|
||||||
ownProps.namespace,
|
ownProps.namespace,
|
||||||
ownProps.name,
|
ownProps.repoName,
|
||||||
permission.name
|
permission.name
|
||||||
) ||
|
) ||
|
||||||
getDeletePermissionFailure(
|
getDeletePermissionFailure(
|
||||||
state,
|
state,
|
||||||
ownProps.namespace,
|
ownProps.namespace,
|
||||||
ownProps.name,
|
ownProps.repoName,
|
||||||
permission.name
|
permission.name
|
||||||
);
|
);
|
||||||
const deleteLoading = isDeletePermissionPending(
|
const deleteLoading = isDeletePermissionPending(
|
||||||
state,
|
state,
|
||||||
ownProps.namespace,
|
ownProps.namespace,
|
||||||
ownProps.name,
|
ownProps.repoName,
|
||||||
permission.name
|
permission.name
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -190,23 +187,23 @@ const mapDispatchToProps = dispatch => {
|
|||||||
modifyPermission: (
|
modifyPermission: (
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
) => {
|
) => {
|
||||||
dispatch(modifyPermission(permission, namespace, name));
|
dispatch(modifyPermission(permission, namespace, repoName));
|
||||||
},
|
},
|
||||||
permissionReset: (
|
permissionReset: (
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string,
|
repoName: string,
|
||||||
permissionname: string
|
permissionname: string
|
||||||
) => {
|
) => {
|
||||||
dispatch(modifyPermissionReset(namespace, name, permissionname));
|
dispatch(modifyPermissionReset(namespace, repoName, permissionname));
|
||||||
},
|
},
|
||||||
deletePermission: (
|
deletePermission: (
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
) => {
|
) => {
|
||||||
dispatch(deletePermission(permission, namespace, name));
|
dispatch(deletePermission(permission, namespace, repoName));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -57,60 +57,60 @@ const CONTENT_TYPE = "application/vnd.scmm-permission+json";
|
|||||||
|
|
||||||
// fetch permissions
|
// fetch permissions
|
||||||
|
|
||||||
export function fetchPermissions(namespace: string, name: string) {
|
export function fetchPermissions(namespace: string, repoName: string) {
|
||||||
return function(dispatch: any) {
|
return function(dispatch: any) {
|
||||||
dispatch(fetchPermissionsPending(namespace, name));
|
dispatch(fetchPermissionsPending(namespace, repoName));
|
||||||
return apiClient
|
return apiClient
|
||||||
.get(`${REPOS_URL}/${namespace}/${name}/${PERMISSIONS_URL}`)
|
.get(`${REPOS_URL}/${namespace}/${repoName}/${PERMISSIONS_URL}`)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(permissions => {
|
.then(permissions => {
|
||||||
dispatch(fetchPermissionsSuccess(permissions, namespace, name));
|
dispatch(fetchPermissionsSuccess(permissions, namespace, repoName));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
dispatch(fetchPermissionsFailure(namespace, name, err));
|
dispatch(fetchPermissionsFailure(namespace, repoName, err));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchPermissionsPending(
|
export function fetchPermissionsPending(
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
): Action {
|
): Action {
|
||||||
return {
|
return {
|
||||||
type: FETCH_PERMISSIONS_PENDING,
|
type: FETCH_PERMISSIONS_PENDING,
|
||||||
payload: {
|
payload: {
|
||||||
namespace,
|
namespace,
|
||||||
name
|
repoName
|
||||||
},
|
},
|
||||||
itemId: namespace + "/" + name
|
itemId: namespace + "/" + repoName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchPermissionsSuccess(
|
export function fetchPermissionsSuccess(
|
||||||
permissions: any,
|
permissions: any,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
): Action {
|
): Action {
|
||||||
return {
|
return {
|
||||||
type: FETCH_PERMISSIONS_SUCCESS,
|
type: FETCH_PERMISSIONS_SUCCESS,
|
||||||
payload: permissions,
|
payload: permissions,
|
||||||
itemId: namespace + "/" + name
|
itemId: namespace + "/" + repoName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchPermissionsFailure(
|
export function fetchPermissionsFailure(
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string,
|
repoName: string,
|
||||||
error: Error
|
error: Error
|
||||||
): Action {
|
): Action {
|
||||||
return {
|
return {
|
||||||
type: FETCH_PERMISSIONS_FAILURE,
|
type: FETCH_PERMISSIONS_FAILURE,
|
||||||
payload: {
|
payload: {
|
||||||
namespace,
|
namespace,
|
||||||
name,
|
repoName,
|
||||||
error
|
error
|
||||||
},
|
},
|
||||||
itemId: namespace + "/" + name
|
itemId: namespace + "/" + repoName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,15 +119,15 @@ export function fetchPermissionsFailure(
|
|||||||
export function modifyPermission(
|
export function modifyPermission(
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string,
|
repoName: string,
|
||||||
callback?: () => void
|
callback?: () => void
|
||||||
) {
|
) {
|
||||||
return function(dispatch: any) {
|
return function(dispatch: any) {
|
||||||
dispatch(modifyPermissionPending(permission, namespace, name));
|
dispatch(modifyPermissionPending(permission, namespace, repoName));
|
||||||
return apiClient
|
return apiClient
|
||||||
.put(permission._links.update.href, permission, CONTENT_TYPE)
|
.put(permission._links.update.href, permission, CONTENT_TYPE)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
dispatch(modifyPermissionSuccess(permission, namespace, name));
|
dispatch(modifyPermissionSuccess(permission, namespace, repoName));
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
@@ -136,7 +136,7 @@ export function modifyPermission(
|
|||||||
const error = new Error(
|
const error = new Error(
|
||||||
`failed to modify permission: ${cause.message}`
|
`failed to modify permission: ${cause.message}`
|
||||||
);
|
);
|
||||||
dispatch(modifyPermissionFailure(permission, error, namespace, name));
|
dispatch(modifyPermissionFailure(permission, error, namespace, repoName));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -144,27 +144,27 @@ export function modifyPermission(
|
|||||||
export function modifyPermissionPending(
|
export function modifyPermissionPending(
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
): Action {
|
): Action {
|
||||||
return {
|
return {
|
||||||
type: MODIFY_PERMISSION_PENDING,
|
type: MODIFY_PERMISSION_PENDING,
|
||||||
payload: permission,
|
payload: permission,
|
||||||
itemId: namespace + "/" + name + "/" + permission.name
|
itemId: namespace + "/" + repoName + "/" + permission.name
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function modifyPermissionSuccess(
|
export function modifyPermissionSuccess(
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
): Action {
|
): Action {
|
||||||
return {
|
return {
|
||||||
type: MODIFY_PERMISSION_SUCCESS,
|
type: MODIFY_PERMISSION_SUCCESS,
|
||||||
payload: {
|
payload: {
|
||||||
permission,
|
permission,
|
||||||
position: namespace + "/" + name
|
position: namespace + "/" + repoName
|
||||||
},
|
},
|
||||||
itemId: namespace + "/" + name + "/" + permission.name
|
itemId: namespace + "/" + repoName + "/" + permission.name
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,12 +172,12 @@ export function modifyPermissionFailure(
|
|||||||
permission: Permission,
|
permission: Permission,
|
||||||
error: Error,
|
error: Error,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
): Action {
|
): Action {
|
||||||
return {
|
return {
|
||||||
type: MODIFY_PERMISSION_FAILURE,
|
type: MODIFY_PERMISSION_FAILURE,
|
||||||
payload: { error, permission },
|
payload: { error, permission },
|
||||||
itemId: namespace + "/" + name + "/" + permission.name
|
itemId: namespace + "/" + repoName + "/" + permission.name
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,12 +195,12 @@ function newPermissions(
|
|||||||
|
|
||||||
export function modifyPermissionReset(
|
export function modifyPermissionReset(
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string,
|
repoName: string,
|
||||||
permissionname: string
|
permissionname: string
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
type: MODIFY_PERMISSION_RESET,
|
type: MODIFY_PERMISSION_RESET,
|
||||||
itemId: namespace + "/" + name + "/" + permissionname
|
itemId: namespace + "/" + repoName + "/" + permissionname
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,19 +208,19 @@ export function modifyPermissionReset(
|
|||||||
export function createPermission(
|
export function createPermission(
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string,
|
repoName: string,
|
||||||
callback?: () => void
|
callback?: () => void
|
||||||
) {
|
) {
|
||||||
return function(dispatch: Dispatch) {
|
return function(dispatch: Dispatch) {
|
||||||
dispatch(createPermissionPending(permission, namespace, name));
|
dispatch(createPermissionPending(permission, namespace, repoName));
|
||||||
return apiClient
|
return apiClient
|
||||||
.post(
|
.post(
|
||||||
`${REPOS_URL}/${namespace}/${name}/${PERMISSIONS_URL}`,
|
`${REPOS_URL}/${namespace}/${repoName}/${PERMISSIONS_URL}`,
|
||||||
permission,
|
permission,
|
||||||
CONTENT_TYPE
|
CONTENT_TYPE
|
||||||
)
|
)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
dispatch(createPermissionSuccess(permission, namespace, name));
|
dispatch(createPermissionSuccess(permission, namespace, repoName));
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
@@ -232,7 +232,7 @@ export function createPermission(
|
|||||||
`failed to add permission ${permission.name}: ${err.message}`
|
`failed to add permission ${permission.name}: ${err.message}`
|
||||||
),
|
),
|
||||||
namespace,
|
namespace,
|
||||||
name
|
repoName
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -242,39 +242,39 @@ export function createPermission(
|
|||||||
export function createPermissionPending(
|
export function createPermissionPending(
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
): Action {
|
): Action {
|
||||||
return {
|
return {
|
||||||
type: CREATE_PERMISSION_PENDING,
|
type: CREATE_PERMISSION_PENDING,
|
||||||
payload: permission,
|
payload: permission,
|
||||||
itemId: namespace + "/" + name
|
itemId: namespace + "/" + repoName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createPermissionSuccess(
|
export function createPermissionSuccess(
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
): Action {
|
): Action {
|
||||||
return {
|
return {
|
||||||
type: CREATE_PERMISSION_SUCCESS,
|
type: CREATE_PERMISSION_SUCCESS,
|
||||||
payload: {
|
payload: {
|
||||||
permission,
|
permission,
|
||||||
position: namespace + "/" + name
|
position: namespace + "/" + repoName
|
||||||
},
|
},
|
||||||
itemId: namespace + "/" + name
|
itemId: namespace + "/" + repoName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createPermissionFailure(
|
export function createPermissionFailure(
|
||||||
error: Error,
|
error: Error,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
): Action {
|
): Action {
|
||||||
return {
|
return {
|
||||||
type: CREATE_PERMISSION_FAILURE,
|
type: CREATE_PERMISSION_FAILURE,
|
||||||
payload: error,
|
payload: error,
|
||||||
itemId: namespace + "/" + name
|
itemId: namespace + "/" + repoName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,15 +283,15 @@ export function createPermissionFailure(
|
|||||||
export function deletePermission(
|
export function deletePermission(
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string,
|
repoName: string,
|
||||||
callback?: () => void
|
callback?: () => void
|
||||||
) {
|
) {
|
||||||
return function(dispatch: any) {
|
return function(dispatch: any) {
|
||||||
dispatch(deletePermissionPending(permission, namespace, name));
|
dispatch(deletePermissionPending(permission, namespace, repoName));
|
||||||
return apiClient
|
return apiClient
|
||||||
.delete(permission._links.delete.href)
|
.delete(permission._links.delete.href)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
dispatch(deletePermissionSuccess(permission, namespace, name));
|
dispatch(deletePermissionSuccess(permission, namespace, repoName));
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
@@ -300,7 +300,7 @@ export function deletePermission(
|
|||||||
const error = new Error(
|
const error = new Error(
|
||||||
`could not delete permission ${permission.name}: ${cause.message}`
|
`could not delete permission ${permission.name}: ${cause.message}`
|
||||||
);
|
);
|
||||||
dispatch(deletePermissionFailure(permission, namespace, name, error));
|
dispatch(deletePermissionFailure(permission, namespace, repoName, error));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -308,34 +308,34 @@ export function deletePermission(
|
|||||||
export function deletePermissionPending(
|
export function deletePermissionPending(
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
): Action {
|
): Action {
|
||||||
return {
|
return {
|
||||||
type: DELETE_PERMISSION_PENDING,
|
type: DELETE_PERMISSION_PENDING,
|
||||||
payload: permission,
|
payload: permission,
|
||||||
itemId: namespace + "/" + name + "/" + permission.name
|
itemId: namespace + "/" + repoName + "/" + permission.name
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deletePermissionSuccess(
|
export function deletePermissionSuccess(
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
): Action {
|
): Action {
|
||||||
return {
|
return {
|
||||||
type: DELETE_PERMISSION_SUCCESS,
|
type: DELETE_PERMISSION_SUCCESS,
|
||||||
payload: {
|
payload: {
|
||||||
permission,
|
permission,
|
||||||
position: namespace + "/" + name
|
position: namespace + "/" + repoName
|
||||||
},
|
},
|
||||||
itemId: namespace + "/" + name + "/" + permission.name
|
itemId: namespace + "/" + repoName + "/" + permission.name
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deletePermissionFailure(
|
export function deletePermissionFailure(
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string,
|
repoName: string,
|
||||||
error: Error
|
error: Error
|
||||||
): Action {
|
): Action {
|
||||||
return {
|
return {
|
||||||
@@ -344,7 +344,7 @@ export function deletePermissionFailure(
|
|||||||
error,
|
error,
|
||||||
permission
|
permission
|
||||||
},
|
},
|
||||||
itemId: namespace + "/" + name + "/" + permission.name
|
itemId: namespace + "/" + repoName + "/" + permission.name
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,10 +425,10 @@ export default function reducer(
|
|||||||
export function getPermissionsOfRepo(
|
export function getPermissionsOfRepo(
|
||||||
state: Object,
|
state: Object,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
) {
|
) {
|
||||||
if (state.permissions && state.permissions[namespace + "/" + name]) {
|
if (state.permissions && state.permissions[namespace + "/" + repoName]) {
|
||||||
const permissions = state.permissions[namespace + "/" + name].entries;
|
const permissions = state.permissions[namespace + "/" + repoName].entries;
|
||||||
return permissions;
|
return permissions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -436,77 +436,100 @@ export function getPermissionsOfRepo(
|
|||||||
export function isFetchPermissionsPending(
|
export function isFetchPermissionsPending(
|
||||||
state: Object,
|
state: Object,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
) {
|
) {
|
||||||
return isPending(state, FETCH_PERMISSIONS, namespace + "/" + name);
|
return isPending(state, FETCH_PERMISSIONS, namespace + "/" + repoName);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFetchPermissionsFailure(
|
export function getFetchPermissionsFailure(
|
||||||
state: Object,
|
state: Object,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
) {
|
) {
|
||||||
return getFailure(state, FETCH_PERMISSIONS, namespace + "/" + name);
|
return getFailure(state, FETCH_PERMISSIONS, namespace + "/" + repoName);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isModifyPermissionPending(
|
export function isModifyPermissionPending(
|
||||||
state: Object,
|
state: Object,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string,
|
repoName: string,
|
||||||
permissionname: string
|
permissionname: string
|
||||||
) {
|
) {
|
||||||
return isPending(
|
return isPending(
|
||||||
state,
|
state,
|
||||||
MODIFY_PERMISSION,
|
MODIFY_PERMISSION,
|
||||||
namespace + "/" + name + "/" + permissionname
|
namespace + "/" + repoName + "/" + permissionname
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getModifyPermissionFailure(
|
export function getModifyPermissionFailure(
|
||||||
state: Object,
|
state: Object,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string,
|
repoName: string,
|
||||||
permissionname: string
|
permissionname: string
|
||||||
) {
|
) {
|
||||||
return getFailure(
|
return getFailure(
|
||||||
state,
|
state,
|
||||||
MODIFY_PERMISSION,
|
MODIFY_PERMISSION,
|
||||||
namespace + "/" + name + "/" + permissionname
|
namespace + "/" + repoName + "/" + permissionname
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hasCreatePermission(
|
export function hasCreatePermission(
|
||||||
state: Object,
|
state: Object,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string
|
repoName: string
|
||||||
) {
|
) {
|
||||||
if (state.permissions && state.permissions[namespace + "/" + name])
|
if (state.permissions && state.permissions[namespace + "/" + repoName])
|
||||||
return state.permissions[namespace + "/" + name].createPermission;
|
return state.permissions[namespace + "/" + repoName].createPermission;
|
||||||
else return null;
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
) {
|
||||||
|
return getFailure(
|
||||||
|
state,
|
||||||
|
CREATE_PERMISSION,
|
||||||
|
namespace + "/" + repoName
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function isDeletePermissionPending(
|
export function isDeletePermissionPending(
|
||||||
state: Object,
|
state: Object,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string,
|
repoName: string,
|
||||||
permissionname: string
|
permissionname: string
|
||||||
) {
|
) {
|
||||||
return isPending(
|
return isPending(
|
||||||
state,
|
state,
|
||||||
DELETE_PERMISSION,
|
DELETE_PERMISSION,
|
||||||
namespace + "/" + name + "/" + permissionname
|
namespace + "/" + repoName + "/" + permissionname
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDeletePermissionFailure(
|
export function getDeletePermissionFailure(
|
||||||
state: Object,
|
state: Object,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
name: string,
|
repoName: string,
|
||||||
permissionname: string
|
permissionname: string
|
||||||
) {
|
) {
|
||||||
return getFailure(
|
return getFailure(
|
||||||
state,
|
state,
|
||||||
DELETE_PERMISSION,
|
DELETE_PERMISSION,
|
||||||
namespace + "/" + name + "/" + permissionname
|
namespace + "/" + repoName + "/" + permissionname
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,10 @@ import reducer, {
|
|||||||
DELETE_PERMISSION_PENDING,
|
DELETE_PERMISSION_PENDING,
|
||||||
DELETE_PERMISSION_SUCCESS,
|
DELETE_PERMISSION_SUCCESS,
|
||||||
DELETE_PERMISSION_FAILURE,
|
DELETE_PERMISSION_FAILURE,
|
||||||
createPermissionSuccess
|
CREATE_PERMISSION,
|
||||||
|
createPermissionSuccess,
|
||||||
|
getCreatePermissionFailure,
|
||||||
|
isCreatePermissionPending
|
||||||
} from "./permissions";
|
} from "./permissions";
|
||||||
import type { Permission, PermissionCollection } from "../types/Permissions";
|
import type { Permission, PermissionCollection } from "../types/Permissions";
|
||||||
|
|
||||||
@@ -113,7 +116,7 @@ describe("permission fetch", () => {
|
|||||||
type: FETCH_PERMISSIONS_PENDING,
|
type: FETCH_PERMISSIONS_PENDING,
|
||||||
payload: {
|
payload: {
|
||||||
namespace: "hitchhiker",
|
namespace: "hitchhiker",
|
||||||
name: "puzzle42"
|
repoName: "puzzle42"
|
||||||
},
|
},
|
||||||
itemId: "hitchhiker/puzzle42"
|
itemId: "hitchhiker/puzzle42"
|
||||||
},
|
},
|
||||||
@@ -636,4 +639,38 @@ describe("permissions selectors", () => {
|
|||||||
getDeletePermissionFailure({}, "hitchhiker", "puzzle42", "user_eins")
|
getDeletePermissionFailure({}, "hitchhiker", "puzzle42", "user_eins")
|
||||||
).toBe(undefined);
|
).toBe(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should return true, when create permission is pending", () => {
|
||||||
|
const state = {
|
||||||
|
pending: {
|
||||||
|
[CREATE_PERMISSION + "/hitchhiker/puzzle42"]: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
expect(isCreatePermissionPending(state, "hitchhiker", "puzzle42")).toEqual(
|
||||||
|
true
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return false, when create permissions is not pending", () => {
|
||||||
|
expect(isCreatePermissionPending({}, "hitchiker", "puzzle42")).toEqual(
|
||||||
|
false
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return error when create permissions did fail", () => {
|
||||||
|
const state = {
|
||||||
|
failure: {
|
||||||
|
[CREATE_PERMISSION + "/hitchhiker/puzzle42"]: error
|
||||||
|
}
|
||||||
|
};
|
||||||
|
expect(getCreatePermissionFailure(state, "hitchhiker", "puzzle42")).toEqual(
|
||||||
|
error
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return undefined when create permissions did not fail", () => {
|
||||||
|
expect(getCreatePermissionFailure({}, "hitchhiker", "puzzle42")).toBe(
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ class RepositoryRoot extends React.Component<Props> {
|
|||||||
component={() => (
|
component={() => (
|
||||||
<Permissions
|
<Permissions
|
||||||
namespace={repository.namespace}
|
namespace={repository.namespace}
|
||||||
name={repository.name}
|
repoName={repository.name}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user