node-abac icon indicating copy to clipboard operation
node-abac copied to clipboard

Feature or rules

Open hunha opened this issue 8 years ago • 4 comments

hunha avatar Jan 11 '18 08:01 hunha

Hi @hungnn0790, you're very welcome to open PRs on this repo. Could you provide some details of the additions you've made?

simon-barton avatar Jan 11 '18 09:01 simon-barton

Hi Simon,

I had intended to create a pull request to my forked repository, but I mistaken it(into your), sorry about it.

My additions is for supporting that: if you want to write a rule that's true if any of those given rules true. e.g:

const myPolicy = { 
    attributes: {
        user: {
            id: "User id",
            active: "User active",
            role: "User role"
        },
        product: {
          creatorId: "Creator Id"
        }
    },
    rules: {
        "is-creator": {
            attributes: {
                "user.id": {
                    "comparison_target": "product",
                    "comparison_type": "string",
                    "comparison": "isStrictlyEqual",
                    "field": "creatorId"
                }
            }
        },
        "is-admin": {
            attributes: {
                "user.role": {
                    comparison_type: "array",
                    comparison: "intersect",
                    value: ["ADMIN"]
                }
            }
        },
        "can-delete-product": {
          anyRules: ["is-creator", "is-admin"]
        }
    }
};

And I also want to support to call object_attribute with multiple nested fields like this:

const myPolicy = {
    attributes: {
        user: {
            id: "User id",
            active: "User active",
            company: "User's company"
        },
        product: {
          companyId: "Company Id own this product"
        }
    },
    rules: {
        "can-delete-product": {
            attributes: {
                "user.company.id": {
                    "comparison_target": "product",
                    "comparison_type": "string",
                    "comparison": "isStrictlyEqual",
                    "field": "companyId"
                }
            }
        }
    }
};

P/S: but it isn't well testing and cleaning so I don't want to create a pull request to your repository yet.

hunha avatar Jan 12 '18 07:01 hunha

Hi @hungnn0790,

I really like the anyRules feature, it's a great idea.

Proper testing is something I need to get round to adding to the library and perhaps a small style guide seeing the library is slowly gaining traction.

Either way your contributions are very welcome so update this PR when you're happy with the new features and I'll be happy to merge.

simon-barton avatar Jan 12 '18 08:01 simon-barton

Hi Simon,

Thanks you for your quick feedback.

I've already used it on my company project and I adjusted it due to my needed, but It need some changes to be suited as a public library, so I will fix it and make a PR soon.

hunha avatar Jan 12 '18 11:01 hunha