<commit_before>'use strict';

(function() {
  angular.module('ncsaas')
    .controller('PlansListController',
      ['baseControllerListClass', 'plansService', 'customersService', 'usersService', 'customerPermissionsService',
       'agreementsService', '$stateParams', '$state', '$window', '$q', PlansListController]);

  function PlansListController(
      baseControllerListClass, plansService, customersService, usersService, customerPermissionsService,
      agreementsService, $stateParams, $state, $window, $q) {
    var controllerScope = this;
    var Controller = baseControllerListClass.extend({
      init:function() {
        this.service = plansService;
        this.controllerScope = controllerScope;
        this.checkPermissions();
        this.selectedPlan = null;
      },

      checkPermissions: function() {
        // check is current user - customer owner and load page if he is
        var vm = this;
        usersService.getCurrentUser().then(function(user) {
          /*jshint camelcase: false */
          customerPermissionsService.userHasCustomerRole(user.username, 'owner', $stateParams.uuid).then(
            function(hasRole) {
              vm.canSeePlans = hasRole;

              if (vm.canSeePlans || user.is_staff) {
                vm.getLimitsAndUsages();
                vm.getList();
              } else {
                $state.go('errorPage.notFound');
              }
            });
        });
      },

      getLimitsAndUsages: function() {
        var vm = this;
        return customersService.$get($stateParams.uuid).then(function(customer) {
          vm.customer = customer;
          vm.currentPlan = customer.plan;
          vm.usage = {};
          for (var i = 0; i < customer.quotas.length; i++) {
            var item = customer.quotas[i];
            vm.usage[item.name] = item.usage;
          }
        });
      },

      // XXX: This is quick fix, we need to get display names from backend, but currently quotas on backend do not
      // have display names
      getPrettyQuotaName: function(name) {
        var prettyNames = {
          'nc_user_count': 'users',
          'nc_resource_count': 'resources',
          'nc_project_count': 'projects'
        };
        return prettyNames[name];
      },

      cancel: function() {
        $state.go('organizations.details', {uuid:$stateParams.uuid});
      },

      selectPlan: function(plan) {
        if (!this.currentPlan || plan.url !== this.currentPlan) {
          this.selectedPlan = plan;
        } else {
          this.selectedPlan = null;<commit_msg>User shouldn’t be able to pay for current plan (SAAS-863)<commit_after>'use strict';

(function() {
  angular.module('ncsaas')
    .controller('PlansListController',
      ['baseControllerListClass', 'plansService', 'customersService', 'usersService', 'customerPermissionsService',
       'agreementsService', '$stateParams', '$state', '$window', '$q', PlansListController]);

  function PlansListController(
      baseControllerListClass, plansService, customersService, usersService, customerPermissionsService,
      agreementsService, $stateParams, $state, $window, $q) {
    var controllerScope = this;
    var Controller = baseControllerListClass.extend({
      init:function() {
        this.service = plansService;
        this.controllerScope = controllerScope;
        this.checkPermissions();
        this.selectedPlan = null;
      },

      checkPermissions: function() {
        // check is current user - customer owner and load page if he is
        var vm = this;
        usersService.getCurrentUser().then(function(user) {
          /*jshint camelcase: false */
          customerPermissionsService.userHasCustomerRole(user.username, 'owner', $stateParams.uuid).then(
            function(hasRole) {
              vm.canSeePlans = hasRole;

              if (vm.canSeePlans || user.is_staff) {
                vm.getLimitsAndUsages();
                vm.getList();
              } else {
                $state.go('errorPage.notFound');
              }
            });
        });
      },

      getLimitsAndUsages: function() {
        var vm = this;
        return customersService.$get($stateParams.uuid).then(function(customer) {
          vm.customer = customer;
          vm.currentPlan = customer.plan;
          vm.usage = {};
          for (var i = 0; i < customer.quotas.length; i++) {
            var item = customer.quotas[i];
            vm.usage[item.name] = item.usage;
          }
        });
      },

      // XXX: This is quick fix, we need to get display names from backend, but currently quotas on backend do not
      // have display names
      getPrettyQuotaName: function(name) {
        var prettyNames = {
          'nc_user_count': 'users',
          'nc_resource_count': 'resources',
          'nc_project_count': 'projects'
        };
        return prettyNames[name];
      },

      cancel: function() {
        $state.go('organizations.details', {uuid:$stateParams.uuid});
      },

      selectPlan: function(plan) {
        if (!this.currentPlan || plan.url !== this.currentPlan.url) {
          this.selectedPlan = plan;
        } else {
          this.selectedPlan = null;
{'fraction_non_alphanumeric': 0.12077572964669739, 'fraction_numerical': 0.0009600614439324117, 'mean_word_length': 2.2678795483061482, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5001898', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1382, 'n_words': 308}