mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
use only one reset state for all permissions
This commit is contained in:
@@ -13,6 +13,20 @@ function extractIdentifierFromFailure(action: Action) {
|
|||||||
return identifier;
|
return identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeAllEntriesOfIdentifierFromState(
|
||||||
|
state: Object,
|
||||||
|
payload: any,
|
||||||
|
identifier: string
|
||||||
|
) {
|
||||||
|
const newState = {};
|
||||||
|
for (let failureType in state) {
|
||||||
|
if (failureType !== identifier && !failureType.startsWith(identifier)) {
|
||||||
|
newState[failureType] = state[failureType];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newState;
|
||||||
|
}
|
||||||
|
|
||||||
function removeFromState(state: Object, identifier: string) {
|
function removeFromState(state: Object, identifier: string) {
|
||||||
const newState = {};
|
const newState = {};
|
||||||
for (let failureType in state) {
|
for (let failureType in state) {
|
||||||
@@ -47,7 +61,9 @@ export default function reducer(
|
|||||||
if (action.itemId) {
|
if (action.itemId) {
|
||||||
identifier += "/" + action.itemId;
|
identifier += "/" + action.itemId;
|
||||||
}
|
}
|
||||||
return removeFromState(state, identifier);
|
if (action.payload)
|
||||||
|
return removeAllEntriesOfIdentifierFromState(state, action.payload, identifier);
|
||||||
|
else return removeFromState(state, identifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
|
|||||||
@@ -19,6 +19,20 @@ function removeFromState(state: Object, identifier: string) {
|
|||||||
return newState;
|
return newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeAllEntriesOfIdentifierFromState(
|
||||||
|
state: Object,
|
||||||
|
payload: any,
|
||||||
|
identifier: string
|
||||||
|
) {
|
||||||
|
const newState = {};
|
||||||
|
for (let childType in state) {
|
||||||
|
if (childType !== identifier && !childType.startsWith(identifier)) {
|
||||||
|
newState[childType] = state[childType];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newState;
|
||||||
|
}
|
||||||
|
|
||||||
function extractIdentifierFromPending(action: Action) {
|
function extractIdentifierFromPending(action: Action) {
|
||||||
const type = action.type;
|
const type = action.type;
|
||||||
let identifier = type.substring(0, type.length - PENDING_SUFFIX.length);
|
let identifier = type.substring(0, type.length - PENDING_SUFFIX.length);
|
||||||
@@ -48,6 +62,9 @@ export default function reducer(
|
|||||||
if (action.itemId) {
|
if (action.itemId) {
|
||||||
identifier += "/" + action.itemId;
|
identifier += "/" + action.itemId;
|
||||||
}
|
}
|
||||||
|
if (action.payload)
|
||||||
|
return removeAllEntriesOfIdentifierFromState(state, action.payload, identifier);
|
||||||
|
else
|
||||||
return removeFromState(state, identifier);
|
return removeFromState(state, identifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ import {
|
|||||||
isCreatePermissionPending,
|
isCreatePermissionPending,
|
||||||
getCreatePermissionFailure,
|
getCreatePermissionFailure,
|
||||||
createPermissionReset,
|
createPermissionReset,
|
||||||
getDeletePermissionsFailure, getModifyPermissionsFailure
|
getDeletePermissionsFailure,
|
||||||
|
getModifyPermissionsFailure,
|
||||||
|
modifyPermissionReset,
|
||||||
|
deletePermissionReset
|
||||||
} from "../modules/permissions";
|
} from "../modules/permissions";
|
||||||
import { Loading, ErrorPage } from "@scm-manager/ui-components";
|
import { Loading, ErrorPage } from "@scm-manager/ui-components";
|
||||||
import type {
|
import type {
|
||||||
@@ -42,7 +45,8 @@ type Props = {
|
|||||||
callback?: () => void
|
callback?: () => void
|
||||||
) => void,
|
) => void,
|
||||||
createPermissionReset: (string, string) => void,
|
createPermissionReset: (string, string) => void,
|
||||||
|
modifyPermissionReset: (string, string) => void,
|
||||||
|
deletePermissionReset: (string, string) => void,
|
||||||
// context props
|
// context props
|
||||||
t: string => string,
|
t: string => string,
|
||||||
match: any,
|
match: any,
|
||||||
@@ -55,10 +59,14 @@ class Permissions extends React.Component<Props> {
|
|||||||
fetchPermissions,
|
fetchPermissions,
|
||||||
namespace,
|
namespace,
|
||||||
repoName,
|
repoName,
|
||||||
createPermissionReset
|
modifyPermissionReset,
|
||||||
|
createPermissionReset,
|
||||||
|
deletePermissionReset
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
createPermissionReset(namespace, repoName);
|
createPermissionReset(namespace, repoName);
|
||||||
|
modifyPermissionReset(namespace, repoName);
|
||||||
|
deletePermissionReset(namespace, repoName);
|
||||||
fetchPermissions(namespace, repoName);
|
fetchPermissions(namespace, repoName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,6 +182,12 @@ const mapDispatchToProps = dispatch => {
|
|||||||
},
|
},
|
||||||
createPermissionReset: (namespace: string, repoName: string) => {
|
createPermissionReset: (namespace: string, repoName: string) => {
|
||||||
dispatch(createPermissionReset(namespace, repoName));
|
dispatch(createPermissionReset(namespace, repoName));
|
||||||
|
},
|
||||||
|
modifyPermissionReset: (namespace: string, repoName: string) => {
|
||||||
|
dispatch(modifyPermissionReset(namespace, repoName));
|
||||||
|
},
|
||||||
|
deletePermissionReset: (namespace: string, repoName: string) => {
|
||||||
|
dispatch(deletePermissionReset(namespace, repoName));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,10 +5,8 @@ import { translate } from "react-i18next";
|
|||||||
import {
|
import {
|
||||||
modifyPermission,
|
modifyPermission,
|
||||||
isModifyPermissionPending,
|
isModifyPermissionPending,
|
||||||
modifyPermissionReset,
|
|
||||||
deletePermission,
|
deletePermission,
|
||||||
isDeletePermissionPending,
|
isDeletePermissionPending
|
||||||
deletePermissionReset
|
|
||||||
} from "../modules/permissions";
|
} from "../modules/permissions";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import type { History } from "history";
|
import type { History } from "history";
|
||||||
@@ -26,8 +24,6 @@ type Props = {
|
|||||||
match: any,
|
match: any,
|
||||||
history: History,
|
history: History,
|
||||||
loading: boolean,
|
loading: boolean,
|
||||||
permissionReset: (string, string, string) => void,
|
|
||||||
deletePermissionReset: (string, string, string) => void,
|
|
||||||
deletePermission: (Permission, string, string) => void,
|
deletePermission: (Permission, string, string) => void,
|
||||||
deleteLoading: boolean
|
deleteLoading: boolean
|
||||||
};
|
};
|
||||||
@@ -52,16 +48,6 @@ class SinglePermission extends React.Component<Props, State> {
|
|||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { permission } = this.props;
|
const { permission } = this.props;
|
||||||
this.props.permissionReset(
|
|
||||||
this.props.namespace,
|
|
||||||
this.props.repoName,
|
|
||||||
permission.name
|
|
||||||
);
|
|
||||||
this.props.deletePermissionReset(
|
|
||||||
this.props.namespace,
|
|
||||||
this.props.repoName,
|
|
||||||
permission.name
|
|
||||||
);
|
|
||||||
if (permission) {
|
if (permission) {
|
||||||
this.setState({
|
this.setState({
|
||||||
permission: {
|
permission: {
|
||||||
@@ -175,26 +161,12 @@ const mapDispatchToProps = dispatch => {
|
|||||||
) => {
|
) => {
|
||||||
dispatch(modifyPermission(permission, namespace, repoName));
|
dispatch(modifyPermission(permission, namespace, repoName));
|
||||||
},
|
},
|
||||||
permissionReset: (
|
|
||||||
namespace: string,
|
|
||||||
repoName: string,
|
|
||||||
permissionname: string
|
|
||||||
) => {
|
|
||||||
dispatch(modifyPermissionReset(namespace, repoName, permissionname));
|
|
||||||
},
|
|
||||||
deletePermission: (
|
deletePermission: (
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
repoName: string
|
repoName: string
|
||||||
) => {
|
) => {
|
||||||
dispatch(deletePermission(permission, namespace, repoName));
|
dispatch(deletePermission(permission, namespace, repoName));
|
||||||
},
|
|
||||||
deletePermissionReset: (
|
|
||||||
namespace: string,
|
|
||||||
repoName: string,
|
|
||||||
permissionname: string
|
|
||||||
) => {
|
|
||||||
dispatch(deletePermissionReset(namespace, repoName, permissionname));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -206,14 +206,14 @@ function newPermissions(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function modifyPermissionReset(
|
export function modifyPermissionReset(namespace: string, repoName: string) {
|
||||||
namespace: string,
|
|
||||||
repoName: string,
|
|
||||||
permissionname: string
|
|
||||||
) {
|
|
||||||
return {
|
return {
|
||||||
type: MODIFY_PERMISSION_RESET,
|
type: MODIFY_PERMISSION_RESET,
|
||||||
itemId: namespace + "/" + repoName + "/" + permissionname
|
payload: {
|
||||||
|
namespace,
|
||||||
|
repoName
|
||||||
|
},
|
||||||
|
itemId: namespace + "/" + repoName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,14 +377,14 @@ export function deletePermissionFailure(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deletePermissionReset(
|
export function deletePermissionReset(namespace: string, repoName: string) {
|
||||||
namespace: string,
|
|
||||||
repoName: string,
|
|
||||||
permissionname: string
|
|
||||||
) {
|
|
||||||
return {
|
return {
|
||||||
type: DELETE_PERMISSION_RESET,
|
type: DELETE_PERMISSION_RESET,
|
||||||
itemId: namespace + "/" + repoName + "/" + permissionname
|
payload: {
|
||||||
|
namespace,
|
||||||
|
repoName
|
||||||
|
},
|
||||||
|
itemId: namespace + "/" + repoName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function deletePermissionFromState(
|
function deletePermissionFromState(
|
||||||
@@ -408,7 +408,6 @@ export default function reducer(
|
|||||||
if (!action.payload) {
|
if (!action.payload) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case FETCH_PERMISSIONS_SUCCESS:
|
case FETCH_PERMISSIONS_SUCCESS:
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user