diff --git a/backend/src/db/migrations/20200320200315-refactor_all_images_to_separate_type.js b/backend/src/db/migrations/20200320200315-refactor_all_images_to_separate_type.js index d87a19827..9a0a5c30d 100644 --- a/backend/src/db/migrations/20200320200315-refactor_all_images_to_separate_type.js +++ b/backend/src/db/migrations/20200320200315-refactor_all_images_to_separate_type.js @@ -23,7 +23,7 @@ export async function up() { [ ` MATCH (post:Post) - WHERE post.image IS NOT NULL + WHERE post.image IS NOT NULL AND post.deleted = FALSE MERGE(image:Image {url: post.image}) CREATE (post)-[:HERO_IMAGE]->(image) SET @@ -36,14 +36,14 @@ export async function up() { `, ` MATCH (user:User) - WHERE user.avatar IS NOT NULL + WHERE user.avatar IS NOT NULL AND user.deleted = FALSE MERGE(avatar:Image {url: user.avatar}) CREATE (user)-[:AVATAR_IMAGE]->(avatar) REMOVE user.avatar `, ` MATCH (user:User) - WHERE user.coverImg IS NOT NULL + WHERE user.coverImg IS NOT NULL AND user.deleted = FALSE MERGE(coverImage:Image {url: user.coverImg}) CREATE (user)-[:COVER_IMAGE]->(coverImage) REMOVE user.coverImg diff --git a/backend/src/db/migrations/20200323140300-remove_deleted_users_obsolete_attributes.js b/backend/src/db/migrations/20200323140300-remove_deleted_users_obsolete_attributes.js new file mode 100644 index 000000000..8b2134dc5 --- /dev/null +++ b/backend/src/db/migrations/20200323140300-remove_deleted_users_obsolete_attributes.js @@ -0,0 +1,44 @@ +import { getDriver } from '../../db/neo4j' + +export const description = + 'We should not maintain obsolete attributes for users who have been deleted.' + +export async function up(next) { + const driver = getDriver() + const session = driver.session() + const transaction = session.beginTransaction() + const updateDeletedUserAttributes = await transaction.run(` + MATCH (user:User) + WHERE user.deleted = TRUE + SET user.createdAt = 'UNAVAILABLE' + SET user.updatedAt = 'UNAVAILABLE' + SET user.lastActiveAt = 'UNAVAILABLE' + SET user.termsAndConditionsAgreedVersion = 'UNAVAILABLE' + SET user.avatar = null + SET user.coverImg = null + RETURN user {.*}; + `) + try { + // Implement your migration here. + const users = await updateDeletedUserAttributes.records.map(record => record.get('user')) + // eslint-disable-next-line no-console + console.log(users) + await transaction.commit() + next() + } catch (error) { + // eslint-disable-next-line no-console + console.log(error) + await transaction.rollback() + // eslint-disable-next-line no-console + console.log('rolled back') + throw new Error(error) + } finally { + session.close() + } +} + +export async function down(next) { + // eslint-disable-next-line no-console + console.log('Irreversible migration') + next() +} diff --git a/backend/src/db/migrations/20200323160336-remove_deleted_posts_obsolete_attributes.js b/backend/src/db/migrations/20200323160336-remove_deleted_posts_obsolete_attributes.js new file mode 100644 index 000000000..07abf9aeb --- /dev/null +++ b/backend/src/db/migrations/20200323160336-remove_deleted_posts_obsolete_attributes.js @@ -0,0 +1,46 @@ +import { getDriver } from '../../db/neo4j' + +export const description = + 'We should not maintain obsolete attributes for posts which have been deleted.' + +export async function up(next) { + const driver = getDriver() + const session = driver.session() + const transaction = session.beginTransaction() + const updateDeletedPostsAttributes = await transaction.run(` + MATCH (post:Post) + WHERE post.deleted = TRUE + SET post.language = 'UNAVAILABLE' + SET post.createdAt = 'UNAVAILABLE' + SET post.updatedAt = 'UNAVAILABLE' + SET post.content = 'UNAVAILABLE' + SET post.title = 'UNAVAILABLE' + SET post.visibility = 'UNAVAILABLE' + SET post.contentExcerpt = 'UNAVAILABLE' + SET post.image = null + RETURN post {.*}; + `) + try { + // Implement your migration here. + const posts = await updateDeletedPostsAttributes.records.map(record => record.get('post')) + // eslint-disable-next-line no-console + console.log(posts) + await transaction.commit() + next() + } catch (error) { + // eslint-disable-next-line no-console + console.log(error) + await transaction.rollback() + // eslint-disable-next-line no-console + console.log('rolled back') + throw new Error(error) + } finally { + session.close() + } +} + +export async function down(next) { + // eslint-disable-next-line no-console + console.log('Irreversible migration') + next() +} diff --git a/backend/src/middleware/softDelete/softDeleteMiddleware.js b/backend/src/middleware/softDelete/softDeleteMiddleware.js index 8be8c3d39..2e1f60251 100644 --- a/backend/src/middleware/softDelete/softDeleteMiddleware.js +++ b/backend/src/middleware/softDelete/softDeleteMiddleware.js @@ -17,10 +17,10 @@ const obfuscate = async (resolve, root, args, context, info) => { root.contentExcerpt = 'UNAVAILABLE' root.title = 'UNAVAILABLE' root.slug = 'UNAVAILABLE' - root.avatar = 'UNAVAILABLE' + root.avatar = null root.about = 'UNAVAILABLE' root.name = 'UNAVAILABLE' - root.image = null // avoid unecessary 500 errors + root.image = null } return resolve(root, args, context, info) } diff --git a/backend/src/schema/resolvers/users.js b/backend/src/schema/resolvers/users.js index 252265ac3..b2f752143 100644 --- a/backend/src/schema/resolvers/users.js +++ b/backend/src/schema/resolvers/users.js @@ -192,6 +192,9 @@ export default { SET resource.deleted = true SET resource.content = 'UNAVAILABLE' SET resource.contentExcerpt = 'UNAVAILABLE' + SET resource.language = 'UNAVAILABLE' + SET resource.createdAt = 'UNAVAILABLE' + SET resource.updatedAt = 'UNAVAILABLE' SET comment.deleted = true RETURN resource {.*} `, @@ -214,6 +217,11 @@ export default { SET user.deleted = true SET user.name = 'UNAVAILABLE' SET user.about = 'UNAVAILABLE' + SET user.lastActiveAt = 'UNAVAILABLE' + SET user.createdAt = 'UNAVAILABLE' + SET user.updatedAt = 'UNAVAILABLE' + SET user.termsAndConditionsAgreedVersion = 'UNAVAILABLE' + SET user.encryptedPassword = null WITH user OPTIONAL MATCH (user)<-[:BELONGS_TO]-(email:EmailAddress) DETACH DELETE email diff --git a/backend/src/schema/types/type/Post.gql b/backend/src/schema/types/type/Post.gql index 01d8409ad..dc6a00a41 100644 --- a/backend/src/schema/types/type/Post.gql +++ b/backend/src/schema/types/type/Post.gql @@ -201,7 +201,6 @@ type Query { title: String slug: String content: String - image: String visibility: Visibility pinned: Boolean createdAt: String diff --git a/webapp/graphql/PostMutations.js b/webapp/graphql/PostMutations.js index 9120b3e87..602256e01 100644 --- a/webapp/graphql/PostMutations.js +++ b/webapp/graphql/PostMutations.js @@ -23,6 +23,7 @@ export default () => { contentExcerpt language image { + url sensitive } } @@ -52,6 +53,7 @@ export default () => { contentExcerpt language image { + url sensitive aspectRatio }