Remove some deprecated/unnecessary code (#9688)

* refactor: remove mkdirp promisify

* refactor: remove old session deletion API route

* refactor: remove middleware.isAdmin

* refactor: remove templateValues.config.bootswatchSkin

* fix: unused dependencies
v1.18.x
Opliko 4 years ago committed by GitHub
parent 9db28b4b4f
commit d509a307f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,12 +3,7 @@
const path = require('path');
const fs = require('fs');
const util = require('util');
let mkdirp = require('mkdirp');
// TODO: remove in 1.16.0
if (!mkdirp.hasOwnProperty('native')) {
mkdirp = util.promisify(mkdirp);
}
const mkdirp = require('mkdirp');
const rimraf = require('rimraf');
const rimrafAsync = util.promisify(rimraf);

@ -101,7 +101,6 @@ middleware.renderHeader = async function renderHeader(req, res, data) {
results.user.isEmailConfirmSent = !!results.isEmailConfirmSent;
templateValues.bootswatchSkin = (parseInt(meta.config.disableCustomUserSkins, 10) !== 1 ? res.locals.config.bootswatchSkin : '') || meta.config.bootswatchSkin || '';
templateValues.config.bootswatchSkin = templateValues.bootswatchSkin || 'noskin'; // TODO remove in v1.12.0+
templateValues.browserTitle = results.browserTitle;
({
navigation: templateValues.navigation,

@ -1,11 +1,9 @@
'use strict';
const nconf = require('nconf');
const winston = require('winston');
const passport = require('passport');
const util = require('util');
const meta = require('../meta');
const user = require('../user');
const privileges = require('../privileges');
const plugins = require('../plugins');
@ -209,47 +207,6 @@ module.exports = function (middleware) {
controllers.helpers.redirect(res, path);
});
middleware.isAdmin = helpers.try(async (req, res, next) => {
// TODO: Remove in v1.16.0
winston.warn('[middleware] middleware.isAdmin deprecated, use middleware.admin.checkPrivileges instead');
const isAdmin = await user.isAdministrator(req.uid);
if (!isAdmin) {
return controllers.helpers.notAllowed(req, res);
}
const hasPassword = await user.hasPassword(req.uid);
if (!hasPassword) {
return next();
}
const loginTime = req.session.meta ? req.session.meta.datetime : 0;
const adminReloginDuration = meta.config.adminReloginDuration * 60000;
const disabled = meta.config.adminReloginDuration === 0;
if (disabled || (loginTime && parseInt(loginTime, 10) > Date.now() - adminReloginDuration)) {
const timeLeft = parseInt(loginTime, 10) - (Date.now() - adminReloginDuration);
if (req.session.meta && timeLeft < Math.min(300000, adminReloginDuration)) {
req.session.meta.datetime += Math.min(300000, adminReloginDuration);
}
return next();
}
let returnTo = req.path;
if (nconf.get('relative_path')) {
returnTo = req.path.replace(new RegExp(`^${nconf.get('relative_path')}`), '');
}
returnTo = returnTo.replace(/^\/api/, '');
req.session.returnTo = returnTo;
req.session.forceLogin = 1;
if (res.locals.isAPI) {
controllers.helpers.formatApiResponse(401, res);
} else {
res.redirect(`${nconf.get('relative_path')}/login?local=1`);
}
});
middleware.requireUser = function (req, res, next) {
if (req.loggedIn) {
return next();

@ -1,8 +1,5 @@
'use strict';
const winston = require('winston');
const nconf = require('nconf');
const helpers = require('./helpers');
const { setupPageRoute } = helpers;
@ -48,14 +45,6 @@ module.exports = function (app, name, middleware, controllers) {
setupPageRoute(app, `/${name}/:userslug/consent`, middleware, accountMiddlewares, controllers.accounts.consent.get);
setupPageRoute(app, `/${name}/:userslug/blocks`, middleware, accountMiddlewares, controllers.accounts.blocks.getBlocks);
setupPageRoute(app, `/${name}/:userslug/sessions`, middleware, accountMiddlewares, controllers.accounts.sessions.get);
app.delete('/api/user/:userslug/session/:uuid', [middleware.exposeUid], (req, res, next) => {
// TODO: Remove this entire route in v1.16.0
winston.warn('[router] `/api/user/:userslug/session/:uuid` has been deprecated, use `DELETE /api/v3/users/:uid/sessions/:uuid` or `DELETE /api/v3/users/bySlug/:userslug/sessions/:uuid` instead');
if (!res.locals.uid) {
return next();
}
res.redirect(`${nconf.get('relative_path')}/api/v3/users/${res.locals.uid}/sessions/${req.params.uuid}`);
});
setupPageRoute(app, '/notifications', middleware, [middleware.ensureLoggedIn], controllers.accounts.notifications.get);
setupPageRoute(app, `/${name}/:userslug/chats/:roomid?`, middleware, middlewares, controllers.accounts.chats.get);

Loading…
Cancel
Save