@ -1,5 +1,3 @@
|
||||
import { Set as ImmutableSet } from 'immutable';
|
||||
|
||||
import ConfigDB from 'pl-fe/utils/config-db';
|
||||
|
||||
import { fetchConfig, updateConfig } from './admin';
|
||||
@ -11,11 +9,15 @@ const simplePolicyMerge = (simplePolicy: MRFSimple, host: string, restrictions:
|
||||
const entries = Object.entries(simplePolicy).map(([key, hosts]) => {
|
||||
const isRestricted = restrictions[key];
|
||||
|
||||
const set = new Set(hosts);
|
||||
|
||||
if (isRestricted) {
|
||||
return [key, ImmutableSet(hosts).add(host).toJS()];
|
||||
set.add(host);
|
||||
} else {
|
||||
return [key, ImmutableSet(hosts).delete(host).toJS()];
|
||||
set.delete(host);
|
||||
}
|
||||
|
||||
return [key, [...set]];
|
||||
});
|
||||
|
||||
return Object.fromEntries(entries);
|
||||
@ -23,13 +25,12 @@ const simplePolicyMerge = (simplePolicy: MRFSimple, host: string, restrictions:
|
||||
|
||||
const updateMrf = (host: string, restrictions: Record<string, any>) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) =>
|
||||
dispatch(fetchConfig())
|
||||
.then(() => {
|
||||
const configs = getState().admin.get('configs');
|
||||
const simplePolicy = ConfigDB.toSimplePolicy(configs);
|
||||
const merged = simplePolicyMerge(simplePolicy, host, restrictions);
|
||||
const config = ConfigDB.fromSimplePolicy(merged);
|
||||
return dispatch(updateConfig(config));
|
||||
});
|
||||
dispatch(fetchConfig()).then(() => {
|
||||
const configs = getState().admin.get('configs');
|
||||
const simplePolicy = ConfigDB.toSimplePolicy(configs);
|
||||
const merged = simplePolicyMerge(simplePolicy, host, restrictions);
|
||||
const config = ConfigDB.fromSimplePolicy(merged);
|
||||
return dispatch(updateConfig(config));
|
||||
});
|
||||
|
||||
export { updateMrf };
|
||||
|
||||
@ -37,7 +37,7 @@ const toSimplePolicy = (configs: ImmutableList<Config>): MRFSimple => {
|
||||
};
|
||||
|
||||
const fromSimplePolicy = (simplePolicy: Policy)=> {
|
||||
const mapper = ([key, hosts]: [key: string, hosts: ImmutableList<string>]) => ({ tuple: [`:${key}`, hosts.toJS()] });
|
||||
const mapper = ([key, hosts]: [key: string, hosts: ImmutableList<string>]) => ({ tuple: [`:${key}`, hosts] });
|
||||
|
||||
const value = Object.entries(simplePolicy).map(mapper);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user