{"id":18084772,"url":"https://github.com/coderofsalvation/dpd-acl-roles-permissions","last_synced_at":"2025-04-12T20:09:07.298Z","repository":{"id":46252755,"uuid":"73685850","full_name":"coderofsalvation/dpd-acl-roles-permissions","owner":"coderofsalvation","description":"Easily configure roles/permissions and limitations for methods and (nested) keyvalue-pairs for deployd","archived":false,"fork":false,"pushed_at":"2020-07-13T00:12:11.000Z","size":464,"stargazers_count":3,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-12T20:08:46.441Z","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/coderofsalvation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":"https://gumroad.com/l/hGYGh"}},"created_at":"2016-11-14T08:58:41.000Z","updated_at":"2021-01-07T23:47:02.000Z","dependencies_parsed_at":"2022-09-07T17:24:22.774Z","dependency_job_id":null,"html_url":"https://github.com/coderofsalvation/dpd-acl-roles-permissions","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/coderofsalvation%2Fdpd-acl-roles-permissions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderofsalvation%2Fdpd-acl-roles-permissions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderofsalvation%2Fdpd-acl-roles-permissions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderofsalvation%2Fdpd-acl-roles-permissions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coderofsalvation","download_url":"https://codeload.github.com/coderofsalvation/dpd-acl-roles-permissions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248625493,"owners_count":21135513,"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-31T15:08:08.360Z","updated_at":"2025-04-12T20:09:07.237Z","avatar_url":"https://github.com/coderofsalvation.png","language":"JavaScript","funding_links":["https://gumroad.com/l/hGYGh"],"categories":[],"sub_categories":[],"readme":"Easily configure roles/permissions regarding methods and (nested) keyvalue-pairs for deployd\n\n![Build Status](https://travis-ci.org/coderofsalvation/dpd-acl-roles-permissions.svg?branch=master)\n\n\u003cimg src=\"http://i.giphy.com/81xwEHX23zhvy.gif\" width=\"150\" style=\"width:150px\"/\u003e\n\n## Usage \n\n    $ npm install dpd-acl-roles-permissions dpd-event --save\n\n## Centralized configuration\n\n* Run deployd and go to your dashboard \n* Make sure you have a users-collection resource \n* Add a `roles`-property in there (array value: `[\"admin\",\"staff\",\"premium\"]`) and set username to '`admin`'\n\n\u003ccenter\u003e\u003cimg src=\"https://raw.githubusercontent.com/coderofsalvation/dpd-acl-roles-permissions/dev/doc/dpd-1.png\"/\u003e\u003c/center\u003e\n\n* Hit the green button, and add an '`event`'-resource (name: `/roles`)\n\n\u003ccenter\u003e\u003cimg src=\"https://raw.githubusercontent.com/coderofsalvation/dpd-acl-roles-permissions/dev/doc/dpd-2.png?23\"/\u003e\u003c/center\u003e\n\n* In the `CONFIG.JSON`-screen paste the json below\n\n    {\n      \"my-endpoint\": {\n        \"GET\":    \"*\",\n        \"POST\":   \"admin,staff,premium\",\n        \"PUT\":    \"admin,staff,premium\",\n        \"DELETE\": \"admin,staff,premium\",\n        \"properties\": {\n          \"email\": {\n            \"GET\":  \"admin,staff,premium\",\n            \"POST\": \"admin,staff,premium\",\n            \"PUT\":  \"admin,staff,premium\"\n          }\n        } \n      }\n    }\n\nDone!\n\n* `curl -X GET http://localhost/my-endpoint` will now work (but hides 'email'-field for users without 'admin' or 'staff' or 'premium'-role )\n* `curl -X POST http://localhost/my-endpoint` will now only work for user with admin- or staff- or premium-roles\n\n\u003e NOTE: feel free to play around with the config\n\n## Automatically filter results by owner \n\n`dpd-acl-roles-permissions` has an integration for [dpd-collection-systemfields](https://npmjs.org/package/dpd-collection-systemfields).\nIt allows you to easily setup endpoints which return owned-only results:\n\n* run `npm install dpd-collection-systemfields --save`\n* add at least the 'createdBy'-fields to all your collection-endpoints (see [docs](https://npmjs.org/package/dpd-collection-systemfields) )\n\n    {\n      \"my-endpoint\": {\n        \"GET\":    \"*\",\n        \"POST\":   \"admin,staff,premium\",\n        \"PUT\":    \"admin,staff,premium\",\n        \"DELETE\": \"admin,staff,premium\",\n        \"properties\": {\n          \"createdBy\": {\n            \"restrict\": true,               \u003c--- add this to filter *any* mongodb query on current user \n            \"GET\":  \"admin,staff,premium\",\n            \"POST\": \"admin,staff,premium\",\n            \"PUT\":  \"admin,staff,premium\"\n          }\n        } \n      }\n    }\n\n## Automatically filter results by group\n\nWe can 'abuse' roles to act as organisations- or groups too.\n\n\u003e NOTE: this feature requires the *dpd-collection-systemfields* module mentioned above \n\nHere's how to easily filter results based on roles (lets say 'staff'):\n\n* add a `roles`-array property in a collection-resource with value: `[\"staff\"]`\n* add a `public`-boolean property in there too \n\nNow for non logged-in users:\n\n* `curl -X GET http://localhost/my-endpoint` returns zero-role and public records \n\nNow for logged-in users:\n\n* `curl -X GET http://localhost/my-endpoint` returns zero-role, public, owned and records with matching roles\n* `curl -X GET http://localhost/my-endpoint?account=1` returns only owned records and/or records with matching roles\n\n## Writing tests \n\nTesting endpoints can be done using [dpd-test](https://npmjs.org/package/dpd-test):\n\n    var dpdTest = require('dpd-test')\n    var request = require('superagent')\n    var port = 3030\n\n    dpdTest.run({\n      port: port, \n      user: {username:\"foo\", \"password\":\"bar\", roles:[\"user\"]},    // specify user/role\n      ready: function(dpd, done, sessionid ){\n\n        request                                                    // do request as user foo\n          .get('http://localhost:'+port+'/scraper')\n          .set('Cookie', 'sid='+sessionid)\n          .set('Content-Type',  'application/json')\n          .set('Accept',  'application/json')\n          .end(function(err,  res){\n            console.dir(res.body)\n            done()\n          })\n\n      }, \n      done: function(err, database){\n        console.log(\"done\") \n        process.exit( err ? 1 : 0 )\n      } \n    })\n\n## Features \n\n* restrict methods (POST/GET/PUT/DELETE method)\n* restrict (nested) key-permissions in incoming payloads (or outgoing results)\n* no need to use hide() and protect() all over the place \n* TODO: more tests\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderofsalvation%2Fdpd-acl-roles-permissions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderofsalvation%2Fdpd-acl-roles-permissions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderofsalvation%2Fdpd-acl-roles-permissions/lists"}