bigbuffet-rw/app/soapbox/actions/mrf.js

31 lines
912 B
JavaScript
Raw Normal View History

2021-07-27 12:40:41 -07:00
import { Set as ImmutableSet } from 'immutable';
import ConfigDB from 'soapbox/utils/config_db';
2022-01-10 14:01:24 -08:00
import { fetchConfig, updateConfig } from './admin';
2021-07-27 12:40:41 -07:00
const simplePolicyMerge = (simplePolicy, host, restrictions) => {
return simplePolicy.map((hosts, key) => {
const isRestricted = restrictions.get(key);
if (isRestricted) {
return ImmutableSet(hosts).add(host);
} else {
return ImmutableSet(hosts).delete(host);
}
});
};
export function updateMrf(host, restrictions) {
return (dispatch, getState) => {
return dispatch(fetchConfig())
2021-07-27 12:40:41 -07:00
.then(() => {
const configs = getState().getIn(['admin', 'configs']);
const simplePolicy = ConfigDB.toSimplePolicy(configs);
2021-07-27 12:40:41 -07:00
const merged = simplePolicyMerge(simplePolicy, host, restrictions);
const config = ConfigDB.fromSimplePolicy(merged);
2021-07-27 12:40:41 -07:00
dispatch(updateConfig(config));
});
};
}