<commit_before>class Admin::UsersController < Admin::ApplicationController
  before_filter :load_user, :only => [ :show, :edit, :update, :destroy ]
  load_and_authorize_resource

  respond_to :html, :js

  def show
    respond_with(@user) do |format|
      format.js { render :show }
    end
  end

  def index
    load_index
    respond_with @users
  end

  def edit
    respond_with(@user) do |format|
      format.js { render :show }
    end
  end

  def update
    # Admin updates user role
    if params[:user][:role]
      @user.update_attributes(safe_params)
      load_index
      respond_with(@users) do |format|
        format.js { render :index }
      end
    # User updates his account
    else
      if params[:user][:subscribe]
        report = Report.find(params[:user][:subscribe])
        @user.reports << report
      elsif params[:user][:unsubscribe]
        report = Report.find(params[:user][:unsubscribe])
        @user.reports.delete(report)
      else
        sign_in @user, :bypass => true if @user.update_attributes(safe_params)
      end

      respond_with(@user) do |format|
        format.js { render :show }
      end
    end
  end

  def destroy
    @user.destroy
    load_index
    respond_with(@users) do |format|
      format.js { render :index }
    end
  end

  protected
  def load_user
    @user = User.find(params[:id])
    @reports = Report.available(@user.role)
    @doc = { :title => "API", :text => IO.read(Rails.root.join("docs/API.md")) }
  end<commit_msg>ALM-645 fixed response to markdown document<commit_after>class Admin::UsersController < Admin::ApplicationController
  before_filter :load_user, :only => [ :show, :edit, :update, :destroy ]
  load_and_authorize_resource

  respond_to :html, :js

  def show
    respond_with(@user) do |format|
      format.js { render :show }
    end
  end

  def index
    load_index
    respond_with @users
  end

  def edit
    respond_with(@user) do |format|
      format.js { render :show }
    end
  end

  def update
    # Admin updates user role
    if params[:user][:role]
      @user.update_attributes(safe_params)
      load_index
      respond_with(@users) do |format|
        format.js { render :index }
      end
    # User updates his account
    else
      if params[:user][:subscribe]
        report = Report.find(params[:user][:subscribe])
        @user.reports << report
      elsif params[:user][:unsubscribe]
        report = Report.find(params[:user][:unsubscribe])
        @user.reports.delete(report)
      else
        sign_in @user, :bypass => true if @user.update_attributes(safe_params)
      end

      respond_with(@user) do |format|
        format.js { render :show }
      end
    end
  end

  def destroy
    @user.destroy
    load_index
    respond_with(@users) do |format|
      format.js { render :index }
    end
  end

  protected
  def load_user
    @user = User.find(params[:id])
    @reports = Report.available(@user.role)
    @doc = Doc.find("api")
  end
{'fraction_non_alphanumeric': 0.11133467471495641, 'fraction_numerical': 0.001006036217303823, 'mean_word_length': 2.6736453201970445, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '7474520', 'n_tokens_mistral': 950, 'n_tokens_neox': 925, 'n_words': 231}