diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/errors.js | 6 | ||||
-rw-r--r-- | lib/migrations/20200321153000-fix-account-deletion.js | 61 | ||||
-rw-r--r-- | lib/web/note/util.js | 4 |
3 files changed, 67 insertions, 4 deletions
diff --git a/lib/errors.js b/lib/errors.js index f86e8aa3..950b4cae 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -7,8 +7,10 @@ module.exports = { responseError(res, '403', 'Forbidden', 'oh no.') } else { if (!req.session) req.session = {} - req.session.returnTo = req.originalUrl || config.serverUrl + '/' - req.flash('error', 'You are not allowed to access this page. Maybe try logging in?') + if (req.originalUrl !== '/403') { + req.session.returnTo = config.serverURL + (req.originalUrl || '/') + req.flash('error', 'You are not allowed to access this page. Maybe try logging in?') + } res.redirect(config.serverURL + '/') } }, diff --git a/lib/migrations/20200321153000-fix-account-deletion.js b/lib/migrations/20200321153000-fix-account-deletion.js new file mode 100644 index 00000000..e794e993 --- /dev/null +++ b/lib/migrations/20200321153000-fix-account-deletion.js @@ -0,0 +1,61 @@ +'use strict' +const { spawnSync } = require('child_process') +const path = require('path') +module.exports = { + up: function (queryInterface, Sequelize) { + const cleanup = spawnSync('./bin/cleanup', { cwd: path.resolve(__dirname, '../../') }) + if (cleanup.status !== 0) { + throw new Error('Unable to cleanup') + } + return queryInterface.addConstraint('Notes', ['ownerId'], { + type: 'foreign key', + name: 'Notes_owner_fkey', + references: { + table: 'Users', + field: 'id' + }, + onDelete: 'cascade' + }).then(function () { + return queryInterface.addConstraint('Revisions', ['noteId'], { + type: 'foreign key', + name: 'Revisions_note_fkey', + references: { + table: 'Notes', + field: 'id' + }, + onDelete: 'cascade' + }) + }).then(function () { + return queryInterface.addConstraint('Authors', ['noteId'], { + type: 'foreign key', + name: 'Author_note_fkey', + references: { + table: 'Notes', + field: 'id' + }, + onDelete: 'cascade' + }) + }).then(function () { + return queryInterface.addConstraint('Authors', ['userId'], { + type: 'foreign key', + name: 'Author_user_fkey', + references: { + table: 'Users', + field: 'id' + }, + onDelete: 'cascade' + }) + }) + }, + + down: function (queryInterface, Sequelize) { + return queryInterface.removeConstraint('Notes', 'Notes_owner_fkey') + .then(function () { + return queryInterface.removeConstraint('Revisions', 'Revisions_note_fkey') + }).then(function () { + return queryInterface.removeConstraint('Authors', 'Author_note_fkey') + }).then(function () { + return queryInterface.removeConstraint('Authors', 'Author_user_fkey') + }) + } +} diff --git a/lib/web/note/util.js b/lib/web/note/util.js index eadfb1a3..c5affd05 100644 --- a/lib/web/note/util.js +++ b/lib/web/note/util.js @@ -19,7 +19,7 @@ exports.findNote = function (req, res, callback, include) { include: include || null }).then(function (note) { if (!note) { - return exports.newNote(req, res, null) + return exports.newNote(req, res, '') } if (!exports.checkViewPermission(req, note)) { return errors.errorForbidden(res) @@ -102,7 +102,7 @@ exports.getPublishData = function (req, res, note, callback) { } function isRevealTheme (theme) { - if (fs.existsSync(path.join(__dirname, '..', 'public', 'build', 'reveal.js', 'css', 'theme', theme + '.css'))) { + if (fs.existsSync(path.join(__dirname, '..', '..', '..', 'public', 'build', 'reveal.js', 'css', 'theme', theme + '.css'))) { return theme } return undefined |