From 92079893fa4ea2364f7f3d7563b0e69ad27557fe Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Fri, 28 Aug 2020 01:53:07 +0300 Subject: [PATCH] Add action that enables MRF TagPolicy, update storage of tagPolicies in state --- src/store/modules/users.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/store/modules/users.js b/src/store/modules/users.js index 51e01b6d..da152069 100644 --- a/src/store/modules/users.js +++ b/src/store/modules/users.js @@ -19,14 +19,14 @@ import { resendConfirmationEmail, updateUserCredentials } from '@/api/users' -import { fetchSettings } from '@/api/settings' +import { fetchSettings, updateSettings } from '@/api/settings' const users = { state: { fetchedUsers: [], loading: true, searchQuery: '', - tagPolicyDisabled: false, + tagPolicies: [], totalUsersCount: 0, currentPage: 1, pageSize: 50, @@ -80,8 +80,8 @@ const users = { SET_SEARCH_QUERY: (state, query) => { state.searchQuery = query }, - SET_TAG_POLICY: (state, policyDisabled) => { - state.tagPolicyDisabled = policyDisabled + SET_TAG_POLICY: (state, tagPolicies) => { + state.tagPolicies = tagPolicies }, SET_USERS_FILTERS: (state, filters) => { state.filters = filters @@ -211,14 +211,23 @@ const users = { } 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 }) { 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.tuple[0] === ':policies').tuple[1] - .includes('Pleroma.Web.ActivityPub.MRF.TagPolicy') + .find(el => el.tuple[0] === ':policies').tuple[1] || [] - commit('SET_TAG_POLICY', tagPolicyDisabled) + commit('SET_TAG_POLICY', Array.isArray(tagPolicies) ? tagPolicies : [tagPolicies]) }, async FetchUsers({ commit, dispatch, getters, state }, { page }) { commit('SET_LOADING', true)