class FilterModule:

    def users_having_access(self, users, host):
        def user_has_access(user):
            # indiviual assignment in hosts definition
            if 'ssh_allow_user_access' in host:
                if user[0] in host['ssh_allow_user_access']:
                    return True

            # new parameter for hosts: individual_service_accounts: true
            if 'individual_service_accounts' in host and host['individual_service_accounts']:
                # do not add user by department if host has seperate user
                # accounts instaed of all users loggin in as perfact
                return False

            # filter users by department
            if 'departments' in host and 'departments' in user[1]:
                for department in host['departments']:
                    if department in user[1]['departments']:
                        return True

            return False


        return dict(filter(user_has_access, users.items()))


    def filters(self):
        return {
            'users_having_access': self.users_having_access,
        }
