<commit_before>define(function(require) {
  'use strict';

  var modules = require('modules');
  var states = require('states');
  var _ = require('lodash');

  modules.get('a4c-auth', ['ngResource']).factory('authService', ['$resource', '$location', '$state', '$http',
    function($resource, $location, $state, $http) {
      var userStatusResource = $resource('rest/latest/auth/status', {}, {
        'query': {
          method: 'GET',
          isArray: false
        }
      });
      // get default 'all-users' group
      var defaultAllUsersGroup = $resource('rest/latest/auth/groups/allusers', {}, {
        'query': {
          method: 'GET',
          isArray: false
        }
      }).query();

      /* Permissions */
      var allAccessAdminRole = 'ADMIN';

      return {
        currentStatus: null,
        menu: states.rootMenu(),

        onCurrentStatus: function() {
          var self = this;
          _.each(this.menu, function(menuItem) {
            menuItem.hasRole = self.hasOneRoleIn(menuItem.roles);
          });
        },

        getStatus: function() {
          var self = this;
          if (this.currentStatus === null) {
            this.currentStatus = userStatusResource.query();
            this.currentStatus.$promise.then(function() {
              self.onCurrentStatus();
            });
          }
          return this.currentStatus;
        },

        authorizationCheck: function(checkCallback) {
          var self = this;
          if (typeof this.currentStatus.data !== 'undefined') {
            return checkCallback(this.currentStatus.data);
          } else {
            return this.getStatus().$promise.then(
              function() {
                return checkCallback(self.currentStatus.data);
              }
            );
          }
        },

        /** Checks if the user has one of the role requested. */
        hasOneRoleIn: function(roles) {
          if (!_.isEmpty(roles)) {
            return this.authorizationCheck(
              function(userData) {
                if (!userData.isLogged) {
                  return false;
                }
                if (userData.roles.indexOf(allAccessAdminRole) > -1) {
                  return true;
                }
                for (var i = 0; i < roles.length; i++) {
                  var hasRole = userData.roles.indexOf(roles[i]) > -1;
                  if (hasRole) {
                    return true;
                  }
                }
                return false;
              }
            );
          } else {
            // empty roles array => full access for authenticated user at least
            return true;
          }
        },

        getRolesForResource: function(resource, userStatus) {
          var allRoles;
          var userRoles = resource.userRoles[userStatus.username];
          if (!_.isEmpty(userRoles)) {
            allRoles = userRoles;
          }
          var groups = userStatus.groups;
          if (_.undefined(groups)) {
            groups = [];
          }
          if (_.defined(defaultAllUsersGroup.data)) {
            groups.push(defaultAllUsersGroup.data.id);
          }
          var groupRolesMap = resource.groupRoles;
          if (_.defined(groups) && !_.isEmpty(groups) && _.defined(groupRolesMap) && !_.isEmpty(groupRolesMap)) {
            for (var i = 0; i < groups.length; i++) {
              var group = groups[i];
              if (groupRolesMap.hasOwnProperty(group)) {<commit_msg>ALIEN-2467: Application cannot be clicked in Application list page (depending on user rights)<commit_after>define(function(require) {
  'use strict';

  var modules = require('modules');
  var states = require('states');
  var _ = require('lodash');

  modules.get('a4c-auth', ['ngResource']).factory('authService', ['$resource', '$location', '$state', '$http',
    function($resource, $location, $state, $http) {
      var userStatusResource = $resource('rest/latest/auth/status', {}, {
        'query': {
          method: 'GET',
          isArray: false
        }
      });
      // get default 'all-users' group
      var defaultAllUsersGroup = $resource('rest/latest/auth/groups/allusers', {}, {
        'query': {
          method: 'GET',
          isArray: false
        }
      }).query();

      /* Permissions */
      var allAccessAdminRole = 'ADMIN';

      return {
        currentStatus: null,
        menu: states.rootMenu(),

        onCurrentStatus: function() {
          var self = this;
          _.each(this.menu, function(menuItem) {
            menuItem.hasRole = self.hasOneRoleIn(menuItem.roles);
          });
        },

        getStatus: function() {
          var self = this;
          if (this.currentStatus === null) {
            this.currentStatus = userStatusResource.query();
            this.currentStatus.$promise.then(function() {
              self.onCurrentStatus();
            });
          }
          return this.currentStatus;
        },

        authorizationCheck: function(checkCallback) {
          var self = this;
          if (typeof this.currentStatus.data !== 'undefined') {
            return checkCallback(this.currentStatus.data);
          } else {
            return this.getStatus().$promise.then(
              function() {
                return checkCallback(self.currentStatus.data);
              }
            );
          }
        },

        /** Checks if the user has one of the role requested. */
        hasOneRoleIn: function(roles) {
          if (!_.isEmpty(roles)) {
            return this.authorizationCheck(
              function(userData) {
                if (!userData.isLogged) {
                  return false;
                }
                if (userData.roles.indexOf(allAccessAdminRole) > -1) {
                  return true;
                }
                for (var i = 0; i < roles.length; i++) {
                  var hasRole = userData.roles.indexOf(roles[i]) > -1;
                  if (hasRole) {
                    return true;
                  }
                }
                return false;
              }
            );
          } else {
            // empty roles array => full access for authenticated user at least
            return true;
          }
        },

        getRolesForResource: function(resource, userStatus) {
          var allRoles;
          var userRoles = _.get(resource, 'userRoles[' + userStatus.username + ']', []);
          if (!_.isEmpty(userRoles)) {
            allRoles = userRoles;
          }
          var groups = userStatus.groups;
          if (_.undefined(groups)) {
            groups = [];
          }
          if (_.defined(defaultAllUsersGroup.data)) {
            groups.push(defaultAllUsersGroup.data.id);
          }
          var groupRolesMap = resource.groupRoles;
          if (_.defined(groups) && !_.isEmpty(groups) && _.defined(groupRolesMap) && !_.isEmpty(groupRolesMap)) {
            for (var i = 0; i < groups.length; i++) {
              var group = groups[i];
              if (groupRolesMap.hasOwnProperty(group)) {
{'fraction_non_alphanumeric': 0.12446958981612447, 'fraction_numerical': 0.0019801980198019802, 'mean_word_length': 1.5825420014609204, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '2895768', 'n_tokens_mistral': 1904, 'n_tokens_neox': 1848, 'n_words': 391}