<commit_before>module Web; end
require "web/helpers"

class Web::AdminController < Sinatra::Base
  helpers Web::Helpers
  set :views, File.join(settings.root, '../views')

  get("/admin") do
    protected!
    erb :admin, layout: :layout
  end

  post("/admin/api_users/:id") do
    protected!
    user = ApiUser.find(params[:id])

    if params.has_key?("destroy")
      user.destroy
    elsif params.has_key?("save")
      update_user(user, params["api_user"])
      user.save
    end

    Appsignal.set_gauge("user_count", ApiUser.count)

    redirect back
  end

  get("/admin/sign_out") do
    protected!
    session.destroy

    redirect "/"
  end

  private

  def update_user user, params
    if params["active"].present?
      user.activate!

      documentation_url = url("/documentation")
      Mailer.send_new_activation_notification(user, documentation_url)
    else
      user.deactivate!
    end

    params["permissions"].each do |(api_object, attrs)|
      user.permissions[api_object] = attrs.keys
    end
  end
end
<commit_msg>don't send activation email if user is already active<commit_after>module Web; end
require "web/helpers"

class Web::AdminController < Sinatra::Base
  helpers Web::Helpers
  set :views, File.join(settings.root, '../views')

  get("/admin") do
    protected!
    erb :admin, layout: :layout
  end

  post("/admin/api_users/:id") do
    protected!
    user = ApiUser.find(params[:id])

    if params.has_key?("destroy")
      user.destroy
    elsif params.has_key?("save")
      update_user(user, params["api_user"])
      user.save
    end

    Appsignal.set_gauge("user_count", ApiUser.count)

    redirect back
  end

  get("/admin/sign_out") do
    protected!
    session.destroy

    redirect "/"
  end

  private

  def update_user user, params
    if params["active"].present?
      unless user.active
        user.activate!

        documentation_url = url("/documentation")
        Mailer.send_new_activation_notification(user, documentation_url)
      end
    else
      user.deactivate!
    end

    params["permissions"].each do |(api_object, attrs)|
      user.permissions[api_object] = attrs.keys
    end
  end
end

{'fraction_non_alphanumeric': 0.11780947998159227, 'fraction_numerical': 0.0, 'mean_word_length': 3.018484288354898, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4087885', 'n_tokens_mistral': 698, 'n_tokens_neox': 682, 'n_words': 153}