<commit_before>(function () {
    "use strict";

    function UserGroupsController($scope, $timeout, $location, userService, userGroupsResource, formHelper, localizationService) {

        var vm = this;

        vm.userGroups = [];
        vm.selection = [];

        vm.createUserGroup = createUserGroup;
        vm.clickUserGroup = clickUserGroup;
        vm.clearSelection = clearSelection;
        vm.selectUserGroup = selectUserGroup;
        vm.deleteUserGroups = deleteUserGroups;

        var currentUser = null;

        function onInit() {

            vm.loading = true;

            userService.getCurrentUser().then(function(user) {
                currentUser = user;
                // Get usergroups
                userGroupsResource.getUserGroups({ onlyCurrentUserGroups: false }).then(function (userGroups) {

                    // only allow editing and selection if user is member of the group or admin
                    vm.userGroups = _.map(userGroups, function (ug) {
                        return { group: ug, hasAccess: user.userGroups.indexOf(ug.alias) !== -1 || user.userGroups.indexOf("admin") !== -1}
                    });

                    vm.loading = false;
                });
            });

        }

        function createUserGroup() {
            // clear all query params
            $location.search({});
            // go to create user group
            $location.path('users/users/group/-1').search("create", "true");;
        }

        function clickUserGroup(userGroup) {

            // only allow editing if user is member of the group or admin
            if (currentUser.userGroups.indexOf(userGroup.group.alias) === -1 && currentUser.userGroups.indexOf("admin") === -1) {
                return;
            }

            if (vm.selection.length > 0) {
                selectUserGroup(userGroup, vm.selection);
            } else {
                goToUserGroup(userGroup.group.id);
            }
        }

        function selectUserGroup(userGroup, selection, event) {

            // only allow selection if user is member of the group or admin
            if (currentUser.userGroups.indexOf(userGroup.group.alias) === -1 && currentUser.userGroups.indexOf("admin") === -1) {
                return;
            }

            if (userGroup.selected) {
                var index = selection.indexOf(userGroup.group.id);
                selection.splice(index, 1);
                userGroup.selected = false;
            } else {
                userGroup.selected = true;
                vm.selection.push(userGroup.group.id);
            }

            if(event){
                event.preventDefault();
                event.stopPropagation();
            }
        }

        function deleteUserGroups() {

            if(vm.selection.length > 0) {

                localizationService.localize("defaultdialogs_confirmdelete")<commit_msg>Disallow selection of the admin group, as it should never be allowed<commit_after>(function () {
    "use strict";

    function UserGroupsController($scope, $timeout, $location, userService, userGroupsResource, formHelper, localizationService) {

        var vm = this;

        vm.userGroups = [];
        vm.selection = [];

        vm.createUserGroup = createUserGroup;
        vm.clickUserGroup = clickUserGroup;
        vm.clearSelection = clearSelection;
        vm.selectUserGroup = selectUserGroup;
        vm.deleteUserGroups = deleteUserGroups;

        var currentUser = null;

        function onInit() {

            vm.loading = true;

            userService.getCurrentUser().then(function(user) {
                currentUser = user;
                // Get usergroups
                userGroupsResource.getUserGroups({ onlyCurrentUserGroups: false }).then(function (userGroups) {

                    // only allow editing and selection if user is member of the group or admin
                    vm.userGroups = _.map(userGroups, function (ug) {
                        return { group: ug, hasAccess: user.userGroups.indexOf(ug.alias) !== -1 || user.userGroups.indexOf("admin") !== -1}
                    });

                    vm.loading = false;
                });
            });

        }

        function createUserGroup() {
            // clear all query params
            $location.search({});
            // go to create user group
            $location.path('users/users/group/-1').search("create", "true");;
        }

        function clickUserGroup(userGroup) {

            // only allow editing if user is member of the group or admin
            if (currentUser.userGroups.indexOf(userGroup.group.alias) === -1 && currentUser.userGroups.indexOf("admin") === -1) {
                return;
            }

            if (vm.selection.length > 0) {
                selectUserGroup(userGroup, vm.selection);
            } else {
                goToUserGroup(userGroup.group.id);
            }
        }

        function selectUserGroup(userGroup, selection, event) {

            // Only allow selection if user is member of the group or admin
            if (currentUser.userGroups.indexOf(userGroup.group.alias) === -1 && currentUser.userGroups.indexOf("admin") === -1) {
                return;
            }
            // Disallow selection of the admin group, the checkbox is not visible in the UI, but clicking(and thous selecting) is still possible.
            // Currently selection can only be used for deleting, and the Controller will also disallow deleting the admin group.
            if (userGroup.group.alias === "admin")
                return;

            if (userGroup.selected) {
                var index = selection.indexOf(userGroup.group.id);
                selection.splice(index, 1);
                userGroup.selected = false;
            } else {
                userGroup.selected = true;
                vm.selection.push(userGroup.group.id);
            }

            if(event){
                event.preventDefault();
                event.stopPropagation();
            }
        }

        function deleteUserGroups() {

            if(vm.selection.length > 0) {

                localizationService.localize("defaultdialogs_confirmdelete")
{'fraction_non_alphanumeric': 0.10282776349614396, 'fraction_numerical': 0.003213367609254499, 'mean_word_length': 1.6901469317199653, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6205091', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1474, 'n_words': 363}