Wiping more information

Ensuring documents and collections created by user still load
This commit is contained in:
Tom Moor
2018-07-10 19:47:15 -07:00
parent 068f199bb0
commit 22d02da2f9
2 changed files with 15 additions and 9 deletions

View File

@ -141,8 +141,8 @@ Document.associate = models => {
{ {
include: [ include: [
{ model: models.Collection, as: 'collection' }, { model: models.Collection, as: 'collection' },
{ model: models.User, as: 'createdBy' }, { model: models.User, as: 'createdBy', paranoid: false },
{ model: models.User, as: 'updatedBy' }, { model: models.User, as: 'updatedBy', paranoid: false },
], ],
where: { where: {
publishedAt: { publishedAt: {
@ -156,8 +156,8 @@ Document.associate = models => {
Document.addScope('withUnpublished', { Document.addScope('withUnpublished', {
include: [ include: [
{ model: models.Collection, as: 'collection' }, { model: models.Collection, as: 'collection' },
{ model: models.User, as: 'createdBy' }, { model: models.User, as: 'createdBy', paranoid: false },
{ model: models.User, as: 'updatedBy' }, { model: models.User, as: 'updatedBy', paranoid: false },
], ],
}); });
Document.addScope('withViews', userId => ({ Document.addScope('withViews', userId => ({

View File

@ -25,7 +25,7 @@ const User = sequelize.define(
slackData: DataTypes.JSONB, slackData: DataTypes.JSONB,
jwtSecret: encryptedFields.vault('jwtSecret'), jwtSecret: encryptedFields.vault('jwtSecret'),
lastActiveAt: DataTypes.DATE, lastActiveAt: DataTypes.DATE,
lastActiveIp: DataTypes.STRING, lastActiveIp: { type: DataTypes.STRING, allowNull: true },
lastSignedInAt: DataTypes.DATE, lastSignedInAt: DataTypes.DATE,
lastSignedInIp: DataTypes.STRING, lastSignedInIp: DataTypes.STRING,
suspendedAt: DataTypes.DATE, suspendedAt: DataTypes.DATE,
@ -92,12 +92,18 @@ const setRandomJwtSecret = model => {
model.jwtSecret = crypto.randomBytes(64).toString('hex'); model.jwtSecret = crypto.randomBytes(64).toString('hex');
}; };
const removeIdentifyingInfo = model => { const removeIdentifyingInfo = async model => {
model.email = ''; model.email = '';
model.username = ''; model.name = 'Unknown';
model.avatarUrl = '';
model.serviceId = '';
model.username = null;
model.slackData = null; model.slackData = null;
model.serviceId = null; model.lastActiveIp = null;
model.isAdmin = false;
// this shouldn't be needed once this issue is resolved:
// https://github.com/sequelize/sequelize/issues/9318
await model.save({ hooks: false });
}; };
const checkLastAdmin = async model => { const checkLastAdmin = async model => {