{"id":17159136,"url":"https://github.com/scull7/empower-role","last_synced_at":"2025-03-24T14:45:18.075Z","repository":{"id":57224926,"uuid":"45421706","full_name":"scull7/empower-role","owner":"scull7","description":"Given a role map, a set of roles and a permission can the user access?","archived":false,"fork":false,"pushed_at":"2015-11-18T22:43:44.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-11T08:40:45.610Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scull7.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-02T20:59:45.000Z","updated_at":"2015-11-03T00:23:03.000Z","dependencies_parsed_at":"2022-08-24T11:01:05.143Z","dependency_job_id":null,"html_url":"https://github.com/scull7/empower-role","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/scull7%2Fempower-role","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scull7%2Fempower-role/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scull7%2Fempower-role/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scull7%2Fempower-role/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scull7","download_url":"https://codeload.github.com/scull7/empower-role/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245294711,"owners_count":20591898,"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-14T22:13:25.869Z","updated_at":"2025-03-24T14:45:18.052Z","avatar_url":"https://github.com/scull7.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/scull7/empower-role.svg?branch=master)](https://travis-ci.org/scull7/empower-role)\n[![Coverage Status](https://coveralls.io/repos/scull7/empower-role/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/scull7/empower-role?branch=master)\n\n# empower-role\nGiven a role map, a set of roles and a permission can the user access?\n\n## Role Map\nMaps a set of roles to a set of permission strings and CRUD actions against\nthat set _(expressed as HTTP/1.1 methods)_.\n\n```json\n{\n  \"role-name\": {\n    \"permission-name\": [ \"get\" ],\n    \"other-permission\": [ \"post\" ],\n    \"one-more-permission\": [ \"get\", \"put\", \"post\", \"delete\" ]\n  },\n  \"other-role\": {\n    \"permission-name\": [ \"get\", \"post\"],\n    \"other-permission\": [ \"delete\" ],\n    \"permission:action\": [ \"get\" ]\n  }\n}\n```\n\n## Set of user roles\nSimply an array of roles to check against.\n\n## Permission\nA string that represents a system action or request.\n\n## Usage\n\n```javascript\nvar RoleMap = require('empower-role').Map;\nvar Role    = require('empower-role').Role;\n\n// Alternatively you can supply JSON via the RoleMap.fromJson function.\nvar map     = RoleMap()\n  .addRole( Role('role-name')\n    .addPermission('permission-name'), [ 'get' ])\n    .addPermission('other-permission'), [ 'get', 'post' ])\n    .addPermission('permission:action', [ 'get', 'put', 'post', 'delete' ])\n  )\n  .addRole( Role('other-role')\n    .addPermission('permission-name'), [ 'get', 'post' ])\n    .addPermission('other-permission'), [ 'delete' ])\n    .addPermission('permission:action', [ 'get' ])\n  )\n;\n\nvar userRoles = [ 'role-name', 'other-role' ];\n\nvar isAllowed1 = map.check(userRoles, 'permission-name', 'get');\nvar isAllowed2 = map.check(userRoles, 'other-permission', [ 'delete' ]);\nvar isAllowed3 = map.check(userRoles, 'permission:action!', [ 'put' ]);\n\n// will print \"true, true, true\"\n// the most permissive result is always returned.\nconsole.log(isAllowed1, isAllowed2, isAllowed3);\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscull7%2Fempower-role","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscull7%2Fempower-role","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscull7%2Fempower-role/lists"}