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/schema/resolvers/images.js b/backend/src/schema/resolvers/images.js index 8b3f4a3e8..1f025eda6 100644 --- a/backend/src/schema/resolvers/images.js +++ b/backend/src/schema/resolvers/images.js @@ -2,7 +2,7 @@ import Resolver from './helpers/Resolver' export default { Image: { ...Resolver('Image', { - undefinedToNull: ['sensitive', 'alt', 'aspectRatio'], + undefinedToNull: ['sensitive', 'alt', 'aspectRatio', 'url'], }), }, } 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/Image.gql b/backend/src/schema/types/type/Image.gql index 41cc11eef..d4d9cf1b4 100644 --- a/backend/src/schema/types/type/Image.gql +++ b/backend/src/schema/types/type/Image.gql @@ -1,5 +1,5 @@ type Image { - url: ID!, + url: ID, # urlW34: String, # urlW160: String, # urlW320: 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 }