mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
add function for getting an error if one permission has delete error state
This commit is contained in:
@@ -11,7 +11,8 @@ import {
|
|||||||
createPermission,
|
createPermission,
|
||||||
isCreatePermissionPending,
|
isCreatePermissionPending,
|
||||||
getCreatePermissionFailure,
|
getCreatePermissionFailure,
|
||||||
createPermissionReset
|
createPermissionReset,
|
||||||
|
getDeletePermissionsFailure
|
||||||
} 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";
|
||||||
@@ -143,7 +144,7 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
const repoName = ownProps.repoName;
|
const repoName = ownProps.repoName;
|
||||||
const error =
|
const error =
|
||||||
getFetchPermissionsFailure(state, namespace, repoName) ||
|
getFetchPermissionsFailure(state, namespace, repoName) ||
|
||||||
getCreatePermissionFailure(state, namespace, repoName);
|
getCreatePermissionFailure(state, namespace, repoName); //|| getDeletePermissionsFailure(state, namespace, repoName);
|
||||||
const loading = isFetchPermissionsPending(state, namespace, repoName);
|
const loading = isFetchPermissionsPending(state, namespace, repoName);
|
||||||
const permissions = getPermissionsOfRepo(state, namespace, repoName);
|
const permissions = getPermissionsOfRepo(state, namespace, repoName);
|
||||||
const loadingCreatePermission = isCreatePermissionPending(
|
const loadingCreatePermission = isCreatePermissionPending(
|
||||||
|
|||||||
@@ -558,3 +558,32 @@ export function getDeletePermissionFailure(
|
|||||||
namespace + "/" + repoName + "/" + permissionname
|
namespace + "/" + repoName + "/" + permissionname
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getDeletePermissionsFailure(
|
||||||
|
state: Object,
|
||||||
|
namespace: string,
|
||||||
|
repoName: string
|
||||||
|
) {
|
||||||
|
const permissions =
|
||||||
|
state.permissions && state.permissions[namespace + "/" + repoName]
|
||||||
|
? state.permissions[namespace + "/" + repoName].entries
|
||||||
|
: null;
|
||||||
|
if (permissions == null) return undefined;
|
||||||
|
for (let i = 0; i < permissions.length; i++) {
|
||||||
|
if (
|
||||||
|
getDeletePermissionFailure(
|
||||||
|
state,
|
||||||
|
namespace,
|
||||||
|
repoName,
|
||||||
|
permissions[i].name
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return getFailure(
|
||||||
|
state,
|
||||||
|
DELETE_PERMISSION,
|
||||||
|
namespace + "/" + repoName + "/" + permissions[i].name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ import reducer, {
|
|||||||
CREATE_PERMISSION,
|
CREATE_PERMISSION,
|
||||||
createPermissionSuccess,
|
createPermissionSuccess,
|
||||||
getCreatePermissionFailure,
|
getCreatePermissionFailure,
|
||||||
isCreatePermissionPending
|
isCreatePermissionPending,
|
||||||
|
getDeletePermissionsFailure
|
||||||
} from "./permissions";
|
} from "./permissions";
|
||||||
import type { Permission, PermissionCollection } from "../types/Permissions";
|
import type { Permission, PermissionCollection } from "../types/Permissions";
|
||||||
|
|
||||||
@@ -644,6 +645,26 @@ describe("permissions selectors", () => {
|
|||||||
).toBe(undefined);
|
).toBe(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should return error when one of the delete permissions did fail", () => {
|
||||||
|
const state = {
|
||||||
|
permissions: {
|
||||||
|
"hitchhiker/puzzle42": { entries: hitchhiker_puzzle42Permissions }
|
||||||
|
},
|
||||||
|
failure: {
|
||||||
|
[DELETE_PERMISSION + "/hitchhiker/puzzle42/user_eins"]: error
|
||||||
|
}
|
||||||
|
};
|
||||||
|
expect(
|
||||||
|
getDeletePermissionsFailure(state, "hitchhiker", "puzzle42")
|
||||||
|
).toEqual(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return undefined when no delete permissions did not fail", () => {
|
||||||
|
expect(getDeletePermissionsFailure({}, "hitchhiker", "puzzle42")).toBe(
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("should return true, when create permission is pending", () => {
|
it("should return true, when create permission is pending", () => {
|
||||||
const state = {
|
const state = {
|
||||||
pending: {
|
pending: {
|
||||||
|
|||||||
Reference in New Issue
Block a user