Add action that enables MRF TagPolicy, update storage of tagPolicies in state

This commit is contained in:
Angelina Filippova 2020-08-28 01:53:07 +03:00
parent b5a3a29539
commit 92079893fa

View file

@ -19,14 +19,14 @@ import {
resendConfirmationEmail, resendConfirmationEmail,
updateUserCredentials updateUserCredentials
} from '@/api/users' } from '@/api/users'
import { fetchSettings } from '@/api/settings' import { fetchSettings, updateSettings } from '@/api/settings'
const users = { const users = {
state: { state: {
fetchedUsers: [], fetchedUsers: [],
loading: true, loading: true,
searchQuery: '', searchQuery: '',
tagPolicyDisabled: false, tagPolicies: [],
totalUsersCount: 0, totalUsersCount: 0,
currentPage: 1, currentPage: 1,
pageSize: 50, pageSize: 50,
@ -80,8 +80,8 @@ const users = {
SET_SEARCH_QUERY: (state, query) => { SET_SEARCH_QUERY: (state, query) => {
state.searchQuery = query state.searchQuery = query
}, },
SET_TAG_POLICY: (state, policyDisabled) => { SET_TAG_POLICY: (state, tagPolicies) => {
state.tagPolicyDisabled = policyDisabled state.tagPolicies = tagPolicies
}, },
SET_USERS_FILTERS: (state, filters) => { SET_USERS_FILTERS: (state, filters) => {
state.filters = filters state.filters = filters
@ -211,14 +211,23 @@ const users = {
} }
dispatch('SuccessMessage') dispatch('SuccessMessage')
}, },
async EnableTagPolicy({ dispatch, getters, state }) {
const configs = [{
group: ':pleroma',
key: ':mrf',
value: [{ tuple: [':policies', [...state.tagPolicies, 'Pleroma.Web.ActivityPub.MRF.TagPolicy']] }]
}]
await updateSettings(configs, getters.authHost, getters.token)
dispatch('FetchTagPolicySetting')
},
async FetchTagPolicySetting({ commit, getters }) { async FetchTagPolicySetting({ commit, getters }) {
const { data } = await fetchSettings(getters.authHost, getters.token) const { data } = await fetchSettings(getters.authHost, getters.token)
const tagPolicyDisabled = !data.configs const tagPolicies = data.configs
.find(el => el.key === ':mrf').value .find(el => el.key === ':mrf').value
.find(el => el.tuple[0] === ':policies').tuple[1] .find(el => el.tuple[0] === ':policies').tuple[1] || []
.includes('Pleroma.Web.ActivityPub.MRF.TagPolicy')
commit('SET_TAG_POLICY', tagPolicyDisabled) commit('SET_TAG_POLICY', Array.isArray(tagPolicies) ? tagPolicies : [tagPolicies])
}, },
async FetchUsers({ commit, dispatch, getters, state }, { page }) { async FetchUsers({ commit, dispatch, getters, state }, { page }) {
commit('SET_LOADING', true) commit('SET_LOADING', true)