update libflitter/flap & run migrations

master
Garrett Mills 5 years ago
parent d25b54da88
commit 33aa97ee49

@ -3,7 +3,8 @@
* ------------------------------------------------------------- * -------------------------------------------------------------
* Put some description here! * Put some description here!
*/ */
class Debug { const Middleware = require('libflitter/middleware/Middleware')
class Debug extends Middleware {
/* /*
* Run the middleware test. * Run the middleware test.
@ -11,10 +12,10 @@ class Debug {
* It should either call the next function in the stack, * It should either call the next function in the stack,
* or it should handle the response accordingly. * or it should handle the response accordingly.
*/ */
test(req, res, next, args = {}){ test(req, res, next, args = {}) {
console.log('DEBUGGING LAYER:') console.log('DEBUGGING LAYER:')
console.log('Incoming destination: '+req.originalUrl) console.log('Incoming destination: ' + req.originalUrl)
console.log('Incoming method: '+req.method) console.log('Incoming method: ' + req.method)
/* /*
* Call the next function in the stack. * Call the next function in the stack.
@ -23,4 +24,4 @@ class Debug {
} }
} }
module.exports = Debug module.exports = Debug

@ -6,7 +6,8 @@
* the '/' route is accessed. It can be injected in routes globally using * the '/' route is accessed. It can be injected in routes globally using
* the global mw() function. * the global mw() function.
*/ */
class HomeLogger { const Middleware = require('libflitter/middleware/Middleware')
class HomeLogger extends Middleware {
/* /*
* Run the middleware test. * Run the middleware test.
@ -14,7 +15,7 @@ class HomeLogger {
* It should either call the next function in the stack, * It should either call the next function in the stack,
* or it should handle the response accordingly. * or it should handle the response accordingly.
*/ */
test(req, res, next){ test(req, res, next) {
console.log("Home was accessed!") console.log("Home was accessed!")
/* /*

@ -8,7 +8,8 @@
* *
* @class * @class
*/ */
class Permission { const Middleware = require('libflitter/middleware/Middleware')
class Permission extends Middleware {
/** /**
* Run the middleware's check. If an authenticated session exists and the user has the specified permission, * Run the middleware's check. If an authenticated session exists and the user has the specified permission,
@ -19,31 +20,33 @@ class Permission {
* @param {Function} next - Express handler stack callback. This should be called if the middleware check passed to allow the request to continue. * @param {Function} next - Express handler stack callback. This should be called if the middleware check passed to allow the request to continue.
* @param {string} permission - Name of the permission to require * @param {string} permission - Name of the permission to require
*/ */
async test(req, res, next, permission){ async test(req, res, next, permission) {
if ( req.session && req.session.auth && (req.session.auth.authenticated === true || req.session.auth.user) ){ if (req.session && req.session.auth && (req.session.auth.authenticated === true || req.session.auth.user)) {
if ( req.session.auth.user.permissions && req.session.auth.user.permissions.includes(permission) ){ if (req.session.auth.user.permissions && req.session.auth.user.permissions.includes(permission)) {
next() next()
} } else if (req.session.auth.user.role) {
else if ( req.session.auth.user.role ){
const Role = _flitter.model('auth:Role') const Role = _flitter.model('auth:Role')
const role = await Role.findOne({name: req.session.auth.user.role}) const role = await Role.findOne({
name: req.session.auth.user.role
})
if ( role.permissions.includes(permission) ){ if (role.permissions.includes(permission)) {
next() next()
} else {
return _flitter.error(res, 401, {
reason: 'Insufficient user permissions.'
})
} }
else { } else {
return _flitter.error(res, 401, {reason: 'Insufficient user permissions.'}) return _flitter.error(res, 401, {
} reason: 'Insufficient user permissions.'
})
} }
else { } else {
return _flitter.error(res, 401, {reason: 'Insufficient user permissions.'})
}
}
else {
req.session.destination = req.originalUrl req.session.destination = req.originalUrl
return res.redirect('/auth/login') return res.redirect('/auth/login')
} }
} }
} }
module.exports = Permission module.exports = Permission

@ -8,7 +8,8 @@
* *
* @class * @class
*/ */
class RequireAuth { const Middleware = require('libflitter/middleware/Middleware')
class RequireAuth extends Middleware {
/** /**
* Run the middleware's check. If an authenticated session exists, let the request continue. * Run the middleware's check. If an authenticated session exists, let the request continue.
@ -18,14 +19,13 @@ class RequireAuth {
* @param {Express/Response} res - the corresponding Express response * @param {Express/Response} res - the corresponding Express response
* @param {Function} next - Express handler stack callback. This should be called if the middleware check passed to allow the request to continue. * @param {Function} next - Express handler stack callback. This should be called if the middleware check passed to allow the request to continue.
*/ */
test(req, res, next){ test(req, res, next) {
if ( req.session && req.session.auth && (req.session.auth.authenticated === true || req.session.auth.user) ){ if (req.session && req.session.auth && (req.session.auth.authenticated === true || req.session.auth.user)) {
/* /*
* Call the next function in the stack. * Call the next function in the stack.
*/ */
next() next()
} } else {
else {
req.session.destination = req.originalUrl req.session.destination = req.originalUrl
return res.redirect('/auth/login') return res.redirect('/auth/login')
} }

@ -8,7 +8,8 @@
* *
* @class * @class
*/ */
class RequireGuest { const Middleware = require('libflitter/middleware/Middleware')
class RequireGuest extends Middleware {
/** /**
* Run the middleware test. If an authenticated session exists, redirect the user to an error page. * Run the middleware test. If an authenticated session exists, redirect the user to an error page.
@ -17,8 +18,8 @@ class RequireGuest {
* @param {Express/Response} res - the corresponding Express response * @param {Express/Response} res - the corresponding Express response
* @param {Function} next - The callback to continue the Express request handling stack. This is called if the middleware check passes. * @param {Function} next - The callback to continue the Express request handling stack. This is called if the middleware check passes.
*/ */
test(req, res, next){ test(req, res, next) {
if ( req.session && req.session.auth && (req.session.auth.authenticated === true || req.session.auth.user) ){ if (req.session && req.session.auth && (req.session.auth.authenticated === true || req.session.auth.user)) {
return _flitter.view(res, 'errors/requires_guest') return _flitter.view(res, 'errors/requires_guest')
} }

@ -8,7 +8,8 @@
* *
* @class * @class
*/ */
class Role { const Middleware = require('libflitter/middleware/Middleware')
class Role extends Middleware {
/** /**
* Run the middleware's check. If an authenticated session exists and the user has the specified role, * Run the middleware's check. If an authenticated session exists and the user has the specified role,
@ -19,20 +20,20 @@ class Role {
* @param {Function} next - Express handler stack callback. This should be called if the middleware check passed to allow the request to continue. * @param {Function} next - Express handler stack callback. This should be called if the middleware check passed to allow the request to continue.
* @param {string} role - Name of the role to require * @param {string} role - Name of the role to require
*/ */
test(req, res, next, role){ test(req, res, next, role) {
if ( req.session && req.session.auth && (req.session.auth.authenticated === true || req.session.auth.user) ){ if (req.session && req.session.auth && (req.session.auth.authenticated === true || req.session.auth.user)) {
if ( req.session.auth.user.role && req.session.auth.user.role === role ){ if (req.session.auth.user.role && req.session.auth.user.role === role) {
next() next()
} else {
return _flitter.error(res, 401, {
reason: 'Insufficient user permissions.'
})
} }
else { } else {
return _flitter.error(res, 401, {reason: 'Insufficient user permissions.'})
}
}
else {
req.session.destination = req.originalUrl req.session.destination = req.originalUrl
return res.redirect('/auth/login') return res.redirect('/auth/login')
} }
} }
} }
module.exports = Role module.exports = Role

@ -3,7 +3,8 @@
* ------------------------------------------------------------- * -------------------------------------------------------------
* Put some description here! * Put some description here!
*/ */
class Invite { const Middleware = require('libflitter/middleware/Middleware')
class Invite extends Middleware {
/* /*
* Run the middleware test. * Run the middleware test.
@ -11,8 +12,8 @@ class Invite {
* It should either call the next function in the stack, * It should either call the next function in the stack,
* or it should handle the response accordingly. * or it should handle the response accordingly.
*/ */
test(req, res, next, args = {}){ test(req, res, next, args = {}) {
if ( req.session.invite && !req.originalUrl.includes('/dash/v1/invitation/accept') ){ if (req.session.invite && !req.originalUrl.includes('/dash/v1/invitation/accept')) {
return res.redirect('/dash/v1/invitation/accept') return res.redirect('/dash/v1/invitation/accept')
} }

@ -23,5 +23,10 @@
"id": 1565741502, "id": 1565741502,
"name": "convert_to_new_model_schema_definitions", "name": "convert_to_new_model_schema_definitions",
"migratedOn": "2019-08-15T14:58:30.109Z" "migratedOn": "2019-08-15T14:58:30.109Z"
},
{
"id": 1565925593,
"name": "make_existing_middleware_extend_base_class",
"migratedOn": "2019-08-16T14:49:39.934Z"
} }
] ]

@ -18,11 +18,11 @@
"dependencies": { "dependencies": {
"flitter-auth": "^0.4.0", "flitter-auth": "^0.4.0",
"flitter-cli": "^0.10.0", "flitter-cli": "^0.10.0",
"flitter-flap": "^0.3.1", "flitter-flap": "^0.4.0",
"flitter-forms": "^0.7.2", "flitter-forms": "^0.7.2",
"flitter-upload": "^0.7.6", "flitter-upload": "^0.7.6",
"js-beautify": "^1.10.2", "js-beautify": "^1.10.2",
"libflitter": "^0.28.0", "libflitter": "^0.29.3",
"stringify-object": "^3.3.0" "stringify-object": "^3.3.0"
} }
} }

@ -869,10 +869,10 @@ flitter-cli@^0.10.0:
mkdirp "^0.5.1" mkdirp "^0.5.1"
nesh "^1.7.0" nesh "^1.7.0"
flitter-flap@^0.3.1: flitter-flap@^0.4.0:
version "0.3.1" version "0.4.0"
resolved "https://registry.yarnpkg.com/flitter-flap/-/flitter-flap-0.3.1.tgz#12dca0f43a6bfefd89b9e461b1eb1f1e7db18cd9" resolved "https://registry.yarnpkg.com/flitter-flap/-/flitter-flap-0.4.0.tgz#ab1cdfc5b9ffe0b5b9fe2e3a8bdc87e9aac82c0e"
integrity sha512-I22gvdK3cKCnQZGVXwtbgtWTkCakhZGs46K5g+UcoKYurHhjo+9+rqsPGZbYzIcFIhwPJTyv3Ve5aZprDz22WQ== integrity sha512-1pfGAckDJ7RZIK6qheAz2dwA4PV/03Z7rPhhVuDqZbuemtiozLgDLPQXzGwSLQESWNuG6CBg3KMEd0CPppB1/Q==
dependencies: dependencies:
del "^4.1.0" del "^4.1.0"
js-beautify "^1.10.2" js-beautify "^1.10.2"
@ -1274,10 +1274,10 @@ leven@^1.0.2:
resolved "https://registry.yarnpkg.com/leven/-/leven-1.0.2.tgz#9144b6eebca5f1d0680169f1a6770dcea60b75c3" resolved "https://registry.yarnpkg.com/leven/-/leven-1.0.2.tgz#9144b6eebca5f1d0680169f1a6770dcea60b75c3"
integrity sha1-kUS27ryl8dBoAWnxpncNzqYLdcM= integrity sha1-kUS27ryl8dBoAWnxpncNzqYLdcM=
libflitter@^0.28.0: libflitter@^0.29.3:
version "0.28.0" version "0.29.3"
resolved "https://registry.yarnpkg.com/libflitter/-/libflitter-0.28.0.tgz#c132dfb74e3a3e6148e924ce5ab9fc6094a6625c" resolved "https://registry.yarnpkg.com/libflitter/-/libflitter-0.29.3.tgz#b3daaac4405599b51f943fd1331a576db6bb9a2d"
integrity sha512-s7m0odIm96QcuycJ4GUyu4Ub6zooCtXnIRjXccAgkKMMkz1I84qT0+DO6tRiSBPlnxA9lXpDjrAzyY0Z5OpQmw== integrity sha512-3W6Mack+U5s7YAN6ItIClI+Q9gAqeOlioHleU1LyilFAwmZxth098mRd+pV0ZLGomtzIeyxJcmP9bYg7RC62pg==
dependencies: dependencies:
busboy-body-parser "^0.3.2" busboy-body-parser "^0.3.2"
connect-mongodb-session "^2.2.0" connect-mongodb-session "^2.2.0"

Loading…
Cancel
Save