{"id":16227627,"url":"https://github.com/leafoftree/simple-mongoose-rbac","last_synced_at":"2025-07-25T09:04:58.565Z","repository":{"id":57360471,"uuid":"75687973","full_name":"leafOfTree/simple-mongoose-rbac","owner":"leafOfTree","description":"Role based access control for mongoose, a simple user authority manager solution.","archived":false,"fork":false,"pushed_at":"2016-12-08T03:21:26.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T23:35:36.940Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leafOfTree.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-06T02:48:38.000Z","updated_at":"2024-04-25T02:10:45.000Z","dependencies_parsed_at":"2022-09-06T22:22:31.244Z","dependency_job_id":null,"html_url":"https://github.com/leafOfTree/simple-mongoose-rbac","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafOfTree%2Fsimple-mongoose-rbac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafOfTree%2Fsimple-mongoose-rbac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafOfTree%2Fsimple-mongoose-rbac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafOfTree%2Fsimple-mongoose-rbac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leafOfTree","download_url":"https://codeload.github.com/leafOfTree/simple-mongoose-rbac/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247777925,"owners_count":20994378,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T12:53:21.014Z","updated_at":"2025-04-08T04:28:24.796Z","avatar_url":"https://github.com/leafOfTree.png","language":"JavaScript","readme":"# simple-mongoose-rbac\nRole based access control for mongoose, a simple user authority manager solution.\n\n[![Build Status](https://travis-ci.org/leafOfTree/simple-mongoose-rbac.svg?branch=master)](https://travis-ci.org/leafOfTree/simple-mongoose-rbac)\n\n## require\n\u003e \"mongoose\": \"~3.8.8\"\n\n## install\n```bash\nnpm install simple-mongoose-rbac --save-dev\n```\n\n## Usage \u0026 Test\n```js\n'use strict';\n\nvar mongoose = require('mongoose'),\n    rbac = require('./index.js');\n\nvar UserSchema = new mongoose.Schema({ name: String });\n\n// usage of rbac: just init with config\nrbac.init({\n    grants: {\n        'user': {\n            'comment': ['add'],\n        },\n        'admin': {\n            'comment': ['delete'],\n        },\n    },\n    callback: function (user, ope, res) {\n        if (user.name === 'John' \u0026\u0026 ope === 'do') {\n            return true;\n        } else {\n            return false;\n        }\n    },\n    schema: UserSchema, \n});\n// end\n\nvar User = mongoose.model('User', UserSchema);\n\nvar John = new User({ name: 'John', roles: ['user'] }),\n    Oliver = new User({ name: 'Oliver', roles: ['admin'] }),\n    Lee = new User({ name: 'Lee', roles: ['admin', 'user'] });\n\nvar expects = [\n    John.can('add', 'comment')  === true,\n    John.can('delete', 'comment')  === false,\n    Oliver.can('add', 'comment')  === false,\n    Oliver.can('delete', 'comment')  === true,\n    Lee.can('add', 'comment')  === true,\n    Lee.can('delete', 'comment')  === true,\n    John.can('do', 'sths')  === true,\n], passed = true;\n\nexpects.forEach(function (res, i) {\n    if (!res) {\n        console.log('The ' + i + ' th test result failed.');\n        passed = false;\n    }\n});\n\nif (passed) {\n    console.log('Test passed.');\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafoftree%2Fsimple-mongoose-rbac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleafoftree%2Fsimple-mongoose-rbac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafoftree%2Fsimple-mongoose-rbac/lists"}