<commit_before>class UserAPI < Grape::API
  format :json
  
  class User < Grape::Entity
    expose :common_name, :documentation => { :type => String, :desc => "Full name" }
    expose :given_name, :documentation => { :type => String, :desc => "Firstname" }
    expose :surname, :documentation => { :type => String, :desc => "Lastname" }
    expose :uid, :documentation => { :type => String, :desc => "Login name" }
    expose :home_directory, :documentation => { :type => String, :desc => "Path to the user home" }
    expose :gid_number, :documentation => { :type => Integer, :desc => "ID of the group" }
    expose :uid_number, :documentation => { :type => Integer, :desc => "ID of the user" }
    expose :mail, :documentation => { :type => String, :desc => "E-Mail address" }
    expose :login_shell, :documentation => { :type => String, :desc => "The shell used for ssh login" }
  end
  
  resource :users do
    desc "Returns the list of users in the ldap", {
      :object_fields => UserAPI::User.documentation
    }
    get '/' do
      present LdapUser.all, with: UserAPI::User
    end
    
    desc "Returns a template for new users", {
      :object_fields => UserAPI::User.documentation<commit_msg>Rescue error when user not found in api and return http 404<commit_after>class UserAPI < Grape::API
  format :json
  
  class User < Grape::Entity
    expose :common_name, :documentation => { :type => String, :desc => "Full name" }
    expose :given_name, :documentation => { :type => String, :desc => "Firstname" }
    expose :surname, :documentation => { :type => String, :desc => "Lastname" }
    expose :uid, :documentation => { :type => String, :desc => "Login name" }
    expose :home_directory, :documentation => { :type => String, :desc => "Path to the user home" }
    expose :gid_number, :documentation => { :type => Integer, :desc => "ID of the group" }
    expose :uid_number, :documentation => { :type => Integer, :desc => "ID of the user" }
    expose :mail, :documentation => { :type => String, :desc => "E-Mail address" }
    expose :login_shell, :documentation => { :type => String, :desc => "The shell used for ssh login" }
  end

  rescue_from ActiveLdap::EntryNotFound do |error|
    Rack::Response.new({
      'status'  => 404,
      'message' => error.message
    }.to_json, 404)
  end

  resource :users do
    desc "Returns the list of users in the ldap", {
      :object_fields => UserAPI::User.documentation
    }
    get '/' do
      present LdapUser.all, with: UserAPI::User
    end
    
    desc "Returns a template for new users", {
      :object_fields => UserAPI::User.documentation
{'fraction_non_alphanumeric': 0.14977134146341464, 'fraction_numerical': 0.003429878048780488, 'mean_word_length': 3.426644182124789, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 63, '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': '2985389', 'n_tokens_mistral': 828, 'n_tokens_neox': 803, 'n_words': 262}