From 506822bed01deb2d2fb98f511902d6801819cbd8 Mon Sep 17 00:00:00 2001
From: taehoon
Date: Mon, 18 Nov 2019 20:29:12 -0500
Subject: [PATCH 1/4] replace setActivationStatus api with new one
---
.../moderation_tools/moderation_tools.js | 2 +-
src/services/api/api.service.js | 19 +++++++------------
.../backend_interactor_service.js | 6 +++---
3 files changed, 11 insertions(+), 16 deletions(-)
diff --git a/src/components/moderation_tools/moderation_tools.js b/src/components/moderation_tools/moderation_tools.js
index 8aadc8c5..10a20709 100644
--- a/src/components/moderation_tools/moderation_tools.js
+++ b/src/components/moderation_tools/moderation_tools.js
@@ -73,7 +73,7 @@ const ModerationTools = {
toggleActivationStatus () {
const store = this.$store
const status = !!this.user.deactivated
- store.state.api.backendInteractor.setActivationStatus(this.user, status).then(response => {
+ store.state.api.backendInteractor.toggleActivationStatus(this.user).then(response => {
if (!response.ok) { return }
store.commit('updateActivationStatus', { user: this.user, status: status })
})
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index 7eb0547e..dbc8320e 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -12,7 +12,7 @@ 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 TOGGLE_ACTIVATION_URL = screenName => `/api/pleroma/admin/users/${screenName}/toggle_activation`
const ADMIN_USERS_URL = '/api/pleroma/admin/users'
const SUGGESTIONS_URL = '/api/v1/suggestions'
const NOTIFICATION_SETTINGS_URL = '/api/pleroma/notification_settings'
@@ -450,19 +450,14 @@ const deleteRight = ({ right, credentials, ...user }) => {
})
}
-const setActivationStatus = ({ status, credentials, ...user }) => {
- const screenName = user.screen_name
- const body = {
- status: status
- }
-
+// eslint-disable-next-line camelcase
+const toggleActivationStatus = ({ credentials, screen_name }) => {
const headers = authHeaders(credentials)
headers['Content-Type'] = 'application/json'
- return fetch(ACTIVATION_STATUS_URL(screenName), {
- method: 'PUT',
- headers: headers,
- body: JSON.stringify(body)
+ return fetch(TOGGLE_ACTIVATION_URL(screen_name), {
+ method: 'PATCH',
+ headers: headers
})
}
@@ -979,7 +974,7 @@ const apiService = {
deleteUser,
addRight,
deleteRight,
- setActivationStatus,
+ toggleActivationStatus,
register,
getCaptcha,
updateAvatar,
diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js
index c16bd1f1..e0a15d3b 100644
--- a/src/services/backend_interactor_service/backend_interactor_service.js
+++ b/src/services/backend_interactor_service/backend_interactor_service.js
@@ -89,8 +89,8 @@ const backendInteractorService = credentials => {
}
// eslint-disable-next-line camelcase
- const setActivationStatus = ({ screen_name }, status) => {
- return apiService.setActivationStatus({ screen_name, status, credentials })
+ const toggleActivationStatus = ({ screen_name }) => {
+ return apiService.toggleActivationStatus({ screen_name, credentials })
}
// eslint-disable-next-line camelcase
@@ -191,7 +191,7 @@ const backendInteractorService = credentials => {
addRight,
deleteRight,
deleteUser,
- setActivationStatus,
+ toggleActivationStatus,
register,
getCaptcha,
updateAvatar,
From 45e7f93c49042c365badf0043ebd0480ecbb9c49 Mon Sep 17 00:00:00 2001
From: taehoon
Date: Mon, 18 Nov 2019 20:33:07 -0500
Subject: [PATCH 2/4] refactor toggleActivationStatus
---
src/services/api/api.service.js | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index dbc8320e..b739ec1f 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -452,13 +452,7 @@ const deleteRight = ({ right, credentials, ...user }) => {
// eslint-disable-next-line camelcase
const toggleActivationStatus = ({ credentials, screen_name }) => {
- const headers = authHeaders(credentials)
- headers['Content-Type'] = 'application/json'
-
- return fetch(TOGGLE_ACTIVATION_URL(screen_name), {
- method: 'PATCH',
- headers: headers
- })
+ return promisedRequest({ url: TOGGLE_ACTIVATION_URL(screen_name), method: 'PATCH', credentials })
}
const deleteUser = ({ credentials, ...user }) => {
From 36376ce57c93c81317b6a8b0b50699d6b8488f57 Mon Sep 17 00:00:00 2001
From: taehoon
Date: Mon, 18 Nov 2019 20:42:10 -0500
Subject: [PATCH 3/4] use vuex action
---
src/components/moderation_tools/moderation_tools.js | 7 +------
src/modules/users.js | 10 ++++++++--
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/components/moderation_tools/moderation_tools.js b/src/components/moderation_tools/moderation_tools.js
index 10a20709..02b92fef 100644
--- a/src/components/moderation_tools/moderation_tools.js
+++ b/src/components/moderation_tools/moderation_tools.js
@@ -71,12 +71,7 @@ const ModerationTools = {
}
},
toggleActivationStatus () {
- const store = this.$store
- const status = !!this.user.deactivated
- store.state.api.backendInteractor.toggleActivationStatus(this.user).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
diff --git a/src/modules/users.js b/src/modules/users.js
index 14b2d8b5..ec2ef608 100644
--- a/src/modules/users.js
+++ b/src/modules/users.js
@@ -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,12 @@ const users = {
return rootState.api.backendInteractor.unsubscribeUser(id)
.then((relationship) => commit('updateUserRelationship', [relationship]))
},
+ toggleActivationStatus ({ rootState, commit }, user) {
+ rootState.api.backendInteractor.toggleActivationStatus(user)
+ .then(response => {
+ commit('updateActivationStatus', { user, deactivated: response.deactivated })
+ })
+ },
registerPushNotifications (store) {
const token = store.state.currentUser.credentials
const vapidPublicKey = store.rootState.instance.vapidPublicKey
From 4e4c4af422c400d016e4605f8bcf699f7154a8b4 Mon Sep 17 00:00:00 2001
From: taehoon
Date: Tue, 19 Nov 2019 14:41:39 -0500
Subject: [PATCH 4/4] toggle_activation api is also deprecated
---
src/modules/users.js | 7 ++---
src/services/api/api.service.js | 31 +++++++++++++++----
.../backend_interactor_service.js | 12 +++++--
3 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/src/modules/users.js b/src/modules/users.js
index ec2ef608..82d3c4e8 100644
--- a/src/modules/users.js
+++ b/src/modules/users.js
@@ -332,10 +332,9 @@ const users = {
.then((relationship) => commit('updateUserRelationship', [relationship]))
},
toggleActivationStatus ({ rootState, commit }, user) {
- rootState.api.backendInteractor.toggleActivationStatus(user)
- .then(response => {
- commit('updateActivationStatus', { user, deactivated: response.deactivated })
- })
+ 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
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index b739ec1f..a69fa53c 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -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 '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 TOGGLE_ACTIVATION_URL = screenName => `/api/pleroma/admin/users/${screenName}/toggle_activation`
+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,9 +451,26 @@ const deleteRight = ({ right, credentials, ...user }) => {
})
}
-// eslint-disable-next-line camelcase
-const toggleActivationStatus = ({ credentials, screen_name }) => {
- return promisedRequest({ url: TOGGLE_ACTIVATION_URL(screen_name), method: 'PATCH', credentials })
+const activateUser = ({ credentials, screen_name: nickname }) => {
+ return promisedRequest({
+ url: ACTIVATE_USER_URL,
+ method: 'PATCH',
+ credentials,
+ payload: {
+ nicknames: [nickname]
+ }
+ }).then(response => get(response, 'users.0'))
+}
+
+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 }) => {
@@ -968,7 +986,8 @@ const apiService = {
deleteUser,
addRight,
deleteRight,
- toggleActivationStatus,
+ activateUser,
+ deactivateUser,
register,
getCaptcha,
updateAvatar,
diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js
index e0a15d3b..3d4ec6ac 100644
--- a/src/services/backend_interactor_service/backend_interactor_service.js
+++ b/src/services/backend_interactor_service/backend_interactor_service.js
@@ -89,8 +89,13 @@ const backendInteractorService = credentials => {
}
// eslint-disable-next-line camelcase
- const toggleActivationStatus = ({ screen_name }) => {
- return apiService.toggleActivationStatus({ screen_name, 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,
- toggleActivationStatus,
+ activateUser,
+ deactivateUser,
register,
getCaptcha,
updateAvatar,