-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
2,483 additions
and
2,322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,5 +213,8 @@ | |
"maxFileSize": 50000, | ||
"baseFolder": null, | ||
"baseURL": null | ||
}, | ||
"encryption": { | ||
"salt": "superSecretSalt" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,5 +173,8 @@ | |
"maxFileSize": 50000, | ||
"baseFolder": "", | ||
"baseURL": "" | ||
}, | ||
"encryption": { | ||
"salt": "superSecretSalt" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
db/migrations/202103251231-alter-vote-lists-add-userhash.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
const config = require('config'); | ||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.sequelize.transaction((t) => { | ||
return Promise.all([ | ||
queryInterface.addColumn('VoteLists', 'userHash', { | ||
type: Sequelize.STRING(64), | ||
comment: 'Hash from users PID that allows filtering votes from different users, but same person' | ||
}, { transaction: t }), | ||
queryInterface.sequelize.query(`CREATE EXTENSION IF NOT EXISTS pgcrypto;`, {transaction: t}), | ||
queryInterface.sequelize.query(`UPDATE "VoteLists" vlt SET "userHash" = encode(hmac(v.id || uc."connectionUserId", '${config.encryption.salt}', 'sha256'), 'hex') FROM "VoteLists" vl JOIN "Votes" v ON v.id = vl."voteId" AND v."authType" = 'hard' JOIN "UserConnections" uc ON uc."userId"::text = vl."userId"::text AND uc."connectionId" = 'esteid' WHERE vl."optionGroupId" = vlt."optionGroupId" AND vl."optionId" = vlt."optionId";`, {transaction: t}) | ||
]) | ||
}) | ||
}, | ||
down: (queryInterface) => { | ||
return queryInterface.sequelize.transaction((t) => { | ||
return Promise.all([ | ||
queryInterface.removeColumn('VoteLists', 'userHash', { transaction: t }) | ||
]) | ||
}) | ||
} | ||
}; |
42 changes: 42 additions & 0 deletions
42
db/migrations/20210329141948-alter-vote-user-containers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.sequelize.transaction((t) => { | ||
return Promise.all([ | ||
queryInterface.addColumn('VoteUserContainers', 'PID', { | ||
type: Sequelize.TEXT, | ||
comment: 'User personal ID' | ||
}, { transaction: t }), | ||
queryInterface.sequelize.query(`UPDATE "VoteUserContainers" vuc SET "PID" = vuc."userId"::text WHERE vuc."userId" IS NOT NULL;`, {transaction: t}), | ||
queryInterface.sequelize.query(`UPDATE "VoteUserContainers" vuc SET "PID" = uc."connectionUserId"::text FROM "UserConnections" uc WHERE uc."userId"::text = vuc."userId"::text AND uc."connectionId" = 'esteid';`, {transaction: t}), | ||
queryInterface.sequelize.query(`DELETE FROM "VoteUserContainers" a USING (SELECT "voteId", "PID", MAX("createdAt") as "createdAt" FROM "VoteUserContainers" GROUP BY "voteId", "PID") b WHERE a."voteId" = b."voteId" AND a."PID" = b."PID" AND a."createdAt" < b."createdAt";`, {transaction: t}), | ||
queryInterface.changeColumn('VoteUserContainers', 'PID', { | ||
type: Sequelize.TEXT, | ||
allowNull: false, | ||
}, {transaction: t}), | ||
queryInterface.removeConstraint('VoteUserContainers','VoteUserContainers_pkey', {transaction: t}), | ||
queryInterface.addConstraint('VoteUserContainers',{ | ||
fields: ['voteId', 'PID'], | ||
type: 'primary key', | ||
name: 'VoteUserContainers_pkey', | ||
transaction: t | ||
}) | ||
]) | ||
}) | ||
}, | ||
down: (queryInterface) => { | ||
return queryInterface.sequelize.transaction((t) => { | ||
return Promise.all([ | ||
queryInterface.removeConstraint('VoteUserContainers','VoteUserContainers_pkey', {transaction: t}), | ||
queryInterface.addConstraint('VoteUserContainers',{ | ||
fields: ['voteId', 'userId'], | ||
type: 'primary key', | ||
name: 'VoteUserContainers_pkey', | ||
transaction: t | ||
}), | ||
queryInterface.removeColumn('VoteUserContainers', 'PID', { transaction: t }) | ||
]) | ||
}) | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.