Skip to content

Instantly share code, notes, and snippets.

@SachaG
Created July 19, 2016 07:29
Show Gist options
  • Save SachaG/79b7b7c4ddd4a1bb0e1de711e7d2c55a to your computer and use it in GitHub Desktop.
Save SachaG/79b7b7c4ddd4a1bb0e1de711e7d2c55a to your computer and use it in GitHub Desktop.

Groups

User groups let you give your users permission to perform specific actions.

Creating A Group

Users.createGroup("mods"); // let's create a new "mods" group

Assigning Actions

Users.groups.mods.can("posts.edit.all"); // mods can edit anybody's posts
Users.groups.mods.can("posts.remove.all"); // mods can delete anybody's posts

You can also define and test for your own custom actions:

Users.groups.mods.can("invite"); // new custom action

Here's a list of all out-of-the-box permissions:

// anonymous actions
posts.view
comments.view

// default actions
posts.new
posts.edit.own
posts.remove.own
posts.upvote
posts.cancelUpvote
posts.downvote
posts.cancelDownvote
comments.new
comments.edit.own
comments.remove.own
comments.upvote
comments.cancelUpvote
comments.downvote
comments.cancelDownvote

// admin actions
posts.new.approved
posts.edit.all
posts.remove.all
comments.edit.all
comments.remove.all

Groups API

Users.addToGroup(user, group); // add a user to a group

Users.getGroups(user); // get a list of all the groups a user belongs to

Users.getActions(user); // get a list of all the actions a user can perform

Users.canDo(user, action); // check if a user can perform a specific action

Note that some groups are applied automatically without having to call addToGroup:

  • anonymous: any non-logged-in user is considered anonymous.
  • admins: any user with the isAdmin flag set to true.
  • default: default group for all existing users.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment