mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Merge pull request #246 from Human-Connection/27_disable_posts
Obfuscate user name and use a neutral replacement
This commit is contained in:
commit
fd8cc3f7e6
@ -15,12 +15,13 @@ const setDefaultFilters = (resolve, root, args, context, info) => {
|
||||
|
||||
const obfuscateDisabled = async (resolve, root, args, context, info) => {
|
||||
if (!isModerator(context) && root.disabled) {
|
||||
root.content = 'DELETED'
|
||||
root.contentExcerpt = 'DELETED'
|
||||
root.title = 'DELETED'
|
||||
root.image = 'DELETED'
|
||||
root.avatar = 'DELETED'
|
||||
root.about = 'DELETED'
|
||||
root.content = 'UNAVAILABLE'
|
||||
root.contentExcerpt = 'UNAVAILABLE'
|
||||
root.title = 'UNAVAILABLE'
|
||||
root.image = 'UNAVAILABLE'
|
||||
root.avatar = 'UNAVAILABLE'
|
||||
root.about = 'UNAVAILABLE'
|
||||
root.name = 'UNAVAILABLE'
|
||||
}
|
||||
return resolve(root, args, context, info)
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ beforeAll(async () => {
|
||||
await Promise.all([
|
||||
factory.create('User', { id: 'u1', role: 'user', email: 'user@example.org', password: '1234' }),
|
||||
factory.create('User', { id: 'm1', role: 'moderator', email: 'moderator@example.org', password: '1234' }),
|
||||
factory.create('User', { id: 'u2', role: 'user', avatar: '/some/offensive/avatar.jpg', about: 'This self description is very offensive', email: 'troll@example.org', password: '1234' })
|
||||
factory.create('User', { id: 'u2', role: 'user', name: 'Offensive Name', avatar: '/some/offensive/avatar.jpg', about: 'This self description is very offensive', email: 'troll@example.org', password: '1234' })
|
||||
])
|
||||
|
||||
await factory.authenticateAs({ email: 'user@example.org', password: '1234' })
|
||||
@ -62,7 +62,7 @@ describe('softDeleteMiddleware', () => {
|
||||
comment = response.User[0].following[0].comments[0]
|
||||
}
|
||||
const beforeUser = async () => {
|
||||
query = '{ User(id: "u1") { following { about avatar } } }'
|
||||
query = '{ User(id: "u1") { following { name about avatar } } }'
|
||||
const response = await action()
|
||||
user = response.User[0].following[0]
|
||||
}
|
||||
@ -85,6 +85,7 @@ describe('softDeleteMiddleware', () => {
|
||||
describe('User', () => {
|
||||
beforeEach(beforeUser)
|
||||
|
||||
it('displays name', () => expect(user.name).toEqual('Offensive Name'))
|
||||
it('displays about', () => expect(user.about).toEqual('This self description is very offensive'))
|
||||
it('displays avatar', () => expect(user.avatar).toEqual('/some/offensive/avatar.jpg'))
|
||||
})
|
||||
@ -115,24 +116,25 @@ describe('softDeleteMiddleware', () => {
|
||||
describe('User', () => {
|
||||
beforeEach(beforeUser)
|
||||
|
||||
it('obfuscates about', () => expect(user.about).toEqual('DELETED'))
|
||||
it('obfuscates avatar', () => expect(user.avatar).toEqual('DELETED'))
|
||||
it('displays name', () => expect(user.name).toEqual('UNAVAILABLE'))
|
||||
it('obfuscates about', () => expect(user.about).toEqual('UNAVAILABLE'))
|
||||
it('obfuscates avatar', () => expect(user.avatar).toEqual('UNAVAILABLE'))
|
||||
})
|
||||
|
||||
describe('Post', () => {
|
||||
beforeEach(beforePost)
|
||||
|
||||
it('obfuscates title', () => expect(post.title).toEqual('DELETED'))
|
||||
it('obfuscates content', () => expect(post.content).toEqual('DELETED'))
|
||||
it('obfuscates contentExcerpt', () => expect(post.contentExcerpt).toEqual('DELETED'))
|
||||
it('obfuscates image', () => expect(post.image).toEqual('DELETED'))
|
||||
it('obfuscates title', () => expect(post.title).toEqual('UNAVAILABLE'))
|
||||
it('obfuscates content', () => expect(post.content).toEqual('UNAVAILABLE'))
|
||||
it('obfuscates contentExcerpt', () => expect(post.contentExcerpt).toEqual('UNAVAILABLE'))
|
||||
it('obfuscates image', () => expect(post.image).toEqual('UNAVAILABLE'))
|
||||
})
|
||||
|
||||
describe('Comment', () => {
|
||||
beforeEach(beforeComment)
|
||||
|
||||
it('obfuscates content', () => expect(comment.content).toEqual('DELETED'))
|
||||
it('obfuscates contentExcerpt', () => expect(comment.contentExcerpt).toEqual('DELETED'))
|
||||
it('obfuscates content', () => expect(comment.content).toEqual('UNAVAILABLE'))
|
||||
it('obfuscates contentExcerpt', () => expect(comment.contentExcerpt).toEqual('UNAVAILABLE'))
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -185,7 +187,7 @@ describe('softDeleteMiddleware', () => {
|
||||
it('conceals disabled comments', async () => {
|
||||
const expected = [
|
||||
{ content: 'Enabled comment on public post' },
|
||||
{ content: 'DELETED' }
|
||||
{ content: 'UNAVAILABLE' }
|
||||
]
|
||||
const { Post: [{ comments }] } = await action()
|
||||
await expect(comments).toEqual(expect.arrayContaining(expected))
|
||||
|
||||
@ -191,7 +191,12 @@ import Factory from './factories'
|
||||
f.create('Comment', { id: 'c4' }),
|
||||
f.create('Comment', { id: 'c5' }),
|
||||
f.create('Comment', { id: 'c6' }),
|
||||
f.create('Comment', { id: 'c7' })
|
||||
f.create('Comment', { id: 'c7' }),
|
||||
f.create('Comment', { id: 'c8' }),
|
||||
f.create('Comment', { id: 'c9' }),
|
||||
f.create('Comment', { id: 'c10' }),
|
||||
f.create('Comment', { id: 'c11' }),
|
||||
f.create('Comment', { id: 'c12' })
|
||||
])
|
||||
|
||||
await Promise.all([
|
||||
@ -208,7 +213,17 @@ import Factory from './factories'
|
||||
f.relate('Comment', 'Author', { from: 'u3', to: 'c6' }),
|
||||
f.relate('Comment', 'Post', { from: 'c6', to: 'p4' }),
|
||||
f.relate('Comment', 'Author', { from: 'u2', to: 'c7' }),
|
||||
f.relate('Comment', 'Post', { from: 'c7', to: 'p2' })
|
||||
f.relate('Comment', 'Post', { from: 'c7', to: 'p2' }),
|
||||
f.relate('Comment', 'Author', { from: 'u5', to: 'c8' }),
|
||||
f.relate('Comment', 'Post', { from: 'c8', to: 'p15' }),
|
||||
f.relate('Comment', 'Author', { from: 'u6', to: 'c9' }),
|
||||
f.relate('Comment', 'Post', { from: 'c9', to: 'p15' }),
|
||||
f.relate('Comment', 'Author', { from: 'u7', to: 'c10' }),
|
||||
f.relate('Comment', 'Post', { from: 'c10', to: 'p15' }),
|
||||
f.relate('Comment', 'Author', { from: 'u5', to: 'c11' }),
|
||||
f.relate('Comment', 'Post', { from: 'c11', to: 'p15' }),
|
||||
f.relate('Comment', 'Author', { from: 'u6', to: 'c12' }),
|
||||
f.relate('Comment', 'Post', { from: 'c12', to: 'p15' })
|
||||
])
|
||||
|
||||
const disableMutation = 'mutation($id: ID!) { disable(id: $id) }'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user