<commit_before>package org.innovateuk.ifs.management.admin.populator;

import org.innovateuk.ifs.category.resource.InnovationSectorResource;
import org.innovateuk.ifs.category.service.CategoryRestService;
import org.innovateuk.ifs.management.admin.form.InviteUserView;
import org.innovateuk.ifs.management.admin.viewmodel.InviteUserViewModel;
import org.innovateuk.ifs.user.resource.Authority;
import org.innovateuk.ifs.user.resource.Role;
import org.innovateuk.ifs.user.resource.UserResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;

import static java.util.stream.Collectors.toSet;

@Component
public class InviteUserModelPopulator {

    @Autowired
    private CategoryRestService categoryRestService;

    public InviteUserViewModel populate(InviteUserView type, Set<Role> roles, UserResource loggedInUser) {

        Set<Role> filteredRoles;

        if (loggedInUser.hasAuthority(Authority.SUPER_ADMIN_USER)) {
            filteredRoles = internalRolesExcludingSuperAdminRole(roles);
        } else {
            filteredRoles = internalRolesExcludingAdminAndAuditorRoles(roles);
        }

        InviteUserViewModel inviteUserViewModel =  new InviteUserViewModel(type, filteredRoles);
        inviteUserViewModel.setInnovationSectorOptions(getInnovationSectors());
        return inviteUserViewModel;
    }

    private List<InnovationSectorResource> getInnovationSectors() {
        return categoryRestService.getInnovationSectors().getSuccess();
    }

    public static Set<Role> internalRolesExcludingAdminAndAuditorRoles(Set<Role> roles) {
        return roles.stream()
                .filter(r -> !r.isSuperAdminUser())
                .filter(r -> !r.isIfsAdministrator())
                .filter(r -> !r.isAuditor())
                .collect(toSet());
    }

    public static Set<Role> internalRolesExcludingSuperAdminRole(Set<Role> roles) {
        return roles.stream()
                .filter(r -> !r.isSuperAdminUser())
                .collect(toSet());
    }
}<commit_msg>IFS-12899 - Auditor filer removed for IFS administrator.<commit_after>package org.innovateuk.ifs.management.admin.populator;

import org.innovateuk.ifs.category.resource.InnovationSectorResource;
import org.innovateuk.ifs.category.service.CategoryRestService;
import org.innovateuk.ifs.management.admin.form.InviteUserView;
import org.innovateuk.ifs.management.admin.viewmodel.InviteUserViewModel;
import org.innovateuk.ifs.user.resource.Authority;
import org.innovateuk.ifs.user.resource.Role;
import org.innovateuk.ifs.user.resource.UserResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;

import static java.util.stream.Collectors.toSet;

@Component
public class InviteUserModelPopulator {

    @Autowired
    private CategoryRestService categoryRestService;

    public InviteUserViewModel populate(InviteUserView type, Set<Role> roles, UserResource loggedInUser) {

        Set<Role> filteredRoles;

        if (loggedInUser.hasAuthority(Authority.SUPER_ADMIN_USER)) {
            filteredRoles = internalRolesExcludingSuperAdminRole(roles);
        } else {
            filteredRoles = internalRolesExcludingAdminAndAuditorRoles(roles);
        }

        InviteUserViewModel inviteUserViewModel =  new InviteUserViewModel(type, filteredRoles);
        inviteUserViewModel.setInnovationSectorOptions(getInnovationSectors());
        return inviteUserViewModel;
    }

    private List<InnovationSectorResource> getInnovationSectors() {
        return categoryRestService.getInnovationSectors().getSuccess();
    }

    public static Set<Role> internalRolesExcludingAdminAndAuditorRoles(Set<Role> roles) {
        return roles.stream()
                .filter(r -> !r.isSuperAdminUser())
                .filter(r -> !r.isIfsAdministrator())
                .collect(toSet());
    }

    public static Set<Role> internalRolesExcludingSuperAdminRole(Set<Role> roles) {
        return roles.stream()
                .filter(r -> !r.isSuperAdminUser())
                .collect(toSet());
    }
}
{'fraction_non_alphanumeric': 0.0946073793755913, 'fraction_numerical': 0.0011825922421948912, 'mean_word_length': 3.8553386911595866, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 24, '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': '5402313', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1225, 'n_words': 182}