From 09d0026b1bf45256cfcbd39eca5d5b5d106dbb14 Mon Sep 17 00:00:00 2001 From: Pete Corey Date: Thu, 9 Jul 2015 10:29:05 -0700 Subject: [PATCH 01/14] Added adminRole property and functionality --- README.md | 13 +++++++++++++ lib/both/AdminDashboard.coffee | 2 +- lib/both/router.coffee | 2 +- lib/client/html/admin_layouts.html | 2 +- lib/client/html/admin_templates.html | 2 +- lib/client/js/helpers.coffee | 3 +++ lib/server/methods.coffee | 26 +++++++++++++------------- lib/server/publish.coffee | 4 ++-- 8 files changed, 35 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 66262d0..69be518 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,19 @@ AdminConfig = { } }; ``` + +By default, the `"admin"` role will be used to identify administrators. To identify administrators by another role, you can use the `adminRole` property: + +```javascript +AdminConfig = { + name: 'My App', + adminRole: 'Owner', + collections: { + Posts: {} + } +}; +``` + #### 3. Define your data models #### If you are unfamiliar with [autoform](https://github.com/aldeed/meteor-autoform) or [collection2](https://github.com/aldeed/meteor-collection2) or [collection-helpers](https://github.com/dburles/meteor-collection-helpers) you should check them out now. diff --git a/lib/both/AdminDashboard.coffee b/lib/both/AdminDashboard.coffee index 0673fc5..68b3185 100644 --- a/lib/both/AdminDashboard.coffee +++ b/lib/both/AdminDashboard.coffee @@ -8,7 +8,7 @@ AdminDashboard = Session.set 'adminError', message checkAdmin: -> - if not Roles.userIsInRole Meteor.userId(), ['admin'] + if not Roles.userIsInRole Meteor.userId(), [AdminConfig?.adminRole or 'admin'] Meteor.call 'adminCheckAdmin' if (typeof AdminConfig?.nonAdminRedirectRoute == "string") Router.go AdminConfig.nonAdminRedirectRoute diff --git a/lib/both/router.coffee b/lib/both/router.coffee index cff5784..38fd135 100644 --- a/lib/both/router.coffee +++ b/lib/both/router.coffee @@ -17,7 +17,7 @@ Session.set 'admin_id', null Session.set 'admin_doc', null - if not Roles.userIsInRole Meteor.userId(), ['admin'] + if not Roles.userIsInRole Meteor.userId(), [AdminConfig?.adminRole or 'admin'] Meteor.call 'adminCheckAdmin' if typeof AdminConfig?.nonAdminRedirectRoute == 'string' Router.go AdminConfig.nonAdminRedirectRoute diff --git a/lib/client/html/admin_layouts.html b/lib/client/html/admin_layouts.html index b417c7c..dcccdf7 100644 --- a/lib/client/html/admin_layouts.html +++ b/lib/client/html/admin_layouts.html @@ -1,6 +1,6 @@