mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Soft delete middleware test passes
This commit is contained in:
parent
911500a3bd
commit
f3ab671f21
@ -1,4 +1,4 @@
|
||||
import { rule, shield, allow } from 'graphql-shield'
|
||||
import { rule, shield, allow, or } from 'graphql-shield'
|
||||
|
||||
/*
|
||||
* TODO: implement
|
||||
@ -11,36 +11,38 @@ const isAuthenticated = rule()(async (parent, args, ctx, info) => {
|
||||
const isAdmin = rule()(async (parent, args, ctx, info) => {
|
||||
return ctx.user.role === 'ADMIN'
|
||||
})
|
||||
const isModerator = rule()(async (parent, args, ctx, info) => {
|
||||
return ctx.user.role === 'MODERATOR'
|
||||
})
|
||||
*/
|
||||
|
||||
const isModerator = rule()(async (parent, args, { user }, info) => {
|
||||
return user && (user.role === 'moderator' || user.role === 'admin')
|
||||
})
|
||||
|
||||
const isMyOwn = rule({ cache: 'no_cache' })(async (parent, args, ctx, info) => {
|
||||
return ctx.user.id === parent.id
|
||||
})
|
||||
|
||||
const onlyEnabledContent = rule({ cache: 'strict' })(async (parent, args, ctx, info) => {
|
||||
const { disabled, deleted } = args
|
||||
return !(disabled || deleted)
|
||||
})
|
||||
|
||||
// Permissions
|
||||
const permissions = shield({
|
||||
Query: {
|
||||
statistics: allow,
|
||||
currentUser: allow
|
||||
// fruits: and(isAuthenticated, or(isAdmin, isModerator)),
|
||||
// customers: and(isAuthenticated, isAdmin)
|
||||
currentUser: allow,
|
||||
Post: or(onlyEnabledContent, isModerator)
|
||||
},
|
||||
Mutation: {
|
||||
CreatePost: isAuthenticated,
|
||||
// TODO UpdatePost: isOwner,
|
||||
// TODO DeletePost: isOwner,
|
||||
report: isAuthenticated
|
||||
// addFruitToBasket: isAuthenticated
|
||||
// CreateUser: allow,
|
||||
},
|
||||
User: {
|
||||
email: isMyOwn,
|
||||
password: isMyOwn
|
||||
}
|
||||
// Post: isAuthenticated
|
||||
})
|
||||
|
||||
export default permissions
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const normalize = (args) => {
|
||||
const setDefaults = (args) => {
|
||||
if (typeof args.deleted !== 'boolean') {
|
||||
args.deleted = false
|
||||
}
|
||||
@ -11,13 +11,13 @@ const normalize = (args) => {
|
||||
export default {
|
||||
Query: {
|
||||
Post: (resolve, root, args, context, info) => {
|
||||
return resolve(root, normalize(args), context, info)
|
||||
return resolve(root, setDefaults(args), context, info)
|
||||
},
|
||||
Comment: async (resolve, root, args, context, info) => {
|
||||
return resolve(root, normalize(args), context, info)
|
||||
return resolve(root, setDefaults(args), context, info)
|
||||
},
|
||||
User: async (resolve, root, args, context, info) => {
|
||||
return resolve(root, normalize(args), context, info)
|
||||
return resolve(root, setDefaults(args), context, info)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user