<commit_before>class Ldap::ServerController < ApplicationController
  include Cms::BaseFilter

  navi_view "ldap/main/navi"
  before_action :set_exclude_groups

  private
    def set_crumbs
      @crumbs << [:"ldap.server", action: :index]
    end

    def set_exclude_groups
      @exclude_groups = SS.config.ldap.exclude_groups || []
    end

    def connect
      Ldap::Connection.connect(base_dn: @cur_site.root_group.ldap_dn, username: @cur_user.ldap_dn, password: session[:password])
    end

  public
    def index
      connection = connect
      if connection.blank?
        @errors = [ t("ldap.errors.connection_setting_not_found") ]
        render status: :bad_request
        return
      end

      dn = params[:dn]
      if dn.blank?
        @parent_group = nil
        @groups = connection.groups
        @users = connection.users
      else
        @parent_group = Ldap::Group.find(connection, dn)
        @groups = @parent_group.try(:groups) || []
        @users = @parent_group.try(:users) || []
      end
    rescue Net::LDAP::Error => e
      @errors = [ e.to_s ]
      render status: :bad_request
    end

    def group
      dn = params[:dn]
      raise "404" if dn.blank?

      connection = connect
      @entity = Ldap::Group.find(connection, dn)

      raise "404" if @entity.blank?
      render file: "ldap/server/entity"<commit_msg>[modified] fix ldap server response code in case of configuration errors<commit_after>class Ldap::ServerController < ApplicationController
  include Cms::BaseFilter

  navi_view "ldap/main/navi"
  before_action :set_exclude_groups

  private
    def set_crumbs
      @crumbs << [:"ldap.server", action: :index]
    end

    def set_exclude_groups
      @exclude_groups = SS.config.ldap.exclude_groups || []
    end

    def connect
      Ldap::Connection.connect(base_dn: @cur_site.root_group.ldap_dn, username: @cur_user.ldap_dn, password: session[:password])
    end

  public
    def index
      connection = connect
      if connection.blank?
        @errors = [ t("ldap.errors.connection_setting_not_found") ]
        render
        return
      end

      dn = params[:dn]
      if dn.blank?
        @parent_group = nil
        @groups = connection.groups
        @users = connection.users
      else
        @parent_group = Ldap::Group.find(connection, dn)
        @groups = @parent_group.try(:groups) || []
        @users = @parent_group.try(:users) || []
      end
    rescue Net::LDAP::Error => e
      @errors = [ e.to_s ]
      render
    end

    def group
      dn = params[:dn]
      raise "404" if dn.blank?

      connection = connect
      @entity = Ldap::Group.find(connection, dn)

      raise "404" if @entity.blank?
      render file: "ldap/server/entity"
{'fraction_non_alphanumeric': 0.10960906101571063, 'fraction_numerical': 0.004384362440628425, 'mean_word_length': 2.5420439844760674, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '5438259', 'n_tokens_mistral': 886, 'n_tokens_neox': 860, 'n_words': 191}