<commit_before>class UsersController < ApplicationController
  before_action :signed_in_user,  only: [:index, :edit, :update, :show, :destroy]
  before_action :correct_user,    only: [:edit, :update, :show]
  before_action :admin_user,      only: [:create_admin, :destroy, :index]
  before_action :limit_user,      only: [:new_noteuser, :new_notetaker, :create]

  def index
    @users = User.all
  end

  def show
		@user = User.find(params[:id])	
    @notes = @user.notes.paginate(page: params[:page])
	end

  def new_noteuser
    @user = User.new
  end

  def new_notetaker
    @user = User.new(note_taker: true)
  end

  def create
		@user = User.new(create_params)
    accomodation = Accomodation.find_by(student_id: @user.student_id)
    if not @user.note_taker and ( accomodation.nil? or not accomodation.note_taking)
      flash.now[:error] = "You are not registered with the OSD to recieve note taking, hence you cannot register for this service."
      render 'new_noteuser'
    else
  		if @user.save
        @user.send_new_registration_message
        sign_in @user
        flash[:success] = "Welcome to EZ Notes!"
  			redirect_to root_path
  		else
        if @user.note_taker
          render 'new_notetaker'
        else
          render 'new_noteuser'
  		  end
      end
    end
  end

  def create_admin
    @user = User.new(admin_params)
    @user.admin = true
    if @user.save
      flash[:success] = "New Admin user [ #{@user.student_id} #{@user.name} #{@user.email} created"
      redirect_to :back
    else
      full_msg = " "
      @user.errors.full_messages.each do |msg|
        full_msg = full_msg + msg + ". "
      end
      flash[:error] = "Could not create admin user. #{full_msg}"
      redirect_to :back
    end
  end

  def edit
  end

  def update
    if @user.update_attributes(update_params)
      # Handle a successful update
      flash[:success] = "Profile updated"
      if current_user.admin? and not current_user?(@user)<commit_msg>Remove stopping users from registereing if they are not part of accomodations<commit_after>class UsersController < ApplicationController
  before_action :signed_in_user,  only: [:index, :edit, :update, :show, :destroy]
  before_action :correct_user,    only: [:edit, :update, :show]
  before_action :admin_user,      only: [:create_admin, :destroy, :index]
  before_action :limit_user,      only: [:new_noteuser, :new_notetaker, :create]

  def index
    @users = User.all
  end

  def show
		@user = User.find(params[:id])	
    @notes = @user.notes.paginate(page: params[:page])
	end

  def new_noteuser
    @user = User.new
  end

  def new_notetaker
    @user = User.new(note_taker: true)
  end

  def create
		@user = User.new(create_params)
    #accomodation = Accomodation.find_by(student_id: @user.student_id)
    #if not @user.note_taker and ( accomodation.nil? or not accomodation.note_taking)
      #flash.now[:error] = "You are not registered with the OSD to recieve note taking, hence you cannot register for this service."
      #render 'new_noteuser'
    #else
  		if @user.save
        @user.send_new_registration_message
        sign_in @user
        flash[:success] = "Welcome to EZ Notes!"
  			redirect_to root_path
  		else
        if @user.note_taker
          render 'new_notetaker'
        else
          render 'new_noteuser'
  		  end
      end
    #end
  end

  def create_admin
    @user = User.new(admin_params)
    @user.admin = true
    if @user.save
      flash[:success] = "New Admin user [ #{@user.student_id} #{@user.name} #{@user.email} created"
      redirect_to :back
    else
      full_msg = " "
      @user.errors.full_messages.each do |msg|
        full_msg = full_msg + msg + ". "
      end
      flash[:error] = "Could not create admin user. #{full_msg}"
      redirect_to :back
    end
  end

  def edit
  end

  def update
    if @user.update_attributes(update_params)
      # Handle a successful update
      flash[:success] = "Profile updated"
      if current_user.admin? and not current_user?(@user)
{'fraction_non_alphanumeric': 0.10233482364629906, 'fraction_numerical': 0.0, 'mean_word_length': 2.8945841392649903, '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': '4494073', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1328, 'n_words': 354}