ForgeComponents
en

Components

j-PermissionsOP

jComponent 20 · jcomponent@20 component

The component edits OpenPlatform user, role and group permissions. Bind the selected permissions to a model path and configure find and read endpoints. The model contains permission strings:

['C@admin', 'U@admin', 'R@admin', 'D@admin', 'R123456', 'R#employees']
  • first letter means allowed type, defined in types
  • @admin means a role admin
  • #employees means a group employees
  • 123456 means a specific userid

Configuration:

  • placeholder {String} a placeholder for j-Directory component (default: Search)
  • types {String} types of permission (array delimited by char, default: CRUD)
  • disabled {Boolean} optional, disables this component
  • default {String} default value of type (default: R)
  • dirkey {String} optional, a key for text in j-Directory (default: name)
  • labelrole {String} optional a label for roles (default: Role)
  • labelgroup {String} optional a label for groups (default: Group)
  • limit {Number} a count of allowed permissions (default: 0 = unlimited)
  • pk {String} a primary key which value will be binded into the model (default: id)
  • IMPORTANT find {String} URL address for finding roles, groups and users, the component sends url?q=SEARCH_QUERY (it sends empty value)
  • IMPORTANT read {String} URL address for reading roles, groups and users, the component sends url?id=@role,#group,userid,...
// The component expects data:
['C@admin', 'U@admin', 'R@admin', 'D@admin', 'R123456', 'R#employees'];

// The component tries to find data:
// The component tries to read data and it pairs them with the model automatically:
[{ id: '123456', name: 'Peter Širka' }, { id: '@admin', name: 'Administrators' }, { id: '#employees', name: 'Employees' }];

Usage

<ui-component name="directory"></ui-component>
<ui-component name="permissionsop" path="form.permissions"
  config="find:/api/permissions/search/;read:/api/permissions/read/;types:CRUD"></ui-component>
<script>
  ON('request', function(request) {
    if (request.method === 'GET' && request.data &&
        request.url.indexOf('/api/permissions/') === 0) {
      request.url = QUERIFY(request.url, request.data);
      request.data = null;
    }
  });
  SET('form.permissions', ['R@admin', 'U#employees']);
</script>

Declare j-Directory for the selection menu. Both endpoints return an array of objects with id and name strings. The find endpoint receives the search text in q. The read endpoint receives comma-separated identifiers in id and resolves the permissions already in the model. Use pk to choose the identifier field; its default is id. Prefix role identifiers with @ and group identifiers with #.

Source: Total.js components. Copyright Peter Širka and contributors. MIT license.