bluelibs / bluelibs

A collection of open-source software solutions designed for the modern web and enterprise scale.
https://www.bluelibs.com
MIT License
769 stars 23 forks source link

Security solutions for Blueprint #56

Open theodorDiaconu opened 3 years ago

theodorDiaconu commented 3 years ago

Security options with basic option in blueprint, roles, security owner, etc. Keep it in "Collection.security.ts" (overridable) inside the resolvers for GraphQL.

Some thoughts for a primitive API:

// Pure Basic Security Principles
collection({
   security: {
      [Roles.ADMIN]: collection.security.everything,
      [Roles.MANAGER]: ["edit", "create"]
   },
   fields: [ 
       field({
         security: {
             [Roles.ADMIN]: [ "view", "edit", "create" ]
         }
       });
   ]
});
theodorDiaconu commented 2 years ago

API Proposal:

security: {
    roles: {},
    'user': true | false | {} | collection.security.isolated("companyId", "companyId"),
    collection.security.tenant("companyId"),
    'anonymous':  {
        maxLimit: 100,
        maxDepth: 5,
        findOne: true | { filters, intersect },
        find: true | { filters, intersect }, 
        edit: true | { filters, fields: [], inside: "userId" },
        create: true | { own: "userId", fields }
        delete: true | { own: "userId", filters, "identity": "user._id" }
    }
},
fields: [
    field({
             // Should we define field-level security logic? Wouldn't it be too much repetition and ugly blueprints?
    })
]

shield.base.ts which is re-exported inside shield.base {}
// roles imported
export const shield: ShieldConfig<Post> = {
    roles: {

    }
}

shield(config, { resolvers });