mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 08:25:46 +01:00
Added block and unblock button to profile dropdown menu, #6560
This commit is contained in:
@@ -33,6 +33,8 @@
|
|||||||
"following": "Following",
|
"following": "Following",
|
||||||
"blocks": "Blocks",
|
"blocks": "Blocks",
|
||||||
"block_toggle": "Toggle Block",
|
"block_toggle": "Toggle Block",
|
||||||
|
"block_user": "Block User",
|
||||||
|
"unblock_user": "Unblock User",
|
||||||
"aboutme": "About me",
|
"aboutme": "About me",
|
||||||
"signature": "Signature",
|
"signature": "Signature",
|
||||||
"birthday": "Birthday",
|
"birthday": "Birthday",
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ define('forum/account/header', [
|
|||||||
components.get('account/unban').on('click', unbanAccount);
|
components.get('account/unban').on('click', unbanAccount);
|
||||||
components.get('account/delete').on('click', deleteAccount);
|
components.get('account/delete').on('click', deleteAccount);
|
||||||
components.get('account/flag').on('click', flagAccount);
|
components.get('account/flag').on('click', flagAccount);
|
||||||
|
components.get('account/block').on('click', toggleBlockAccount);
|
||||||
};
|
};
|
||||||
|
|
||||||
function hidePrivateLinks() {
|
function hidePrivateLinks() {
|
||||||
@@ -191,6 +192,25 @@ define('forum/account/header', [
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleBlockAccount() {
|
||||||
|
var targetEl = this;
|
||||||
|
socket.emit('user.toggleBlock', {
|
||||||
|
blockeeUid: ajaxify.data.uid,
|
||||||
|
blockerUid: app.user.uid,
|
||||||
|
}, function (err, blocked) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
translator.translate('[[user:' + (blocked ? 'unblock' : 'block') + '_user]]', function (label) {
|
||||||
|
$(targetEl).text(label);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Keep dropdown open
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function removeCover() {
|
function removeCover() {
|
||||||
translator.translate('[[user:remove_cover_picture_confirm]]', function (translated) {
|
translator.translate('[[user:remove_cover_picture_confirm]]', function (translated) {
|
||||||
bootbox.confirm(translated, function (confirm) {
|
bootbox.confirm(translated, function (confirm) {
|
||||||
|
|||||||
@@ -91,6 +91,9 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
|
|||||||
canBanUser: function (next) {
|
canBanUser: function (next) {
|
||||||
privileges.users.canBanUser(callerUID, uid, next);
|
privileges.users.canBanUser(callerUID, uid, next);
|
||||||
},
|
},
|
||||||
|
isBlocked: function (next) {
|
||||||
|
user.blocks.is(uid, callerUID, next);
|
||||||
|
},
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
@@ -129,6 +132,11 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
|
|||||||
userData.moderationNote = undefined;
|
userData.moderationNote = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
userData.isBlocked = results.isBlocked;
|
||||||
|
if (isAdmin || isSelf) {
|
||||||
|
userData.blocksCount = parseInt(userData.blocksCount, 10) || 0;
|
||||||
|
}
|
||||||
|
|
||||||
userData.yourid = callerUID;
|
userData.yourid = callerUID;
|
||||||
userData.theirid = userData.uid;
|
userData.theirid = userData.uid;
|
||||||
userData.isTargetAdmin = results.isTargetAdmin;
|
userData.isTargetAdmin = results.isTargetAdmin;
|
||||||
@@ -165,7 +173,6 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
|
|||||||
userData.websiteName = userData.website.replace(validator.escape('http://'), '').replace(validator.escape('https://'), '');
|
userData.websiteName = userData.website.replace(validator.escape('http://'), '').replace(validator.escape('https://'), '');
|
||||||
userData.followingCount = parseInt(userData.followingCount, 10) || 0;
|
userData.followingCount = parseInt(userData.followingCount, 10) || 0;
|
||||||
userData.followerCount = parseInt(userData.followerCount, 10) || 0;
|
userData.followerCount = parseInt(userData.followerCount, 10) || 0;
|
||||||
userData.blocksCount = parseInt(userData.blocksCount, 10) || 0;
|
|
||||||
|
|
||||||
userData.email = validator.escape(String(userData.email || ''));
|
userData.email = validator.escape(String(userData.email || ''));
|
||||||
userData.fullname = validator.escape(String(userData.fullname || ''));
|
userData.fullname = validator.escape(String(userData.fullname || ''));
|
||||||
|
|||||||
@@ -223,16 +223,4 @@ module.exports = function (middleware) {
|
|||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
middleware.handleBlocking = function (req, res, next) {
|
|
||||||
user.blocks.is(res.locals.uid, req.uid, function (err, blocked) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
} else if (blocked) {
|
|
||||||
res.status(404).render('404', { title: '[[global:404.title]]' });
|
|
||||||
} else {
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ var helpers = require('./helpers');
|
|||||||
var setupPageRoute = helpers.setupPageRoute;
|
var setupPageRoute = helpers.setupPageRoute;
|
||||||
|
|
||||||
module.exports = function (app, middleware, controllers) {
|
module.exports = function (app, middleware, controllers) {
|
||||||
var middlewares = [middleware.checkGlobalPrivacySettings, middleware.exposeUid, middleware.handleBlocking];
|
var middlewares = [middleware.checkGlobalPrivacySettings, middleware.exposeUid];
|
||||||
var accountMiddlewares = [middleware.checkGlobalPrivacySettings, middleware.checkAccountPermissions, middleware.exposeUid, middleware.handleBlocking];
|
var accountMiddlewares = [middleware.checkGlobalPrivacySettings, middleware.checkAccountPermissions, middleware.exposeUid];
|
||||||
|
|
||||||
setupPageRoute(app, '/me/*', middleware, [], middleware.redirectMeToUserslug);
|
setupPageRoute(app, '/me/*', middleware, [], middleware.redirectMeToUserslug);
|
||||||
setupPageRoute(app, '/uid/:uid*', middleware, [], middleware.redirectUidToUserslug);
|
setupPageRoute(app, '/uid/:uid*', middleware, [], middleware.redirectUidToUserslug);
|
||||||
|
|||||||
@@ -201,6 +201,8 @@ module.exports = function (SocketUser) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SocketUser.toggleBlock = function (socket, data, callback) {
|
SocketUser.toggleBlock = function (socket, data, callback) {
|
||||||
|
let current;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
user.blocks.can(socket.uid, data.blockerUid, data.blockeeUid, next);
|
user.blocks.can(socket.uid, data.blockerUid, data.blockeeUid, next);
|
||||||
@@ -212,8 +214,11 @@ module.exports = function (SocketUser) {
|
|||||||
user.blocks.is(data.blockeeUid, data.blockerUid, next);
|
user.blocks.is(data.blockeeUid, data.blockerUid, next);
|
||||||
},
|
},
|
||||||
function (is, next) {
|
function (is, next) {
|
||||||
|
current = is;
|
||||||
user.blocks[is ? 'remove' : 'add'](data.blockeeUid, data.blockerUid, next);
|
user.blocks[is ? 'remove' : 'add'](data.blockeeUid, data.blockerUid, next);
|
||||||
},
|
},
|
||||||
], callback);
|
], function (err) {
|
||||||
|
callback(err, !current);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user