mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Prevent disabling any type
Resource must have a label Post|Comment|User
This commit is contained in:
parent
f14c903d2a
commit
ee5c4127e6
@ -6,16 +6,18 @@ export default {
|
||||
const cypher = `
|
||||
MATCH (u:User {id: $userId})
|
||||
MATCH (resource {id: $id})
|
||||
WHERE resource:User OR resource:Comment OR resource:Post
|
||||
SET resource.disabled = true
|
||||
MERGE (resource)<-[:DISABLED]-(u)
|
||||
RETURN resource {.id}
|
||||
`
|
||||
const session = driver.session()
|
||||
const res = await session.run(cypher, { id, userId })
|
||||
session.close()
|
||||
const [resource] = res.records.map((record) => {
|
||||
return record.get('resource')
|
||||
})
|
||||
session.close()
|
||||
if(!resource) return null
|
||||
return resource.id
|
||||
},
|
||||
enable: async (object, params, { user, driver }) => {
|
||||
@ -28,10 +30,11 @@ export default {
|
||||
`
|
||||
const session = driver.session()
|
||||
const res = await session.run(cypher, { id })
|
||||
session.close()
|
||||
const [resource] = res.records.map((record) => {
|
||||
return record.get('resource')
|
||||
})
|
||||
session.close()
|
||||
if(!resource) return null
|
||||
return resource.id
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,6 +80,25 @@ describe('disable', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('on something that is not a (Comment|Post|User) ', () => {
|
||||
beforeEach(async () => {
|
||||
variables = {
|
||||
id: 't23'
|
||||
}
|
||||
createResource = () => {
|
||||
return Promise.all([
|
||||
factory.create('Tag', { id: 't23' }),
|
||||
])
|
||||
}
|
||||
})
|
||||
|
||||
it('returns null', async () => {
|
||||
const expected = { disable: null }
|
||||
await setup()
|
||||
await expect(action()).resolves.toEqual(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe('on a comment', () => {
|
||||
beforeEach(async () => {
|
||||
variables = {
|
||||
@ -234,6 +253,26 @@ describe('enable', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('on something that is not a (Comment|Post|User) ', () => {
|
||||
beforeEach(async () => {
|
||||
variables = {
|
||||
id: 't23'
|
||||
}
|
||||
createResource = () => {
|
||||
// we cannot create a :DISABLED relationship here
|
||||
return Promise.all([
|
||||
factory.create('Tag', { id: 't23' }),
|
||||
])
|
||||
}
|
||||
})
|
||||
|
||||
it('returns null', async () => {
|
||||
const expected = { enable: null }
|
||||
await setup()
|
||||
await expect(action()).resolves.toEqual(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe('on a comment', () => {
|
||||
beforeEach(async () => {
|
||||
variables = {
|
||||
|
||||
@ -10,8 +10,8 @@ type Mutation {
|
||||
login(email: String!, password: String!): String!
|
||||
signup(email: String!, password: String!): Boolean!
|
||||
report(id: ID!, description: String): Report
|
||||
disable(id: ID!): ID!
|
||||
enable(id: ID!): ID!
|
||||
disable(id: ID!): ID
|
||||
enable(id: ID!): ID
|
||||
"Shout the given Type and ID"
|
||||
shout(id: ID!, type: ShoutTypeEnum): Boolean! @cypher(statement: """
|
||||
MATCH (n {id: $id})<-[:WROTE]-(wu:User), (u:User {id: $cypherParams.currentUserId})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user