How to use the mson/lib/access.fieldsCanAccess function in mson

To help you get started, we’ve selected a few mson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github redgeoff / mson-react / src / fields / collection-field.js View on Github external
sortOptions() {
    const { component } = this.props;
    if (component && component.get('form')) {
      const form = component.get('form');
      const fieldsCanAccess = access.fieldsCanAccess('read', form);
      const fields = [];
      form.eachField(field => {
        const name = field.get('name');

        // Do we have access to the field? Allowed to sort? Not hidden? Not a button?
        if (
          fieldsCanAccess[name] !== undefined &&
          !field.get('forbidSort') &&
          !field.get('hidden') &&
          !(field instanceof ButtonField)
        ) {
          fields.push({
            value: (form.isDefaultField(name) ? '' : 'fieldValues.') + name,
            label: field.get('label')
          });
        }
github redgeoff / mson-react / src / form.js View on Github external
calcFieldsCanAccess() {
    const { component, mode } = this.props;
    const canDowngrade = true;
    const fieldsCanAccess = access.fieldsCanAccess(
      // Default to update so that access control has a sensible default
      mode ? mode : 'update',
      component,
      null,
      canDowngrade
    );

    // We need to set the ignoreErrs state as there may be a field that is not accessible that is
    // generating an error.
    for (const field of component.getFields()) {
      const ignoreErrs = fieldsCanAccess[field.get('name')] === undefined;
      field.set({ ignoreErrs });
    }

    return fieldsCanAccess;
  }