<commit_before>---
layout: default
title:  "Roles and Abilities"
date:   2017-07-21 13:00:48 +0300
categories: [abilities, roles]
---

CASL forces you to think about what a user can actually do in the application and not who a user is in terms of roles, groups or whatever. This allows you to simply define user's abilities in JavaScript and define your own vision of how roles are translated into abilities. I will describe my vision.

In the simplest scenario, you will need to define abilities per role and share it between different users of the same role:

```js
const { AbilityBuilder } = require('casl')

const admin = AbilityBuilder.define(can => {
  can('manage', 'all')
})

const moderator = AbilityBuilder.define(can => {
  can('read', 'all')
  can('update', 'Post', { state: 'waitForModeration' })
})

const default = AbilityBuilder.define(can => {
  can('read', 'all')
})<commit_msg>docs(package): renames core package name<commit_after>---
layout: default
title:  "Roles and Abilities"
date:   2017-07-21 13:00:48 +0300
categories: [abilities, roles]
---

CASL forces you to think about what a user can actually do in the application and not who a user is in terms of roles, groups or whatever. This allows you to simply define user's abilities in JavaScript and define your own vision of how roles are translated into abilities. I will describe my vision.

In the simplest scenario, you will need to define abilities per role and share it between different users of the same role:

```js
const { AbilityBuilder } = require('@casl/ability')

const admin = AbilityBuilder.define(can => {
  can('manage', 'all')
})

const moderator = AbilityBuilder.define(can => {
  can('read', 'all')
  can('update', 'Post', { state: 'waitForModeration' })
})

const default = AbilityBuilder.define(can => {
  can('read', 'all')
})
{'fraction_non_alphanumeric': 0.10995623632385121, 'fraction_numerical': 0.019693654266958426, 'mean_word_length': 4.542424242424242, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6622501', 'n_tokens_mistral': 550, 'n_tokens_neox': 513, 'n_words': 232}