<commit_before>/*************************************************
 * Copyright (c) 2015 Ansible, Inc.
 *
 * All Rights Reserved
 *************************************************/

/**
 * @ngdoc function
 * @name controllers.function:Users
 * @description This controller's the Users page
*/

const user_type_options = [
    {type: 'normal'              , label: 'Normal User'          },
    {type: 'system_auditor'      , label: 'System Auditor'       },
    {type: 'system_administrator', label: 'System Administrator' },
];

function user_type_sync($scope) {
    return (type_option) => {
        $scope.is_superuser = false;
        $scope.is_system_auditor = false;
        switch (type_option.type) {
            case 'system_administrator':
                $scope.is_superuser = true;
            break;
            case 'system_auditor':
                $scope.is_system_auditor = true;
            break;
        }
    };
}

export function UsersList($scope, $rootScope, $location, $log, $stateParams,
    Rest, Alert, UserList, GenerateList, Prompt, SearchInit, PaginateInit,
    ReturnToCaller, ClearScope, ProcessErrors, GetBasePath, SelectionInit,
    Wait, $state, Refresh, $filter) {

    ClearScope();

    var list = UserList,
        defaultUrl = GetBasePath('users'),
        generator = GenerateList,
        base = $location.path().replace(/^\//, '').split('/')[0],
        mode = (base === 'users') ? 'edit' : 'select',
        url = (base === 'organizations') ? GetBasePath('organizations') + $stateParams.organization_id + '/users/' :
            GetBasePath('teams') + $stateParams.team_id + '/users/';

    var injectForm = function() {
        generator.inject(UserList, { mode: mode, scope: $scope });
    };

    injectForm();

    $scope.$on("RefreshUsersList", function() {
        injectForm();
        Refresh({
            scope: $scope,
            set: 'users',
            iterator: 'user',
            url: GetBasePath('users') + "?order_by=username&page_size=" + $scope.user_page_size
        });
    });

    $scope.selected = [];

    if (mode === 'select') {
        SelectionInit({ scope: $scope, list: list, url: url, returnToCaller: 1 });
    }

    if ($scope.removePostRefresh) {
        $scope.removePostRefresh();
    }
    $scope.removePostRefresh = $scope.$on('PostRefresh', function () {
        // Cleanup after a delete
        Wait('stop');
        $('#prompt-modal').modal('hide');
    });

    $rootScope.flashMessage = null;
    SearchInit({
        scope: $scope,
        set: 'users',
        list: list,
        url: defaultUrl
    });
    PaginateInit({
        scope: $scope,
        list: list,
        url: defaultUrl
    });
    $scope.search(list.iterator);

    $scope.addUser = function () {
        $state.transitionTo('users.add');
    };

    $scope.editUser = function (id) {
        $state.transitionTo('users.edit', {user_id: id});
    };

    $scope.deleteUser = function (id, name) {

        var action = function () {
            //$('#prompt-modal').on('hidden.bs.modal', function () {
            //    Wait('start');
            //});
            $('#prompt-modal').modal('hide');
            Wait('start');
            var url = defaultUrl + id + '/';
            Rest.setUrl(url);
            Rest.destroy()
                .success(function () {
                    if (parseInt($state.params.user_id) === id) {
                        $state.go("^", null, {reload: true});
                    } else {
                        $scope.search(list.iterator);
                    }
                })
                .error(function (data, status) {
                    ProcessErrors($scope, data, status, null, { hdr: 'Error!',
                        msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status });
                });
        };

        Prompt({
            hdr: 'Delete',
            body: '<div class="Prompt-bodyQuery">Are you sure you want to delete the user below?</div><div class="Prompt-bodyTarget">' + $filter('sanitize')(name) + '</div>',
            action: action,
            actionText: 'DELETE'
        });
    };
}

UsersList.$inject = ['$scope', '$rootScope', '$location', '$log',
    '$stateParams', 'Rest', 'Alert', 'UserList', 'generateList', 'Prompt',
    'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope',
    'ProcessErrors', 'GetBasePath', 'SelectionInit', 'Wait', '$state',
    'Refresh', '$filter'
];





export function UsersAdd($scope, $rootScope, $compile, $location, $log,
    $stateParams, UserForm, GenerateForm, Rest, Alert, ProcessErrors,
    ReturnToCaller, ClearScope, GetBasePath, LookUpInit, OrganizationList,
    ResetForm, Wait, CreateSelect2, $state) {

    ClearScope();

    // Inject dynamic view
    var defaultUrl = GetBasePath('organizations'),
        form = UserForm,
        generator = GenerateForm;

    generator.inject(form, { mode: 'add', related: false, scope: $scope });
    ResetForm();

    $scope.ldap_user = false;
    $scope.not_ldap_user = !$scope.ldap_user;
    $scope.ldap_dn = null;
    $scope.socialAuthUser = false;

    generator.reset();

    $scope.user_type_options = user_type_options;
    $scope.user_type = user_type_options[0];
    $scope.$watch('user_type', user_type_sync($scope));

    CreateSelect2({
        element: '#user_user_type',
        multiple: false
    });
<commit_msg>Show password fields for new uers<commit_after>/*************************************************
 * Copyright (c) 2015 Ansible, Inc.
 *
 * All Rights Reserved
 *************************************************/

/**
 * @ngdoc function
 * @name controllers.function:Users
 * @description This controller's the Users page
*/

const user_type_options = [
    {type: 'normal'              , label: 'Normal User'          },
    {type: 'system_auditor'      , label: 'System Auditor'       },
    {type: 'system_administrator', label: 'System Administrator' },
];

function user_type_sync($scope) {
    return (type_option) => {
        $scope.is_superuser = false;
        $scope.is_system_auditor = false;
        switch (type_option.type) {
            case 'system_administrator':
                $scope.is_superuser = true;
            break;
            case 'system_auditor':
                $scope.is_system_auditor = true;
            break;
        }
    };
}

export function UsersList($scope, $rootScope, $location, $log, $stateParams,
    Rest, Alert, UserList, GenerateList, Prompt, SearchInit, PaginateInit,
    ReturnToCaller, ClearScope, ProcessErrors, GetBasePath, SelectionInit,
    Wait, $state, Refresh, $filter) {

    ClearScope();

    var list = UserList,
        defaultUrl = GetBasePath('users'),
        generator = GenerateList,
        base = $location.path().replace(/^\//, '').split('/')[0],
        mode = (base === 'users') ? 'edit' : 'select',
        url = (base === 'organizations') ? GetBasePath('organizations') + $stateParams.organization_id + '/users/' :
            GetBasePath('teams') + $stateParams.team_id + '/users/';

    var injectForm = function() {
        generator.inject(UserList, { mode: mode, scope: $scope });
    };

    injectForm();

    $scope.$on("RefreshUsersList", function() {
        injectForm();
        Refresh({
            scope: $scope,
            set: 'users',
            iterator: 'user',
            url: GetBasePath('users') + "?order_by=username&page_size=" + $scope.user_page_size
        });
    });

    $scope.selected = [];

    if (mode === 'select') {
        SelectionInit({ scope: $scope, list: list, url: url, returnToCaller: 1 });
    }

    if ($scope.removePostRefresh) {
        $scope.removePostRefresh();
    }
    $scope.removePostRefresh = $scope.$on('PostRefresh', function () {
        // Cleanup after a delete
        Wait('stop');
        $('#prompt-modal').modal('hide');
    });

    $rootScope.flashMessage = null;
    SearchInit({
        scope: $scope,
        set: 'users',
        list: list,
        url: defaultUrl
    });
    PaginateInit({
        scope: $scope,
        list: list,
        url: defaultUrl
    });
    $scope.search(list.iterator);

    $scope.addUser = function () {
        $state.transitionTo('users.add');
    };

    $scope.editUser = function (id) {
        $state.transitionTo('users.edit', {user_id: id});
    };

    $scope.deleteUser = function (id, name) {

        var action = function () {
            //$('#prompt-modal').on('hidden.bs.modal', function () {
            //    Wait('start');
            //});
            $('#prompt-modal').modal('hide');
            Wait('start');
            var url = defaultUrl + id + '/';
            Rest.setUrl(url);
            Rest.destroy()
                .success(function () {
                    if (parseInt($state.params.user_id) === id) {
                        $state.go("^", null, {reload: true});
                    } else {
                        $scope.search(list.iterator);
                    }
                })
                .error(function (data, status) {
                    ProcessErrors($scope, data, status, null, { hdr: 'Error!',
                        msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status });
                });
        };

        Prompt({
            hdr: 'Delete',
            body: '<div class="Prompt-bodyQuery">Are you sure you want to delete the user below?</div><div class="Prompt-bodyTarget">' + $filter('sanitize')(name) + '</div>',
            action: action,
            actionText: 'DELETE'
        });
    };
}

UsersList.$inject = ['$scope', '$rootScope', '$location', '$log',
    '$stateParams', 'Rest', 'Alert', 'UserList', 'generateList', 'Prompt',
    'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope',
    'ProcessErrors', 'GetBasePath', 'SelectionInit', 'Wait', '$state',
    'Refresh', '$filter'
];





export function UsersAdd($scope, $rootScope, $compile, $location, $log,
    $stateParams, UserForm, GenerateForm, Rest, Alert, ProcessErrors,
    ReturnToCaller, ClearScope, GetBasePath, LookUpInit, OrganizationList,
    ResetForm, Wait, CreateSelect2, $state) {

    ClearScope();

    // Inject dynamic view
    var defaultUrl = GetBasePath('organizations'),
        form = UserForm,
        generator = GenerateForm;

    generator.inject(form, { mode: 'add', related: false, scope: $scope });
    ResetForm();

    $scope.ldap_user = false;
    $scope.not_ldap_user = !$scope.ldap_user;
    $scope.ldap_dn = null;
    $scope.socialAuthUser = false;
    $scope.external_account = null;

    generator.reset();

    $scope.user_type_options = user_type_options;
    $scope.user_type = user_type_options[0];
    $scope.$watch('user_type', user_type_sync($scope));

    CreateSelect2({
        element: '#user_user_type',
        multiple: false
    });

{'fraction_non_alphanumeric': 0.1712860310421286, 'fraction_numerical': 0.0016629711751662971, 'mean_word_length': 2.3124235006119953, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '5921695', 'n_tokens_mistral': 3196, 'n_tokens_neox': 3093, 'n_words': 669}