feat: deprecate users collection from MongoDB

User accounts and meta data are only stored in Auth0, for better or worse.

Skipping the useless modified timestamp update on most API calls saves 1 RTT to MongoDB.
parent a2273059
module.exports.modifyUser = function () {
return async function (request, reply) {
const userId = request.req.user.sub
const { db } = this.mongo
await db.collection('users').updateOne(
{ userId },
{
$set: { userId },
$currentDate: { modified: true }
},
{ upsert: true }
)
}
}
const jwtPermissions = require('express-jwt-permissions')
const { modifyUser } = require('../../../hooks/modifyUser')
const isValidDomain = require('is-valid-domain')
const isDomainName = require('is-domain-name')
const { Gone } = require('http-errors')
......@@ -18,9 +17,6 @@ module.exports = async (fastify, options) => {
domain: { type: 'string' }
}
},
beforeHandler: [
modifyUser()
],
handler: async (request, reply) => {
const { db } = fastify.mongo
if (request.query.domain) {
......
const { domainToASCII: toASCII } = require('url')
const jwtPermissions = require('express-jwt-permissions')
const { modifyUser } = require('../../../hooks/modifyUser')
const isDomainName = require('is-domain-name')
const randomSequence = require('../../../helpers/randomSequence')
......@@ -24,9 +23,6 @@ module.exports = async (fastify, options) => {
}
}
},
beforeHandler: [
modifyUser()
],
handler: async (request, reply) => {
const { configuration } = fastify
const { db } = fastify.mongo
......
const jwtPermissions = require('express-jwt-permissions')
const { modifyUser } = require('../../../../hooks/modifyUser')
const { checkDomainAccess } = require('../../../../hooks/checkDomainAccess')
module.exports = async (fastify, options) => {
......@@ -27,7 +26,6 @@ module.exports = async (fastify, options) => {
}
},
beforeHandler: [
modifyUser(),
checkDomainAccess()
],
handler: async (request, reply) => {
......
const jwtPermissions = require('express-jwt-permissions')
const { modifyUser } = require('../../../hooks/modifyUser')
const { checkDomainAccess } = require('../../../hooks/checkDomainAccess')
const { s3cmd } = require('../../../helpers/s3cmd')
......@@ -14,7 +13,6 @@ module.exports = async (fastify, options) => {
url: '/sites/:domain',
schema: {},
beforeHandler: [
modifyUser(),
checkDomainAccess()
],
handler: async (request, reply) => {
......
......@@ -4,7 +4,6 @@ const { createReadStream, createWriteStream } = require('fs')
const { rename } = require('graceful-fs')
const mkdirp = require('mkdirp')
const tmp = require('tmp-promise')
const { modifyUser } = require('../../../hooks/modifyUser')
const mime = require('mime/lite')
const compressible = require('compressible')
const { compressStream: brotli } = require('iltorb')
......@@ -61,9 +60,6 @@ module.exports = async (fastify, options) => {
}
}
},
beforeHandler: [
modifyUser()
],
handler: async (request, reply) => {
const { configuration } = fastify
const { db } = fastify.mongo
......
......@@ -11,13 +11,6 @@ test('Setup database fixtures', async (t) => {
const userId = await getUserId()
const modified = new Date()
await mongo.db.collection('users').deleteMany()
await mongo.db.collection('users').insertMany([
{
modified,
userId
}
])
await mongo.db.collection('hosts').deleteMany()
await mongo.db.collection('hosts').insertMany([
{
......
......@@ -18,11 +18,6 @@ test('Setup database fixtures', async (t) => {
fixture.modified = new Date()
fixture.configuration = { foo: 'bar' }
await mongo.db.collection('users').deleteMany()
await mongo.db.collection('users').insertMany([{
modified: fixture.modified,
userId: fixture.userId
}])
await mongo.db.collection('hosts').deleteMany()
await mongo.db.collection('hosts').insertMany([{
modified: fixture.modified,
......
......@@ -22,11 +22,6 @@ test('Setup database fixtures', async (t) => {
fixture.configuration = {}
fixture.san = []
await mongo.db.collection('users').deleteMany()
await mongo.db.collection('users').insertMany([{
modified: fixture.modified,
userId: fixture.userId
}])
await mongo.db.collection('hosts').deleteMany()
await mongo.db.collection('hosts').insertMany([{
modified: fixture.modified,
......
......@@ -24,11 +24,6 @@ test('Setup database fixtures', async (t) => {
fixture.modified = new Date()
fixture.domain = 'fixture.example.net'
await mongo.db.collection('users').deleteMany()
await mongo.db.collection('users').insertMany([{
modified: fixture.modified,
userId: fixture.userId
}])
await mongo.db.collection('hosts').deleteMany()
await mongo.db.collection('configurations').deleteMany()
await mongo.db.collection('certificates').deleteMany()
......
......@@ -14,11 +14,6 @@ test('Setup database fixtures', async (t) => {
fixture.modified = new Date()
fixture.configuration = {}
await mongo.db.collection('users').deleteMany()
await mongo.db.collection('users').insertMany([{
modified: fixture.modified,
userId: fixture.userId
}])
await mongo.db.collection('hosts').deleteMany()
await mongo.db.collection('hosts').insertMany([{
modified: fixture.modified,
......
......@@ -3,17 +3,8 @@ const configuration = require('../core.conf.example.js')
const { getUserAccessToken, getUserId } = require('./helpers/credentials')
const { fetch } = require('./helpers/fetch')
const mongo = require('./helpers/database')(configuration)
require('./helpers/setup')(configuration)
test('Setup database fixtures', async (t) => {
await mongo.db.collection('users').deleteMany()
await mongo.db.collection('users').insertMany([{
modified: new Date(),
userId: await getUserId()
}])
})
test('Change email address', async (t) => {
const accessToken = await getUserAccessToken()
const userId = await getUserId()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment