Commit f7029a27 authored by HJ's avatar HJ 🐼

Merge branch '716' into 'develop'

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

Closes #716

See merge request !1006
parents b739edb5 4e4c4af4
Pipeline #21275 passed with stages
in 4 minutes and 22 seconds
......@@ -71,12 +71,7 @@ const ModerationTools = {
}
},
toggleActivationStatus () {
const store = this.$store
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 })
})
this.$store.dispatch('toggleActivationStatus', this.user)
},
deleteUserDialog (show) {
this.showDeleteUserDialog = show
......
......@@ -95,9 +95,9 @@ export const mutations = {
newRights[right] = value
set(user, 'rights', newRights)
},
updateActivationStatus (state, { user: { id }, status }) {
updateActivationStatus (state, { user: { id }, deactivated }) {
const user = state.usersObject[id]
set(user, 'deactivated', !status)
set(user, 'deactivated', deactivated)
},
setCurrentUser (state, user) {
state.lastLoginName = user.screen_name
......@@ -331,6 +331,11 @@ const users = {
return rootState.api.backendInteractor.unsubscribeUser(id)
.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) {
const token = store.state.currentUser.credentials
const vapidPublicKey = store.rootState.instance.vapidPublicKey
......
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 'whatwg-fetch'
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 TAG_USER_URL = '/api/pleroma/admin/users/tag'
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 SUGGESTIONS_URL = '/api/v1/suggestions'
const NOTIFICATION_SETTINGS_URL = '/api/pleroma/notification_settings'
......@@ -450,20 +451,26 @@ const deleteRight = ({ right, credentials, ...user }) => {
})
}
const setActivationStatus = ({ status, credentials, ...user }) => {
const screenName = user.screen_name
const body = {
status: status
}
const headers = authHeaders(credentials)
headers['Content-Type'] = 'application/json'
const activateUser = ({ credentials, screen_name: nickname }) => {
return promisedRequest({
url: ACTIVATE_USER_URL,
method: 'PATCH',
credentials,
payload: {
nicknames: [nickname]
}
}).then(response => get(response, 'users.0'))
}
return fetch(ACTIVATION_STATUS_URL(screenName), {
method: 'PUT',
headers: headers,
body: JSON.stringify(body)
})
const deactivateUser = ({ credentials, screen_name: nickname }) => {
return promisedRequest({
url: DEACTIVATE_USER_URL,
method: 'PATCH',
credentials,
payload: {
nicknames: [nickname]
}
}).then(response => get(response, 'users.0'))
}
const deleteUser = ({ credentials, ...user }) => {
......@@ -979,7 +986,8 @@ const apiService = {
deleteUser,
addRight,
deleteRight,
setActivationStatus,
activateUser,
deactivateUser,
register,
getCaptcha,
updateAvatar,
......
......@@ -89,8 +89,13 @@ const backendInteractorService = credentials => {
}
// eslint-disable-next-line camelcase
const setActivationStatus = ({ screen_name }, status) => {
return apiService.setActivationStatus({ screen_name, status, credentials })
const activateUser = ({ screen_name }) => {
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
......@@ -191,7 +196,8 @@ const backendInteractorService = credentials => {
addRight,
deleteRight,
deleteUser,
setActivationStatus,
activateUser,
deactivateUser,
register,
getCaptcha,
updateAvatar,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment