mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Filter for blockedUsers/content, fix cypress
This commit is contained in:
parent
d74d2072ba
commit
46c4602db1
@ -0,0 +1,25 @@
|
||||
import { getBlockedUsers, getBlockedByUsers } from '../users.js'
|
||||
import { mergeWith, isArray } from 'lodash'
|
||||
|
||||
export const filterForBlockedUsers = async (params, context) => {
|
||||
if (!context.user) return params
|
||||
const [blockedUsers, blockedByUsers] = await Promise.all([
|
||||
getBlockedUsers(context),
|
||||
getBlockedByUsers(context),
|
||||
])
|
||||
const blockedUsersIds = [...blockedByUsers.map(b => b.id), ...blockedUsers.map(b => b.id)]
|
||||
if (!blockedUsersIds.length) return params
|
||||
|
||||
params.filter = mergeWith(
|
||||
params.filter,
|
||||
{
|
||||
author_not: { id_in: blockedUsersIds },
|
||||
},
|
||||
(objValue, srcValue) => {
|
||||
if (isArray(objValue)) {
|
||||
return objValue.concat(srcValue)
|
||||
}
|
||||
},
|
||||
)
|
||||
return params
|
||||
}
|
||||
@ -1,33 +1,10 @@
|
||||
import uuid from 'uuid/v4'
|
||||
import { neo4jgraphql } from 'neo4j-graphql-js'
|
||||
import { isEmpty } from 'lodash'
|
||||
import fileUpload from './fileUpload'
|
||||
import { getBlockedUsers, getBlockedByUsers } from './users.js'
|
||||
import { mergeWith, isArray, isEmpty } from 'lodash'
|
||||
import { UserInputError } from 'apollo-server'
|
||||
import Resolver from './helpers/Resolver'
|
||||
|
||||
const filterForBlockedUsers = async (params, context) => {
|
||||
if (!context.user) return params
|
||||
const [blockedUsers, blockedByUsers] = await Promise.all([
|
||||
getBlockedUsers(context),
|
||||
getBlockedByUsers(context),
|
||||
])
|
||||
const badIds = [...blockedByUsers.map(b => b.id), ...blockedUsers.map(b => b.id)]
|
||||
if (!badIds.length) return params
|
||||
|
||||
params.filter = mergeWith(
|
||||
params.filter,
|
||||
{
|
||||
author_not: { id_in: badIds },
|
||||
},
|
||||
(objValue, srcValue) => {
|
||||
if (isArray(objValue)) {
|
||||
return objValue.concat(srcValue)
|
||||
}
|
||||
},
|
||||
)
|
||||
return params
|
||||
}
|
||||
import { filterForBlockedUsers } from './helpers/filterForBlockedUsers'
|
||||
|
||||
const maintainPinnedPosts = params => {
|
||||
const pinnedPostFilter = { pinned: true }
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { filterForBlockedUsers } from './helpers/filterForBlockedUsers'
|
||||
|
||||
const transformReturnType = record => {
|
||||
return {
|
||||
__typename: record.get('type'),
|
||||
@ -6,9 +8,10 @@ const transformReturnType = record => {
|
||||
}
|
||||
export default {
|
||||
Query: {
|
||||
findResources: async (_parent, args, context, _resolveInfo) => {
|
||||
const { query, limit } = args
|
||||
const filter = {}
|
||||
findResources: async (_parent, params, context, _resolveInfo) => {
|
||||
params = await filterForBlockedUsers(params, context)
|
||||
const { query, limit } = params
|
||||
const filter = { ...params.filter }
|
||||
const { id: thisUserId } = context.user
|
||||
// see http://lucene.apache.org/core/8_3_1/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#package.description
|
||||
const myQuery = query.replace(/\s/g, '* ') + '*'
|
||||
@ -17,10 +20,10 @@ export default {
|
||||
YIELD node as resource, score
|
||||
MATCH (resource)<-[:WROTE]-(user:User)
|
||||
WHERE score >= 0.5
|
||||
AND NOT user.deleted = true AND NOT user.disabled = true
|
||||
AND NOT resource.deleted = true AND NOT resource.disabled = true
|
||||
AND NOT user.id in COALESCE($filter.author_not.id_in, [])
|
||||
AND NOT (:User { id: $thisUserId })-[:BLOCKED]-(user)
|
||||
AND NOT (user.deleted = true AND NOT user.disabled = true
|
||||
OR resource.deleted = true AND NOT resource.disabled = true
|
||||
OR user.id in COALESCE($filter.author_not.id_in, [])
|
||||
OR (:User { id: $thisUserId })-[:BLOCKED]-(user))
|
||||
RETURN resource, labels(resource)[0] AS type
|
||||
LIMIT $limit
|
||||
`
|
||||
@ -46,8 +49,8 @@ export default {
|
||||
YIELD node as resource, score
|
||||
MATCH (resource)
|
||||
WHERE score >= 0.5
|
||||
AND NOT resource.deleted = true AND NOT resource.disabled = true
|
||||
AND NOT (:User { id: $thisUserId })-[:BLOCKED]-(resource)
|
||||
AND NOT (resource.deleted = true AND NOT resource.disabled = true
|
||||
OR (:User { id: $thisUserId })-[:BLOCKED]-(resource))
|
||||
RETURN resource, labels(resource)[0] AS type
|
||||
LIMIT $limit
|
||||
`
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { When, Then } from "cypress-cucumber-preprocessor/steps";
|
||||
When("I search for {string}", value => {
|
||||
cy.get("#nav-search")
|
||||
cy.get("#search-resources")
|
||||
.focus()
|
||||
.type(value);
|
||||
});
|
||||
@ -25,21 +25,21 @@ Then("I should see the following posts in the select dropdown:", table => {
|
||||
});
|
||||
|
||||
When("I type {string} and press Enter", value => {
|
||||
cy.get("#nav-search")
|
||||
cy.get("#search-resources")
|
||||
.focus()
|
||||
.type(value)
|
||||
.type("{enter}", { force: true });
|
||||
});
|
||||
|
||||
When("I type {string} and press escape", value => {
|
||||
cy.get("#nav-search")
|
||||
cy.get("#search-resources")
|
||||
.focus()
|
||||
.type(value)
|
||||
.type("{esc}");
|
||||
});
|
||||
|
||||
Then("the search field should clear", () => {
|
||||
cy.get("#nav-search").should("have.text", "");
|
||||
cy.get("#search-resources").should("have.text", "");
|
||||
});
|
||||
|
||||
When("I select an entry", () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user