Fix forcing password reset

This commit is contained in:
Angelina Filippova 2020-01-28 16:06:49 +03:00
parent 47dbb5b8de
commit ad2d487beb
4 changed files with 14 additions and 11 deletions

View file

@ -89,12 +89,13 @@ export async function getPasswordResetToken(nickname, authHost, token) {
}) })
} }
export async function requirePasswordReset(nickname, authHost, token) { export async function forcePasswordReset(nicknames, authHost, token) {
return await request({ return await request({
baseURL: baseName(authHost), baseURL: baseName(authHost),
url: `/api/pleroma/admin/users/${nickname}/force_password_reset`, url: `/api/pleroma/admin/users/force_password_reset`,
method: 'patch', method: 'patch',
headers: authHeaders(token) headers: authHeaders(token),
data: { nicknames }
}) })
} }

View file

@ -12,7 +12,7 @@ import {
searchUsers, searchUsers,
tagUser, tagUser,
untagUser, untagUser,
requirePasswordReset, forcePasswordReset,
confirmUserEmail, confirmUserEmail,
resendConfirmationEmail resendConfirmationEmail
} from '@/api/users' } from '@/api/users'
@ -207,9 +207,10 @@ const users = {
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: users[0].id }) dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: users[0].id })
}, },
async RequirePasswordReset({ dispatch, getters }, user) { async RequirePasswordReset({ dispatch, getters }, users) {
const nicknames = users.map(user => user.nickname)
try { try {
await requirePasswordReset(user.nickname, getters.authHost, getters.token) await forcePasswordReset(nicknames, getters.authHost, getters.token)
} catch (_e) { } catch (_e) {
return return
} }

View file

@ -95,7 +95,7 @@
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item <el-dropdown-item
v-if="user.local" v-if="user.local"
@click.native="requirePasswordReset(user.nickname)"> @click.native="requirePasswordReset(user)">
{{ $t('users.requirePasswordReset') }} {{ $t('users.requirePasswordReset') }}
</el-dropdown-item> </el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
@ -136,13 +136,13 @@ export default {
handleEmailConfirmation(user) { handleEmailConfirmation(user) {
this.$store.dispatch('ConfirmUsersEmail', [user]) this.$store.dispatch('ConfirmUsersEmail', [user])
}, },
requirePasswordReset(nickname) { requirePasswordReset(user) {
const mailerEnabled = this.$store.state.user.nodeInfo.metadata.mailerEnabled const mailerEnabled = this.$store.state.user.nodeInfo.metadata.mailerEnabled
if (!mailerEnabled) { if (!mailerEnabled) {
this.$alert(this.$t('users.mailerMustBeEnabled'), 'Error', { type: 'error' }) this.$alert(this.$t('users.mailerMustBeEnabled'), 'Error', { type: 'error' })
return return
} }
this.$store.dispatch('RequirePasswordReset', { nickname }) this.$store.dispatch('RequirePasswordReset', [user])
}, },
showAdminAction({ local, id }) { showAdminAction({ local, id }) {
return local && this.showDeactivatedButton(id) return local && this.showDeactivatedButton(id)

View file

@ -216,8 +216,9 @@ export default {
}, },
requirePasswordReset: () => { requirePasswordReset: () => {
const filtered = this.selectedUsers.filter(user => user.local) const filtered = this.selectedUsers.filter(user => user.local)
filtered.map(user => this.$store.dispatch('RequirePasswordReset', user)) const requirePasswordResetFn = async(users) => await this.$store.dispatch('RequirePasswordReset', users)
this.$emit('apply-action')
applyAction(filtered, requirePasswordResetFn)
}, },
confirmAccounts: () => { confirmAccounts: () => {
const filtered = this.selectedUsers.filter(user => user.local && user.confirmation_pending) const filtered = this.selectedUsers.filter(user => user.local && user.confirmation_pending)