<commit_before><commit_msg>Renamed the file and added validation to behavior params before calling authorize()<commit_after>(function () {
  'use strict';

  var directives = {
    only: 'rpOnly',
    except: 'rpExcept'
  };

  var elementBehaviors = {
    'hide': function(element) {
      element.addClass('ng-hide');
    },
    'disable': function(element) {
      element.attr('disabled', 'disabled');
    }
  }

  var EXCEPTIONS = {
      UNDEFINED_RP_BEHAVIOR: 'rp-behavior is undefined. Check your spelling, it can be either hide or disable!'
  }

  angular.module('permission')
    .directive(directives.only, only)

  angular.module('permission')
    .directive(directives.except, except)

  only.$inject = ['$q', 'Permission'];
  except.$inject = ['$q', 'Permission'];

  function only($q, Permission) {
    var directive = {
      restrict: 'A',
      link: link
    }
    return directive;

    function link(scope, element, attrs) {
      checkPermissions(directives.only, element, attrs, Permission);
    }
  }

  function except($q, Permission) {
    var directive = {
      restrict: 'A',
      link: link
    }
    return directive;

    function link(scope, element, attrs) {
      checkPermissions(directives.except, element, attrs, Permission);
    }
  }

  function validateBehaviorParams(behavior) {
    if(!elementBehaviors[behavior]) {
      throw new Error(EXCEPTIONS.UNDEFINED_RP_BEHAVIOR);
    }
  }

  function checkPermissions(directiveName, element, attrs, Permission) {
    var roleMap = {};
    var roles = attrs[directiveName].replace(/\[|]|'/gi, '').split(',');
    roleMap[(directiveName === directives.only ? 'only' : 'except')] = roles;

    var behavior = (attrs.rpBehavior ? attrs.rpBehavior : 'hide');
    validateBehaviorParams(behavior);

    var authorizing = Permission.authorize(roleMap, null);
    authorizing.then(null, function() {
      //authorize rejected -> apply behavior to element
      elementBehaviors[behavior](element);
    });
  }


}());
{'fraction_non_alphanumeric': 0.13913913913913914, 'fraction_numerical': 0.0, 'mean_word_length': 3.3934065934065933, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '4515298', 'n_tokens_mistral': 627, 'n_tokens_neox': 593, 'n_words': 136}