Merge branch 'feature/require-mailer-to-reset-password' into 'master'

mailerEnabled must be set to `true` in order to require password reset

See merge request pleroma/admin-fe!51
This commit is contained in:
Maxim Filippov 2019-09-27 20:08:36 +00:00
commit e500401698
14 changed files with 58 additions and 4 deletions

View file

@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## Unreleased ## Unreleased
### Changed
- `mailerEnabled` must be set to `true` in order to require password reset (password reset currently only works via email)
## [1.2.0] - 2019-09-27 ## [1.2.0] - 2019-09-27
### Added ### Added

View file

@ -0,0 +1,9 @@
export async function getNodeInfo(authHost) {
const data = {
metadata: {
mailerEnabled: true
}
}
return Promise.resolve({ data })
}

10
src/api/nodeInfo.js Normal file
View file

@ -0,0 +1,10 @@
import request from '@/utils/request'
import { baseName } from './utils'
export async function getNodeInfo(authHost) {
return await request({
baseURL: baseName(authHost),
url: `/nodeinfo/2.0.json`,
method: 'get'
})
}

View file

@ -1,7 +1,7 @@
const isLocalhost = (instanceName) => const isLocalhost = (instanceName) =>
instanceName.startsWith('localhost:') || instanceName.startsWith('127.0.0.1:') instanceName.startsWith('localhost:') || instanceName.startsWith('127.0.0.1:')
export const baseName = (instanceName) => { export const baseName = (instanceName = 'localhost') => {
if (instanceName.match(/https?:\/\//)) { if (instanceName.match(/https?:\/\//)) {
return instanceName return instanceName
} else { } else {

View file

@ -215,6 +215,7 @@ export default {
addTagForMultipleUsersConfirmation: 'Are you sure you want to apply tag to all selected users?', addTagForMultipleUsersConfirmation: 'Are you sure you want to apply tag to all selected users?',
removeTagFromMultipleUsersConfirmation: 'Are you sure you want to remove tag from all selected users?', removeTagFromMultipleUsersConfirmation: 'Are you sure you want to remove tag from all selected users?',
requirePasswordResetConfirmation: 'Are you sure you want to require password reset for all selected users?', requirePasswordResetConfirmation: 'Are you sure you want to require password reset for all selected users?',
mailerMustBeEnabled: 'To require user\'s password reset you must enable mailer.',
ok: 'Okay', ok: 'Okay',
completed: 'Completed', completed: 'Completed',
cancel: 'Cancel', cancel: 'Cancel',

View file

@ -1,4 +1,5 @@
import { loginByUsername, getUserInfo } from '@/api/login' import { loginByUsername, getUserInfo } from '@/api/login'
import { getNodeInfo } from '@/api/nodeInfo'
import { getToken, setToken, removeToken, getAuthHost, setAuthHost, removeAuthHost } from '@/utils/auth' import { getToken, setToken, removeToken, getAuthHost, setAuthHost, removeAuthHost } from '@/utils/auth'
const user = { const user = {
@ -15,7 +16,8 @@ const user = {
roles: [], roles: [],
setting: { setting: {
articlePlatform: [] articlePlatform: []
} },
nodeInfo: {}
}, },
mutations: { mutations: {
@ -48,6 +50,9 @@ const user = {
}, },
SET_AUTH_HOST: (state, authHost) => { SET_AUTH_HOST: (state, authHost) => {
state.authHost = authHost state.authHost = authHost
},
SET_NODE_INFO: (state, nodeInfo) => {
state.nodeInfo = nodeInfo
} }
}, },
@ -67,7 +72,11 @@ const user = {
}) })
}) })
}, },
async GetNodeInfo({ commit, state }) {
const nodeInfo = await getNodeInfo(state.authHost)
commit('SET_NODE_INFO', nodeInfo.data)
},
GetUserInfo({ commit, state }) { GetUserInfo({ commit, state }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
getUserInfo(state.token, state.authHost).then(response => { getUserInfo(state.token, state.authHost).then(response => {

View file

@ -98,10 +98,11 @@ const users = {
async RequirePasswordReset({ commit, getters, state }, user) { async RequirePasswordReset({ commit, getters, state }, user) {
await requirePasswordReset(user.nickname, getters.authHost, getters.token) await requirePasswordReset(user.nickname, getters.authHost, getters.token)
}, },
async FetchUsers({ commit, state, getters }, { page }) { async FetchUsers({ commit, state, getters, dispatch }, { page }) {
commit('SET_LOADING', true) commit('SET_LOADING', true)
const filters = Object.keys(state.filters).filter(filter => state.filters[filter]).join() const filters = Object.keys(state.filters).filter(filter => state.filters[filter]).join()
const response = await fetchUsers(filters, getters.authHost, getters.token, page) const response = await fetchUsers(filters, getters.authHost, getters.token, page)
await dispatch('GetNodeInfo')
loadUsers(commit, page, response.data) loadUsers(commit, page, response.data)
}, },
async GetPasswordResetToken({ commit, state, getters }, nickname) { async GetPasswordResetToken({ commit, state, getters }, nickname) {

View file

@ -10,7 +10,7 @@ const service = axios.create({
service.interceptors.response.use( service.interceptors.response.use(
response => response, response => response,
error => { error => {
console.log('Error ' + error) console.log(`Error ${error}`)
console.log(error.response.data) console.log(error.response.data)
// If there's an "error" property in the json, use it // If there's an "error" property in the json, use it

View file

@ -273,6 +273,14 @@ export default {
) )
}, },
requirePasswordReset() { requirePasswordReset() {
const mailerEnabled = this.$store.state.user.nodeInfo.metadata.mailerEnabled
if (!mailerEnabled) {
this.$alert(this.$t('users.mailerMustBeEnabled'), 'Error', { type: 'error' })
return
}
const { requirePasswordReset } = this.mappers() const { requirePasswordReset } = this.mappers()
this.confirmMessage( this.confirmMessage(
this.$t('users.requirePasswordResetConfirmation'), this.$t('users.requirePasswordResetConfirmation'),

View file

@ -265,6 +265,14 @@ export default {
this.$store.dispatch('GetPasswordResetToken', nickname) this.$store.dispatch('GetPasswordResetToken', nickname)
}, },
requirePasswordReset(nickname) { requirePasswordReset(nickname) {
const mailerEnabled = this.$store.state.user.nodeInfo.metadata.mailerEnabled
if (!mailerEnabled) {
this.$alert(this.$t('users.mailerMustBeEnabled'), 'Error', { type: 'error' })
return
}
this.$store.dispatch('RequirePasswordReset', { nickname }) this.$store.dispatch('RequirePasswordReset', { nickname })
}, },
handleDeactivation({ nickname }) { handleDeactivation({ nickname }) {

View file

@ -16,6 +16,7 @@ localVue.use(Vuex)
localVue.use(VueRouter) localVue.use(VueRouter)
localVue.use(Element) localVue.use(Element)
jest.mock('@/api/nodeInfo')
jest.mock('@/api/login') jest.mock('@/api/login')
describe('Login', () => { describe('Login', () => {

View file

@ -14,6 +14,7 @@ const localVue = createLocalVue()
localVue.use(Vuex) localVue.use(Vuex)
localVue.use(Element) localVue.use(Element)
jest.mock('@/api/nodeInfo')
jest.mock('@/api/users') jest.mock('@/api/users')
describe('Search and filter users', () => { describe('Search and filter users', () => {

View file

@ -13,6 +13,7 @@ const localVue = createLocalVue()
localVue.use(Vuex) localVue.use(Vuex)
localVue.use(Element) localVue.use(Element)
jest.mock('@/api/nodeInfo')
jest.mock('@/api/users') jest.mock('@/api/users')
describe('Apply users actions to multiple users', () => { describe('Apply users actions to multiple users', () => {

View file

@ -13,6 +13,7 @@ const localVue = createLocalVue()
localVue.use(Vuex) localVue.use(Vuex)
localVue.use(Element) localVue.use(Element)
jest.mock('@/api/nodeInfo')
jest.mock('@/api/users') jest.mock('@/api/users')
describe('Filters users', () => { describe('Filters users', () => {