feat: admin group edit / assign / unassign
This commit is contained in:
@@ -34,18 +34,19 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
GroupMutation: {
|
||||
assignUser(obj, args) {
|
||||
return WIKI.db.Group.findById(args.groupId).then(grp => {
|
||||
if (!grp) {
|
||||
throw new gql.GraphQLError('Invalid Group ID')
|
||||
}
|
||||
return WIKI.db.User.findById(args.userId).then(usr => {
|
||||
if (!usr) {
|
||||
throw new gql.GraphQLError('Invalid User ID')
|
||||
}
|
||||
return grp.addUser(usr)
|
||||
})
|
||||
})
|
||||
async assignUser(obj, args) {
|
||||
const grp = await WIKI.db.Group.findById(args.groupId)
|
||||
if (!grp) {
|
||||
throw new gql.GraphQLError('Invalid Group ID')
|
||||
}
|
||||
const usr = await WIKI.db.User.findById(args.userId)
|
||||
if (!usr) {
|
||||
throw new gql.GraphQLError('Invalid User ID')
|
||||
}
|
||||
await grp.addUser(usr)
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('User has been assigned to group.')
|
||||
}
|
||||
},
|
||||
async create(obj, args) {
|
||||
const group = await WIKI.db.Group.create({
|
||||
@@ -67,25 +68,29 @@ module.exports = {
|
||||
responseResult: graphHelper.generateSuccess('Group has been deleted.')
|
||||
}
|
||||
},
|
||||
unassignUser(obj, args) {
|
||||
return WIKI.db.Group.findById(args.groupId).then(grp => {
|
||||
if (!grp) {
|
||||
throw new gql.GraphQLError('Invalid Group ID')
|
||||
}
|
||||
return WIKI.db.User.findById(args.userId).then(usr => {
|
||||
if (!usr) {
|
||||
throw new gql.GraphQLError('Invalid User ID')
|
||||
}
|
||||
return grp.removeUser(usr)
|
||||
})
|
||||
})
|
||||
async unassignUser(obj, args) {
|
||||
const grp = await WIKI.db.Group.findById(args.groupId)
|
||||
if (!grp) {
|
||||
throw new gql.GraphQLError('Invalid Group ID')
|
||||
}
|
||||
const usr = await WIKI.db.User.findById(args.userId)
|
||||
if (!usr) {
|
||||
throw new gql.GraphQLError('Invalid User ID')
|
||||
}
|
||||
await grp.removeUser(usr)
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('User has been unassigned from group.')
|
||||
}
|
||||
},
|
||||
update(obj, args) {
|
||||
return WIKI.db.Group.update({
|
||||
async update(obj, args) {
|
||||
await WIKI.db.Group.update({
|
||||
name: args.name
|
||||
}, {
|
||||
where: { id: args.id }
|
||||
})
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Group has been updated.')
|
||||
}
|
||||
}
|
||||
},
|
||||
Group: {
|
||||
|
@@ -3,15 +3,42 @@
|
||||
|
||||
module.exports = {
|
||||
Query: {
|
||||
users(obj, args, context, info) {
|
||||
return WIKI.db.User.findAll({ where: args })
|
||||
}
|
||||
async users() { return {} }
|
||||
},
|
||||
Mutation: {
|
||||
createUser(obj, args) {
|
||||
async users() { return {} }
|
||||
},
|
||||
UserQuery: {
|
||||
async list(obj, args, context, info) {
|
||||
return WIKI.db.User.findAll({
|
||||
attributes: {
|
||||
exclude: ['password', 'tfaSecret']
|
||||
},
|
||||
raw: true
|
||||
})
|
||||
},
|
||||
async search(obj, args, context, info) {
|
||||
return WIKI.db.User.findAll({
|
||||
where: {
|
||||
$or: [
|
||||
{ email: { $like: `%${args.query}%` } },
|
||||
{ name: { $like: `%${args.query}%` } }
|
||||
]
|
||||
},
|
||||
limit: 10,
|
||||
attributes: ['id', 'email', 'name', 'provider', 'role', 'createdAt', 'updatedAt'],
|
||||
raw: true
|
||||
})
|
||||
},
|
||||
async single(obj, args, context, info) {
|
||||
return WIKI.db.User.findById(args.id)
|
||||
}
|
||||
},
|
||||
UserMutation: {
|
||||
create(obj, args) {
|
||||
return WIKI.db.User.create(args)
|
||||
},
|
||||
deleteUser(obj, args) {
|
||||
delete(obj, args) {
|
||||
return WIKI.db.User.destroy({
|
||||
where: {
|
||||
id: args.id
|
||||
@@ -19,7 +46,7 @@ module.exports = {
|
||||
limit: 1
|
||||
})
|
||||
},
|
||||
modifyUser(obj, args) {
|
||||
update(obj, args) {
|
||||
return WIKI.db.User.update({
|
||||
email: args.email,
|
||||
name: args.name,
|
||||
@@ -30,10 +57,10 @@ module.exports = {
|
||||
where: { id: args.id }
|
||||
})
|
||||
},
|
||||
resetUserPassword(obj, args) {
|
||||
resetPassword(obj, args) {
|
||||
return false
|
||||
},
|
||||
setUserPassword(obj, args) {
|
||||
setPassword(obj, args) {
|
||||
return false
|
||||
}
|
||||
},
|
||||
|
@@ -2,12 +2,6 @@
|
||||
|
||||
# ENUMS
|
||||
|
||||
enum UserRole {
|
||||
guest
|
||||
user
|
||||
admin
|
||||
}
|
||||
|
||||
enum FileType {
|
||||
binary
|
||||
image
|
||||
@@ -134,19 +128,6 @@ type Translation {
|
||||
value: String!
|
||||
}
|
||||
|
||||
# A User
|
||||
type User implements Base {
|
||||
id: Int!
|
||||
createdAt: Date
|
||||
updatedAt: Date
|
||||
email: String!
|
||||
provider: String!
|
||||
providerId: String
|
||||
name: String
|
||||
role: UserRole!
|
||||
groups: [Group]
|
||||
}
|
||||
|
||||
type OperationResult {
|
||||
succeeded: Boolean!
|
||||
message: String
|
||||
@@ -164,7 +145,6 @@ type Query {
|
||||
settings(key: String): [Setting]
|
||||
tags(key: String): [Tag]
|
||||
translations(locale: String!, namespace: String!): [Translation]
|
||||
users(id: Int, email: String, provider: String, providerId: String, role: UserRole): [User]
|
||||
}
|
||||
|
||||
# Mutations (Create, Update, Delete)
|
||||
@@ -202,15 +182,6 @@ type Mutation {
|
||||
name: String!
|
||||
): Tag
|
||||
|
||||
createUser(
|
||||
email: String!
|
||||
name: String
|
||||
passwordRaw: String
|
||||
provider: String!
|
||||
providerId: String
|
||||
role: UserRole!
|
||||
): User
|
||||
|
||||
deleteComment(
|
||||
id: Int!
|
||||
): OperationResult
|
||||
@@ -231,10 +202,6 @@ type Mutation {
|
||||
id: Int!
|
||||
): OperationResult
|
||||
|
||||
deleteUser(
|
||||
id: Int!
|
||||
): OperationResult
|
||||
|
||||
modifyComment(
|
||||
id: Int!
|
||||
content: String!
|
||||
@@ -246,15 +213,6 @@ type Mutation {
|
||||
subtitle: String
|
||||
): Document
|
||||
|
||||
modifyUser(
|
||||
id: Int!
|
||||
email: String
|
||||
name: String
|
||||
provider: String
|
||||
providerId: String
|
||||
role: UserRole
|
||||
): User
|
||||
|
||||
modifyRight(
|
||||
id: Int!
|
||||
path: String
|
||||
@@ -297,20 +255,11 @@ type Mutation {
|
||||
rightId: Int!
|
||||
): OperationResult
|
||||
|
||||
resetUserPassword(
|
||||
id: Int!
|
||||
): OperationResult
|
||||
|
||||
setConfigEntry(
|
||||
key: String!
|
||||
value: String!
|
||||
): OperationResult
|
||||
|
||||
setUserPassword(
|
||||
id: Int!
|
||||
passwordRaw: String!
|
||||
): OperationResult
|
||||
|
||||
uploadFile(
|
||||
category: FileType!
|
||||
filename: String!
|
||||
|
@@ -37,7 +37,7 @@ type GroupMutation {
|
||||
update(
|
||||
id: Int!
|
||||
name: String!
|
||||
): GroupResponse
|
||||
): DefaultResponse
|
||||
|
||||
delete(
|
||||
id: Int!
|
||||
|
101
server/graph/schemas/user.graphql
Normal file
101
server/graph/schemas/user.graphql
Normal file
@@ -0,0 +1,101 @@
|
||||
# ===============================================
|
||||
# USERS
|
||||
# ===============================================
|
||||
|
||||
extend type Query {
|
||||
users: UserQuery
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
users: UserMutation
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# QUERIES
|
||||
# -----------------------------------------------
|
||||
|
||||
type UserQuery {
|
||||
list(
|
||||
filter: String
|
||||
orderBy: String
|
||||
): [UserMinimal]
|
||||
|
||||
search(
|
||||
query: String!
|
||||
): [UserMinimal]
|
||||
|
||||
single(
|
||||
id: Int!
|
||||
): User
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# MUTATIONS
|
||||
# -----------------------------------------------
|
||||
|
||||
type UserMutation {
|
||||
create(
|
||||
email: String!
|
||||
name: String
|
||||
passwordRaw: String
|
||||
provider: String!
|
||||
providerId: String
|
||||
role: UserRole!
|
||||
): UserResponse
|
||||
|
||||
update(
|
||||
id: Int!
|
||||
email: String
|
||||
name: String
|
||||
provider: String
|
||||
providerId: String
|
||||
role: UserRole
|
||||
): UserResponse
|
||||
|
||||
delete(
|
||||
id: Int!
|
||||
): DefaultResponse
|
||||
|
||||
resetPassword(
|
||||
id: Int!
|
||||
): DefaultResponse
|
||||
|
||||
setPassword(
|
||||
id: Int!
|
||||
passwordRaw: String!
|
||||
): DefaultResponse
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# TYPES
|
||||
# -----------------------------------------------
|
||||
|
||||
enum UserRole {
|
||||
guest
|
||||
user
|
||||
admin
|
||||
}
|
||||
|
||||
type UserResponse {
|
||||
responseResult: ResponseStatus!
|
||||
user: User
|
||||
}
|
||||
|
||||
type UserMinimal {
|
||||
id: Int!
|
||||
name: String!
|
||||
email: String!
|
||||
provider: String!
|
||||
}
|
||||
|
||||
type User {
|
||||
id: Int!
|
||||
name: String!
|
||||
email: String!
|
||||
provider: String!
|
||||
providerId: String
|
||||
role: UserRole!
|
||||
createdAt: Date!
|
||||
updatedAt: Date!
|
||||
groups: [Group]
|
||||
}
|
Reference in New Issue
Block a user