Framework

- About
- Guides
- Community
- API
- Code
- Download

# Kanso API Documentation

Index | View on single page

## permissions

Permissions functions are used on both Fields and Types to check a given user is authorized to make a change to a document.

### matchUsername()

Field's new value should match current user's name

Returns: Function

### hasRole(role)

Checks if the user has a specific role

#### Parameters

role | String |

Returns: Function

### fieldUneditable()

The value of this field should never change after the document has been created.

Returns: Function

### usernameMatchesField(path)

User's name should match the old value of the given field. A field can be specified using a string or an array of strings (like a path).

    eg: usernameMatchesField('creator')
        usernameMatchesField(['meta','creator'])

        {
            creator: 'name',
            meta: {creator: 'name2'}
        }

#### Parameters

path | String | Array |

Returns: Function

### loggedIn()

Checks that user's context has a username

Returns: Function

### all(perms)

Runs an array of permissions functions and checks that all of them pass, returning all failures.

#### Parameters

perms | Array |

Returns: Function

### any(perms)

Tests to see if any one permission function passes, returning on the first success. If all permissions fail, then all errors are returned.

#### Parameters

perms | Array |

### inherit(type)

Treat new and old values like new documents of a given type, and attempt to authorize the value against the type's permissions. Useful when handling permissions for an embedded type.

Can be combined with permissions.any or permissions.all to extend the permissions for an embedded type field. For example, the following might allow both the owner of the parent document and the owner of the comment itself to remove it.

        comment: fields.embed({
            type: types.comment,
            permissions: {
                remove: permissions.any([
                    permissions.usernameMatchesField('creator'),
                    permissions.inherit(types.comment)
                ])
            }
        });

#### Parameters

type | Type |