|
|
@@ -9,16 +9,14 @@ import {
|
|
|
messageSend
|
|
|
} from './base'
|
|
|
|
|
|
-// 公众号二维码
|
|
|
-export function getTicket (id) {
|
|
|
+export function getWechatQr (id) {
|
|
|
return request({
|
|
|
url: `keycloak/query/ticket/${id}`,
|
|
|
method: 'GET'
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-// 小程序二维码
|
|
|
-export function getQrcode (data) {
|
|
|
+export function getAppletQr (data) {
|
|
|
return request({
|
|
|
url: `wxapplet/qrcode`,
|
|
|
method: 'GET',
|
|
|
@@ -28,7 +26,6 @@ export function getQrcode (data) {
|
|
|
|
|
|
export function userinfo (silence) {
|
|
|
const config = {
|
|
|
- // url: `${baseUrl}/realms/${realm}/account`,
|
|
|
url: `/users/${store.getters.userId}`,
|
|
|
method: 'GET'
|
|
|
}
|
|
|
@@ -40,55 +37,116 @@ export function userinfo (silence) {
|
|
|
}
|
|
|
|
|
|
export function addUserAccount (data) {
|
|
|
+ if (store.getters.canManageUsers) {
|
|
|
+ return add({
|
|
|
+ url: '/users',
|
|
|
+ method: 'POST',
|
|
|
+ data: {
|
|
|
+ ...data,
|
|
|
+ credentials: [{ type: 'password', value: process.env.VUE_APP_USER_PASSWORD, temporary: true }]
|
|
|
+ }
|
|
|
+ }, keycloakRequest)
|
|
|
+ }
|
|
|
return add({
|
|
|
- url: `/users`,
|
|
|
+ url: '/admin/users',
|
|
|
method: 'POST',
|
|
|
data: {
|
|
|
...data,
|
|
|
credentials: [{ type: 'password', value: process.env.VUE_APP_USER_PASSWORD, temporary: true }]
|
|
|
}
|
|
|
- }, keycloakRequest)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
-export function updateUser (id, data, message) {
|
|
|
+export function updateUser (data, message) {
|
|
|
+ if (store.getters.canManageUsers) {
|
|
|
+ return update({
|
|
|
+ url: `/users/${store.getters.userId}`,
|
|
|
+ method: 'PUT',
|
|
|
+ data
|
|
|
+ }, message, keycloakRequest)
|
|
|
+ }
|
|
|
return update({
|
|
|
- url: `/users/${id}`,
|
|
|
+ url: '/keycloak/users/attribute',
|
|
|
method: 'PUT',
|
|
|
data
|
|
|
- }, message, keycloakRequest)
|
|
|
+ }, message)
|
|
|
+}
|
|
|
+
|
|
|
+export function toggleUser (id, enabled) {
|
|
|
+ if (store.getters.canManageUsers) {
|
|
|
+ return update({
|
|
|
+ url: `/users/${id}`,
|
|
|
+ method: 'PUT',
|
|
|
+ data: { enabled }
|
|
|
+ }, enabled ? '启用' : '停用', keycloakRequest)
|
|
|
+ }
|
|
|
+ return update({
|
|
|
+ url: `/admin/users/${id}`,
|
|
|
+ method: 'PUT',
|
|
|
+ data: { enabled }
|
|
|
+ }, enabled ? '启用' : '停用')
|
|
|
}
|
|
|
|
|
|
export function deleteUser ({ id }) {
|
|
|
- return keycloakRequest({
|
|
|
- url: `/users/${id}`,
|
|
|
+ if (store.getters.canManageUsers) {
|
|
|
+ return keycloakRequest({
|
|
|
+ url: `/users/${id}`,
|
|
|
+ method: 'DELETE'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return request({
|
|
|
+ url: `/admin/users/${id}`,
|
|
|
method: 'DELETE'
|
|
|
})
|
|
|
}
|
|
|
|
|
|
export function getUserCredentials ({ id }) {
|
|
|
- return keycloakRequest({
|
|
|
- url: `/users/${id}/credentials`,
|
|
|
+ if (store.getters.canManageUsers) {
|
|
|
+ return keycloakRequest({
|
|
|
+ url: `/users/${id}/credentials`,
|
|
|
+ method: 'GET'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return request({
|
|
|
+ url: `/admin/users/${id}/credentials`,
|
|
|
method: 'GET'
|
|
|
- })
|
|
|
+ }).then(({ data }) => data)
|
|
|
}
|
|
|
|
|
|
export function deleteUserCredentials (userId, credentialId) {
|
|
|
- return send({
|
|
|
- url: `/users/${userId}/credentials/${credentialId}`,
|
|
|
+ if (store.getters.canManageUsers) {
|
|
|
+ return messageSend({
|
|
|
+ url: `/users/${userId}/credentials/${credentialId}`,
|
|
|
+ method: 'DELETE'
|
|
|
+ }, '重置', keycloakRequest)
|
|
|
+ }
|
|
|
+ return messageSend({
|
|
|
+ url: `/admin/users/${userId}/credentials/${credentialId}`,
|
|
|
method: 'DELETE'
|
|
|
- }, keycloakRequest)
|
|
|
+ }, '重置')
|
|
|
}
|
|
|
|
|
|
export function resetPassword ({ id }) {
|
|
|
+ if (store.getters.canManageUsers) {
|
|
|
+ return messageSend({
|
|
|
+ url: `/users/${id}/reset-password`,
|
|
|
+ method: 'PUT',
|
|
|
+ data: {
|
|
|
+ type: 'password',
|
|
|
+ value: process.env.VUE_APP_USER_PASSWORD,
|
|
|
+ temporary: true
|
|
|
+ }
|
|
|
+ }, '重置', keycloakRequest)
|
|
|
+ }
|
|
|
return messageSend({
|
|
|
- url: `/users/${id}/reset-password`,
|
|
|
+ url: `/admin/users/${id}/resetPassword`,
|
|
|
method: 'PUT',
|
|
|
data: {
|
|
|
type: 'password',
|
|
|
value: process.env.VUE_APP_USER_PASSWORD,
|
|
|
temporary: true
|
|
|
}
|
|
|
- }, '重置', keycloakRequest)
|
|
|
+ }, '重置')
|
|
|
}
|
|
|
|
|
|
export function resetPasswordByUser (newPassword) {
|
|
|
@@ -175,8 +233,20 @@ export function getTenantGroups () {
|
|
|
}
|
|
|
|
|
|
export function addTenant ({ name, remark }) {
|
|
|
+ if (store.getters.canManageUsers) {
|
|
|
+ return add({
|
|
|
+ url: '/groups',
|
|
|
+ method: 'POST',
|
|
|
+ data: {
|
|
|
+ name,
|
|
|
+ attributes: {
|
|
|
+ remark: [remark]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, keycloakRequest)
|
|
|
+ }
|
|
|
return add({
|
|
|
- url: '/groups',
|
|
|
+ url: '/super/admin/tenant',
|
|
|
method: 'POST',
|
|
|
data: {
|
|
|
name,
|
|
|
@@ -184,7 +254,17 @@ export function addTenant ({ name, remark }) {
|
|
|
remark: [remark]
|
|
|
}
|
|
|
}
|
|
|
- }, keycloakRequest)
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+export function deleteTenant ({ id }) {
|
|
|
+ if (store.getters.canManageUsers) {
|
|
|
+ return deleteGroup({ id })
|
|
|
+ }
|
|
|
+ return request({
|
|
|
+ url: `/super/admin/tenant/${id}`,
|
|
|
+ method: 'DELETE'
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
async function getGroups () {
|
|
|
@@ -199,19 +279,41 @@ async function getGroups () {
|
|
|
}
|
|
|
|
|
|
export function addSubGroup ({ id }, { name, remark }) {
|
|
|
+ if (store.getters.canManageUsers) {
|
|
|
+ return add({
|
|
|
+ url: `/groups/${id}/children`,
|
|
|
+ method: 'POST',
|
|
|
+ data: {
|
|
|
+ name,
|
|
|
+ attributes: { remark: [remark] }
|
|
|
+ }
|
|
|
+ }, keycloakRequest)
|
|
|
+ }
|
|
|
return add({
|
|
|
- url: `/groups/${id}/children`,
|
|
|
+ url: `/admin/group/${id}/children`,
|
|
|
method: 'POST',
|
|
|
data: {
|
|
|
name,
|
|
|
attributes: { remark: [remark] }
|
|
|
}
|
|
|
- }, keycloakRequest)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
export function updateGroup ({ id, name, remark }) {
|
|
|
+ if (store.getters.canManageUsers) {
|
|
|
+ return update({
|
|
|
+ url: `/groups/${id}`,
|
|
|
+ method: 'PUT',
|
|
|
+ data: {
|
|
|
+ name,
|
|
|
+ attributes: {
|
|
|
+ remark: [remark]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, null, keycloakRequest)
|
|
|
+ }
|
|
|
return update({
|
|
|
- url: `/groups/${id}`,
|
|
|
+ url: `/admin/group/${id}`,
|
|
|
method: 'PUT',
|
|
|
data: {
|
|
|
name,
|
|
|
@@ -219,12 +321,18 @@ export function updateGroup ({ id, name, remark }) {
|
|
|
remark: [remark]
|
|
|
}
|
|
|
}
|
|
|
- }, null, keycloakRequest)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
export function deleteGroup ({ id }) {
|
|
|
- return keycloakRequest({
|
|
|
- url: `/groups/${id}`,
|
|
|
+ if (store.getters.canManageUsers) {
|
|
|
+ return keycloakRequest({
|
|
|
+ url: `/groups/${id}`,
|
|
|
+ method: 'DELETE'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return request({
|
|
|
+ url: `/admin/group/${id}`,
|
|
|
method: 'DELETE'
|
|
|
})
|
|
|
}
|
|
|
@@ -260,6 +368,16 @@ export function getUserGroups (id, briefRepresentation = true) {
|
|
|
}).then(data => data.sort((a, b) => a.path.length - b.path.length))
|
|
|
}
|
|
|
|
|
|
+export function moveUserGroup (userId, from, to) {
|
|
|
+ if (store.getters.canManageUsers) {
|
|
|
+ return moveUserGroupByKeycloak(userId, from, to)
|
|
|
+ }
|
|
|
+ return request({
|
|
|
+ url: `/admin/users/${userId}/groups/${to.id}`,
|
|
|
+ method: 'PUT'
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
function addUserToGroup (userId, groupId) {
|
|
|
return keycloakRequest({
|
|
|
url: `/users/${userId}/groups/${groupId}`,
|
|
|
@@ -274,7 +392,7 @@ function removeUserFromGroup (userId, groupId) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-export async function moveUserGroup (userId, from, to) {
|
|
|
+async function moveUserGroupByKeycloak (userId, from, to) {
|
|
|
const fromGroups = getGroupList(from)
|
|
|
const toGroups = getGroupList(to)
|
|
|
let fromLast = fromGroups.length - 1
|
|
|
@@ -347,9 +465,6 @@ export async function updateUserRoles (userId, available, fromKeys, toKeys) {
|
|
|
delRoles.push(available.find(role => role.id === id))
|
|
|
}
|
|
|
})
|
|
|
- if (delRoles.length) {
|
|
|
- await removeUserRoles(userId, delRoles)
|
|
|
- }
|
|
|
const addRoles = []
|
|
|
const fromSet = new Set(fromKeys)
|
|
|
toKeys.forEach(id => {
|
|
|
@@ -357,9 +472,24 @@ export async function updateUserRoles (userId, available, fromKeys, toKeys) {
|
|
|
addRoles.push(available.find(role => role.id === id))
|
|
|
}
|
|
|
})
|
|
|
- if (addRoles.length) {
|
|
|
- await addUserRoles(userId, addRoles)
|
|
|
+ if (store.getters.canManageUsers) {
|
|
|
+ if (delRoles.length) {
|
|
|
+ await removeUserRoles(userId, delRoles)
|
|
|
+ }
|
|
|
+ if (addRoles.length) {
|
|
|
+ await addUserRoles(userId, addRoles)
|
|
|
+ }
|
|
|
+ return Promise.resolve()
|
|
|
}
|
|
|
+ return request({
|
|
|
+ url: '/admin/users/role/configure',
|
|
|
+ method: 'PUT',
|
|
|
+ data: {
|
|
|
+ userId,
|
|
|
+ addRoleList: addRoles,
|
|
|
+ removeRoleList: delRoles
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
function removeUserRoles (userId, roles) {
|
|
|
@@ -377,7 +507,8 @@ function addUserRoles (userId, roles) {
|
|
|
data: roles
|
|
|
})
|
|
|
}
|
|
|
-export function authcodeSend (data) {
|
|
|
+
|
|
|
+export function sendVerificationCode (data) {
|
|
|
return request({
|
|
|
url: `/authcode/send`,
|
|
|
method: 'POST',
|
|
|
@@ -385,7 +516,7 @@ export function authcodeSend (data) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-export function authcodeCheck (data) {
|
|
|
+export function checkVerificationCode (data) {
|
|
|
return request({
|
|
|
url: `/authcode/check`,
|
|
|
method: 'POST',
|