I found a good way to get the user list out of mongodb. In case anyone need it:
async function doMongoDb() { const { MongoClient } = require("mongodb"); const username = encodeURIComponent("admin"); const password = encodeURIComponent("mypassword"); const clusterUrl = "localhost:27017"; const authMechanism = "DEFAULT"; const uri = `mongodb://${username}:${password}@${clusterUrl}/?authMechanism=${authMechanism}`; const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true }); try { await client.connect(); const database = client.db("nodebb"); const objects = database.collection("objects"); // get all user const query = { _key: /^user:\d+$/ }; // select fields we want to see const options = { projection: { _id: 0, username: true, _id: false, email: true, "email:confirmed": true, joindate: true, fullname: true }, }; const cursor = objects.find(query, options); if ((await cursor.count()) === 0) { console.log("No user found!"); } // iterate over the users await cursor.forEach(user => { if (user["email:confirmed"] == 1 ) { console.dir(user); } }); } finally { // make sure we close the connection await client.close(); } } // --------------------------------------------------- function init() { try { doMongoDb(); } catch(e) { console.log(e); } } // --------------------------------------------------- init();How do we know if the current user is an adminstrator
-
Hi,
I'm working on a enhancement found on your github : [https://github.com/designcreateplay/NodeBB/issues/929](link url)
I'm wondering which is the best way to know if the current user is an administrator. Actually I use the user.isAdminstrator() method with the req.user.uid parameter is that the best way to get the info?
Thanks for the future answer and keep the good work your forum is awesome!
-
Take a look at
/src/routes/user.js:500
. That conditional filters out all users who are online, but actually have their status set to invisible (which returns "offline" when their user data is returned).Simply add a conditional that does not execute that filtering if an administrator is calling that api call. So, yes,
.isAdministrator()
withreq.user.uid
is the right way to go