mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Remove global filters for disabled/deleted
I think there is no use case for it and it looks to me like sth. you shouldn't be able to query for.
This commit is contained in:
parent
034a353367
commit
0e3ace36fb
@ -41,20 +41,6 @@ const isMySocialMedia = rule({
|
|||||||
return socialMedia.ownedBy.node.id === user.id
|
return socialMedia.ownedBy.node.id === user.id
|
||||||
})
|
})
|
||||||
|
|
||||||
/* TODO: decide if we want to remove this check: the check
|
|
||||||
* `onlyEnabledContent` throws authorization errors only if you have
|
|
||||||
* arguments for `disabled` or `deleted` assuming these are filter
|
|
||||||
* parameters. Soft-delete middleware obfuscates data on its way out
|
|
||||||
* anyways. Furthermore, `neo4j-graphql-js` offers many ways to filter for
|
|
||||||
* data so I believe, this is not a good check anyways.
|
|
||||||
*/
|
|
||||||
const onlyEnabledContent = rule({
|
|
||||||
cache: 'strict',
|
|
||||||
})(async (parent, args, ctx, info) => {
|
|
||||||
const { disabled, deleted } = args
|
|
||||||
return !(disabled || deleted)
|
|
||||||
})
|
|
||||||
|
|
||||||
const invitationLimitReached = rule({
|
const invitationLimitReached = rule({
|
||||||
cache: 'no_cache',
|
cache: 'no_cache',
|
||||||
})(async (parent, args, { user, driver }) => {
|
})(async (parent, args, { user, driver }) => {
|
||||||
@ -125,7 +111,8 @@ const permissions = shield(
|
|||||||
reports: isModerator,
|
reports: isModerator,
|
||||||
statistics: allow,
|
statistics: allow,
|
||||||
currentUser: allow,
|
currentUser: allow,
|
||||||
Post: or(onlyEnabledContent, isModerator),
|
Post: allow,
|
||||||
|
profilePagePosts: allow,
|
||||||
Comment: allow,
|
Comment: allow,
|
||||||
User: or(noEmailFilter, isAdmin),
|
User: or(noEmailFilter, isAdmin),
|
||||||
isLoggedIn: allow,
|
isLoggedIn: allow,
|
||||||
@ -134,7 +121,6 @@ const permissions = shield(
|
|||||||
PostsEmotionsByCurrentUser: isAuthenticated,
|
PostsEmotionsByCurrentUser: isAuthenticated,
|
||||||
blockedUsers: isAuthenticated,
|
blockedUsers: isAuthenticated,
|
||||||
notifications: isAuthenticated,
|
notifications: isAuthenticated,
|
||||||
profilePagePosts: or(onlyEnabledContent, isModerator),
|
|
||||||
Donations: isAuthenticated,
|
Donations: isAuthenticated,
|
||||||
},
|
},
|
||||||
Mutation: {
|
Mutation: {
|
||||||
|
|||||||
@ -3,9 +3,7 @@ const isModerator = ({ user }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const setDefaultFilters = (resolve, root, args, context, info) => {
|
const setDefaultFilters = (resolve, root, args, context, info) => {
|
||||||
if (typeof args.deleted !== 'boolean') {
|
args.deleted = false
|
||||||
args.deleted = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isModerator(context)) {
|
if (!isModerator(context)) {
|
||||||
args.disabled = false
|
args.disabled = false
|
||||||
|
|||||||
@ -341,76 +341,6 @@ describe('softDeleteMiddleware', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('filter (deleted: true)', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
graphqlQuery = gql`
|
|
||||||
{
|
|
||||||
Post(deleted: true) {
|
|
||||||
title
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('as user', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
authenticatedUser = await user.toJson()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('throws authorisation error', async () => {
|
|
||||||
const { data, errors } = await action()
|
|
||||||
expect(data).toEqual({ Post: null })
|
|
||||||
expect(errors[0]).toHaveProperty('message', 'Not Authorised!')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('as moderator', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
authenticatedUser = await moderator.toJson()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('does not show deleted posts', async () => {
|
|
||||||
const expected = { data: { Post: [{ title: 'UNAVAILABLE' }] } }
|
|
||||||
await expect(action()).resolves.toMatchObject(expected)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('filter (disabled: true)', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
graphqlQuery = gql`
|
|
||||||
{
|
|
||||||
Post(disabled: true) {
|
|
||||||
title
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('as user', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
authenticatedUser = await user.toJson()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('throws authorisation error', async () => {
|
|
||||||
const { data, errors } = await action()
|
|
||||||
expect(data).toEqual({ Post: null })
|
|
||||||
expect(errors[0]).toHaveProperty('message', 'Not Authorised!')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('as moderator', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
authenticatedUser = await moderator.toJson()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('shows disabled posts', async () => {
|
|
||||||
const expected = { data: { Post: [{ title: 'Disabled post' }] } }
|
|
||||||
await expect(action()).resolves.toMatchObject(expected)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user