node_acl icon indicating copy to clipboard operation
node_acl copied to clipboard

How to get all roles and userRoles ?

Open vijaypatoliya opened this issue 10 years ago • 2 comments

vijaypatoliya avatar Feb 18 '16 13:02 vijaypatoliya

hi, don't you have any ideas?

yinzishao avatar Jan 10 '17 09:01 yinzishao

You could do this using your native data storage. There should be a link to it in the Acl object. I used mongo db so yours is probably different. Also the syntax is es7 so might have to do a bit of translating.

import { connect as mongoConnect } from "mongodb";
import acl from "acl";

const connectToMongoDb = () => new Promise((resolve, reject) => {
    mongoConnect(`${process.env.database}/mastermindacl`, (err, db) => {
        if (err) return reject(err);
        else return resolve(db);
    });
});

const findAllRoles = async ({ backend: { db } }) => {
    const collection = await db.collection("acl_roles");
    return new Promise((resolve, reject) => {
        collection.find({}).toArray((err, roles) => {
            if (err) reject(err);
            else resolve(roles);
        });
    });
};

const getAllroles = () => {
    const aclDatabase  = await connectToMongoDb();
    const ACL = new acl(new acl.mongodbBackend(aclDatabase, "acl_"));
    return await findAllRoles(ACL)
}

johnpangalos avatar Jan 31 '17 14:01 johnpangalos