Prevent disabling any type

Resource must have a label Post|Comment|User
This commit is contained in:
Robert Schäfer 2019-03-10 18:49:04 +01:00
parent f14c903d2a
commit ee5c4127e6
3 changed files with 46 additions and 4 deletions

View File

@ -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
}
}

View File

@ -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 = {

View File

@ -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})