Merge branch '716' into 'develop'

Fix "Deactivation of remote accounts from frontend does not work"

Closes #716

See merge request pleroma/pleroma-fe!1006
This commit is contained in:
HJ 2019-12-18 00:51:41 +00:00
commit f7029a27eb
4 changed files with 41 additions and 27 deletions

View File

@ -71,12 +71,7 @@ const ModerationTools = {
} }
}, },
toggleActivationStatus () { toggleActivationStatus () {
const store = this.$store this.$store.dispatch('toggleActivationStatus', this.user)
const status = !!this.user.deactivated
store.state.api.backendInteractor.setActivationStatus(this.user, status).then(response => {
if (!response.ok) { return }
store.commit('updateActivationStatus', { user: this.user, status: status })
})
}, },
deleteUserDialog (show) { deleteUserDialog (show) {
this.showDeleteUserDialog = show this.showDeleteUserDialog = show

View File

@ -95,9 +95,9 @@ export const mutations = {
newRights[right] = value newRights[right] = value
set(user, 'rights', newRights) set(user, 'rights', newRights)
}, },
updateActivationStatus (state, { user: { id }, status }) { updateActivationStatus (state, { user: { id }, deactivated }) {
const user = state.usersObject[id] const user = state.usersObject[id]
set(user, 'deactivated', !status) set(user, 'deactivated', deactivated)
}, },
setCurrentUser (state, user) { setCurrentUser (state, user) {
state.lastLoginName = user.screen_name state.lastLoginName = user.screen_name
@ -331,6 +331,11 @@ const users = {
return rootState.api.backendInteractor.unsubscribeUser(id) return rootState.api.backendInteractor.unsubscribeUser(id)
.then((relationship) => commit('updateUserRelationship', [relationship])) .then((relationship) => commit('updateUserRelationship', [relationship]))
}, },
toggleActivationStatus ({ rootState, commit }, user) {
const api = user.deactivated ? rootState.api.backendInteractor.activateUser : rootState.api.backendInteractor.deactivateUser
api(user)
.then(({ deactivated }) => commit('updateActivationStatus', { user, deactivated }))
},
registerPushNotifications (store) { registerPushNotifications (store) {
const token = store.state.currentUser.credentials const token = store.state.currentUser.credentials
const vapidPublicKey = store.rootState.instance.vapidPublicKey const vapidPublicKey = store.rootState.instance.vapidPublicKey

View File

@ -1,4 +1,4 @@
import { each, map, concat, last } from 'lodash' import { each, map, concat, last, get } from 'lodash'
import { parseStatus, parseUser, parseNotification, parseAttachment } from '../entity_normalizer/entity_normalizer.service.js' import { parseStatus, parseUser, parseNotification, parseAttachment } from '../entity_normalizer/entity_normalizer.service.js'
import 'whatwg-fetch' import 'whatwg-fetch'
import { RegistrationError, StatusCodeError } from '../errors/errors' import { RegistrationError, StatusCodeError } from '../errors/errors'
@ -12,7 +12,8 @@ const CHANGE_EMAIL_URL = '/api/pleroma/change_email'
const CHANGE_PASSWORD_URL = '/api/pleroma/change_password' const CHANGE_PASSWORD_URL = '/api/pleroma/change_password'
const TAG_USER_URL = '/api/pleroma/admin/users/tag' const TAG_USER_URL = '/api/pleroma/admin/users/tag'
const PERMISSION_GROUP_URL = (screenName, right) => `/api/pleroma/admin/users/${screenName}/permission_group/${right}` const PERMISSION_GROUP_URL = (screenName, right) => `/api/pleroma/admin/users/${screenName}/permission_group/${right}`
const ACTIVATION_STATUS_URL = screenName => `/api/pleroma/admin/users/${screenName}/activation_status` const ACTIVATE_USER_URL = '/api/pleroma/admin/users/activate'
const DEACTIVATE_USER_URL = '/api/pleroma/admin/users/deactivate'
const ADMIN_USERS_URL = '/api/pleroma/admin/users' const ADMIN_USERS_URL = '/api/pleroma/admin/users'
const SUGGESTIONS_URL = '/api/v1/suggestions' const SUGGESTIONS_URL = '/api/v1/suggestions'
const NOTIFICATION_SETTINGS_URL = '/api/pleroma/notification_settings' const NOTIFICATION_SETTINGS_URL = '/api/pleroma/notification_settings'
@ -450,20 +451,26 @@ const deleteRight = ({ right, credentials, ...user }) => {
}) })
} }
const setActivationStatus = ({ status, credentials, ...user }) => { const activateUser = ({ credentials, screen_name: nickname }) => {
const screenName = user.screen_name return promisedRequest({
const body = { url: ACTIVATE_USER_URL,
status: status method: 'PATCH',
credentials,
payload: {
nicknames: [nickname]
}
}).then(response => get(response, 'users.0'))
} }
const headers = authHeaders(credentials) const deactivateUser = ({ credentials, screen_name: nickname }) => {
headers['Content-Type'] = 'application/json' return promisedRequest({
url: DEACTIVATE_USER_URL,
return fetch(ACTIVATION_STATUS_URL(screenName), { method: 'PATCH',
method: 'PUT', credentials,
headers: headers, payload: {
body: JSON.stringify(body) nicknames: [nickname]
}) }
}).then(response => get(response, 'users.0'))
} }
const deleteUser = ({ credentials, ...user }) => { const deleteUser = ({ credentials, ...user }) => {
@ -979,7 +986,8 @@ const apiService = {
deleteUser, deleteUser,
addRight, addRight,
deleteRight, deleteRight,
setActivationStatus, activateUser,
deactivateUser,
register, register,
getCaptcha, getCaptcha,
updateAvatar, updateAvatar,

View File

@ -89,8 +89,13 @@ const backendInteractorService = credentials => {
} }
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
const setActivationStatus = ({ screen_name }, status) => { const activateUser = ({ screen_name }) => {
return apiService.setActivationStatus({ screen_name, status, credentials }) return apiService.activateUser({ screen_name, credentials })
}
// eslint-disable-next-line camelcase
const deactivateUser = ({ screen_name }) => {
return apiService.deactivateUser({ screen_name, credentials })
} }
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
@ -191,7 +196,8 @@ const backendInteractorService = credentials => {
addRight, addRight,
deleteRight, deleteRight,
deleteUser, deleteUser,
setActivationStatus, activateUser,
deactivateUser,
register, register,
getCaptcha, getCaptcha,
updateAvatar, updateAvatar,