feat: delete user with replace target
This commit is contained in:
@@ -72,7 +72,7 @@ module.exports = {
|
||||
if (args.id <= 2) {
|
||||
throw new WIKI.Error.UserDeleteProtected()
|
||||
}
|
||||
await WIKI.models.users.deleteUser(args.id)
|
||||
await WIKI.models.users.deleteUser(args.id, args.replaceId)
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('User deleted successfully')
|
||||
}
|
||||
|
@@ -63,6 +63,7 @@ type UserMutation {
|
||||
|
||||
delete(
|
||||
id: Int!
|
||||
replaceId: Int!
|
||||
): DefaultResponse @auth(requires: ["manage:users", "manage:system"])
|
||||
|
||||
verify(
|
||||
|
@@ -71,13 +71,19 @@ module.exports = {
|
||||
['description', page.description],
|
||||
['published', page.isPublished.toString()],
|
||||
['date', page.updatedAt],
|
||||
['tags', page.tags ? page.tags.map(t => t.tag).join(', ') : '']
|
||||
['tags', page.tags ? page.tags.map(t => t.tag).join(', ') : ''],
|
||||
['editor', page.editorKey]
|
||||
]
|
||||
switch (page.contentType) {
|
||||
case 'markdown':
|
||||
return '---\n' + meta.map(mt => `${mt[0]}: ${mt[1]}`).join('\n') + '\n---\n\n' + page.content
|
||||
case 'html':
|
||||
return '<!--\n' + meta.map(mt => `${mt[0]}: ${mt[1]}`).join('\n') + '\n-->\n\n' + page.content
|
||||
case 'json':
|
||||
return {
|
||||
...page.content,
|
||||
_meta: _.fromPairs(meta)
|
||||
}
|
||||
default:
|
||||
return page.content
|
||||
}
|
||||
|
@@ -128,8 +128,10 @@ module.exports = class CommentProvider extends Model {
|
||||
} else {
|
||||
WIKI.data.commentProvider = {
|
||||
...WIKI.data.commentProvider,
|
||||
...require(`../modules/comments/${commentProvider.key}/comment`)
|
||||
...require(`../modules/comments/${commentProvider.key}/comment`),
|
||||
config: commentProvider.config
|
||||
}
|
||||
await WIKI.data.commentProvider.init()
|
||||
}
|
||||
WIKI.data.commentProvider.config = commentProvider.config
|
||||
}
|
||||
|
@@ -613,9 +613,15 @@ module.exports = class User extends Model {
|
||||
*
|
||||
* @param {*} id User ID
|
||||
*/
|
||||
static async deleteUser (id) {
|
||||
static async deleteUser (id, replaceId) {
|
||||
const usr = await WIKI.models.users.query().findById(id)
|
||||
if (usr) {
|
||||
await WIKI.models.assets.query().patch({ authorId: replaceId }).where('authorId', id)
|
||||
await WIKI.models.comments.query().patch({ authorId: replaceId }).where('authorId', id)
|
||||
await WIKI.models.pageHistory.query().patch({ authorId: replaceId }).where('authorId', id)
|
||||
await WIKI.models.pages.query().patch({ authorId: replaceId }).where('authorId', id)
|
||||
await WIKI.models.pages.query().patch({ creatorId: replaceId }).where('creatorId', id)
|
||||
|
||||
await WIKI.models.userKeys.query().delete().where('userId', id)
|
||||
await WIKI.models.users.query().deleteById(id)
|
||||
} else {
|
||||
|
@@ -10,8 +10,6 @@ const { AkismetClient } = require('akismet-api')
|
||||
const window = new JSDOM('').window
|
||||
const DOMPurify = createDOMPurify(window)
|
||||
|
||||
md.use(mdEmoji)
|
||||
|
||||
let akismetClient = null
|
||||
|
||||
// ------------------------------------
|
||||
@@ -23,6 +21,7 @@ module.exports = {
|
||||
* Init
|
||||
*/
|
||||
async init (config) {
|
||||
WIKI.logger.info('(COMMENTS/DEFAULT) Initializing...')
|
||||
if (WIKI.data.commentProvider.config.akismet && WIKI.data.commentProvider.config.akismet.length > 2) {
|
||||
akismetClient = new AkismetClient({
|
||||
key: WIKI.data.commentProvider.config.akismet,
|
||||
@@ -33,14 +32,19 @@ module.exports = {
|
||||
try {
|
||||
const isValid = await akismetClient.verifyKey()
|
||||
if (!isValid) {
|
||||
WIKI.logger.warn('Akismet Key is invalid!')
|
||||
akismetClient = null
|
||||
WIKI.logger.warn('(COMMENTS/DEFAULT) Akismet Key is invalid! [ DISABLED ]')
|
||||
} else {
|
||||
WIKI.logger.info('(COMMENTS/DEFAULT) Akismet key is valid. [ OK ]')
|
||||
}
|
||||
} catch (err) {
|
||||
WIKI.logger.warn('Unable to verify Akismet Key: ' + err.message)
|
||||
akismetClient = null
|
||||
WIKI.logger.warn('(COMMENTS/DEFAULT) Unable to verify Akismet Key: ' + err.message)
|
||||
}
|
||||
} else {
|
||||
akismetClient = null
|
||||
}
|
||||
WIKI.logger.info('(COMMENTS/DEFAULT) Initialization completed.')
|
||||
},
|
||||
/**
|
||||
* Create New Comment
|
||||
@@ -56,6 +60,8 @@ module.exports = {
|
||||
}
|
||||
})
|
||||
|
||||
mkdown.use(mdEmoji)
|
||||
|
||||
// -> Build New Comment
|
||||
const newComment = {
|
||||
content,
|
||||
|
Reference in New Issue
Block a user