<commit_before>angular.module('openspecimen')
  .factory('AuthorizationService', function($rootScope, $http, User, ApiUtil, ApiUrls) {
    var userRights = [];

    function isAllowed(allowedOps, requestedOps) {
      var allowed = false;
      for (var i = 0; i < requestedOps.length; ++i) {
        if (allowedOps.indexOf(requestedOps[i]) != -1) {
          allowed = true;
          break;
        }
      }
      return allowed;
    }

    return {
      initializeUserRights: function() {
        return User.getCurrentUserRoles().then(
          function(userRoles) {
            userRights = [];
            angular.forEach(userRoles, function(userRole) {
              var site = userRole.site ? userRole.site.name : null;
              var cp = userRole.collectionProtocol ? userRole.collectionProtocol.shortTitle : null;
              angular.forEach(userRole.role.acl, function(ac) {
                userRights.push({
                  site: site,
                  cp: cp,
                  resource: ac.resourceName,
                  operations: ac.operations.map(function(op) { return op.operationName; } )
                });
              });
            });
            return userRights;
          }
        );
      },

      isAllowed: function(opts) {
        if ($rootScope.currentUser.admin) {
          return true;
        }

        var allowed = false;
        for (var i = 0; i < userRights.length; i++) {
          if (!opts.sites && !opts.cp && userRights[i].resource == opts.resource) {
            //
            // For resources whose rights are independent of CP and/or Site
            //
            allowed = isAllowed(userRights[i].operations, opts.operations);

          } else if ((!opts.sites || !userRights[i].site ||
                      (opts.sites && opts.sites.indexOf(userRights[i].site) != -1)) &&
                    (!opts.cp || !userRights[i].cp || userRights[i].cp == opts.cp) &&
                    (userRights[i].resource == opts.resource)) {
            //
            // For resources whose rights are specified based on CP and/or Site
            //
            allowed = isAllowed(userRights[i].operations, opts.operations);
          }

          if (allowed) {
            break;
          }
        }
<commit_msg>Minor change in authorization<commit_after>angular.module('openspecimen')
  .factory('AuthorizationService', function($rootScope, $http, User, ApiUtil, ApiUrls) {
    var userRights = [];

    function isAllowed(allowedOps, requestedOps) {
      var allowed = false;
      for (var i = 0; i < requestedOps.length; ++i) {
        if (allowedOps.indexOf(requestedOps[i]) != -1) {
          allowed = true;
          break;
        }
      }
      return allowed;
    }

    return {
      initializeUserRights: function() {
        return User.getCurrentUserRoles().then(
          function(userRoles) {
            userRights = [];
            angular.forEach(userRoles, function(userRole) {
              var site = userRole.site ? userRole.site.name : null;
              var cp = userRole.collectionProtocol ? userRole.collectionProtocol.shortTitle : null;
              angular.forEach(userRole.role.acl, function(ac) {
                userRights.push({
                  site: site,
                  cp: cp,
                  resource: ac.resourceName,
                  operations: ac.operations.map(function(op) { return op.operationName; } )
                });
              });
            });
            return userRights;
          }
        );
      },

      isAllowed: function(opts) {
        if ($rootScope.currentUser.admin) {
          return true;
        }

        var allowed = false;
        for (var i = 0; i < userRights.length; i++) {
          if (!opts.sites && !opts.cp && userRights[i].resource == opts.resource) {
            //
            // For resources whose rights are independent of CP and Site
            //
            allowed = isAllowed(userRights[i].operations, opts.operations);

          } else if ((!opts.sites || !userRights[i].site || opts.sites.indexOf(userRights[i].site) != -1) &&
                    (!opts.cp || !userRights[i].cp || userRights[i].cp == opts.cp) &&
                    (userRights[i].resource == opts.resource)) {
            //
            // For resources whose rights are specified based on CP and/or Site
            //
            allowed = isAllowed(userRights[i].operations, opts.operations);
          }

          if (allowed) {
            break;
          }
        }

{'fraction_non_alphanumeric': 0.12320600574078162, 'fraction_numerical': 0.0017663943475380878, 'mean_word_length': 1.6215277777777777, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '234349', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1221, 'n_words': 258}