<commit_before>class GroupsController < ApplicationController
  before_action :set_paper_trail_whodunnit
  before_action :set_group, only: [:show, :edit, :update, :destroy, :add_user, :add_machine, :add_vpn, :add_admin, :remove_admin, :delete_user, :delete_vpn, :delete_machine]
  prepend_before_filter :setup_user if Rails.env.development?

  def index
    @groups = []
    @group_search = params[:group_search]
    if current_user.admin && @group_search.present?
        @groups = Group.where("name LIKE ?", "%#{@group_search}%" )
    elsif current_user.group_admin? && !current_user.admin
        @groups = GroupAdmin.where(user_id: current_user.id).map{ |ga| ga.group }
    end
  end

  def create
    if current_user.admin?
      @group = Group.new(group_params)
      respond_to do |format|
        if @group.save
          format.html { redirect_to group_path(@group), notice: 'Group was successfully created.' }
          format.json { render status: :created, json: "#{@group.name}host created" }
        else
          format.html { redirect_to groups_path, notice: "Can't save '#{group_params[:name]}'" }
          format.json { render status: :error, json: "#{@group.name} not created" }
        end
      end
    else
      format.html { redirect_to groups_path, notice: "Can't save '#{group_params[:name]}'" }
      format.json { render status: :error, json: "#{@group.name} not created" }
    end
  end

  def new
    @group = Group.new
  end

  def show
    #This is set in before_action filter
    #@group = Group.find(params[:id])
    @vpns = Vpn.all.select {|vpn| vpn.groups.count == 0}
    @users = User.all
    @host_machines = HostMachine.all
  end

  def delete_machine
    @machine = HostMachine.find(params[:host_machine_id])
    if current_user.admin?
      @machine.groups.delete(@group)
    end

    redirect_to group_path @group
  end

  def delete_user
    if current_user.admin? || @group.admin?(current_user)
      @user = User.find(params[:user_id])

      if @user.email.split('@').first != @group.name
        @user.groups.delete(@group)
      end

    end
    redirect_to group_path(@group, anchor: "group_members")
  end

  def add_user
    if current_user.admin? || @group.admin?(current_user)
      user = User.find(params[:user_id])<commit_msg>[ajey] display only active users in group<commit_after>class GroupsController < ApplicationController
  before_action :set_paper_trail_whodunnit
  before_action :set_group, only: [:show, :edit, :update, :destroy, :add_user, :add_machine, :add_vpn, :add_admin, :remove_admin, :delete_user, :delete_vpn, :delete_machine]
  prepend_before_filter :setup_user if Rails.env.development?

  def index
    @groups = []
    @group_search = params[:group_search]
    if current_user.admin && @group_search.present?
        @groups = Group.where("name LIKE ?", "%#{@group_search}%" )
    elsif current_user.group_admin? && !current_user.admin
        @groups = GroupAdmin.where(user_id: current_user.id).map{ |ga| ga.group }
    end
  end

  def create
    if current_user.admin?
      @group = Group.new(group_params)
      respond_to do |format|
        if @group.save
          format.html { redirect_to group_path(@group), notice: 'Group was successfully created.' }
          format.json { render status: :created, json: "#{@group.name}host created" }
        else
          format.html { redirect_to groups_path, notice: "Can't save '#{group_params[:name]}'" }
          format.json { render status: :error, json: "#{@group.name} not created" }
        end
      end
    else
      format.html { redirect_to groups_path, notice: "Can't save '#{group_params[:name]}'" }
      format.json { render status: :error, json: "#{@group.name} not created" }
    end
  end

  def new
    @group = Group.new
  end

  def show
    #This is set in before_action filter
    #@group = Group.find(params[:id])
    @vpns = Vpn.all.select {|vpn| vpn.groups.count == 0}
    @users = User.where(active: true)
    @host_machines = HostMachine.all
  end

  def delete_machine
    @machine = HostMachine.find(params[:host_machine_id])
    if current_user.admin?
      @machine.groups.delete(@group)
    end

    redirect_to group_path @group
  end

  def delete_user
    if current_user.admin? || @group.admin?(current_user)
      @user = User.find(params[:user_id])

      if @user.email.split('@').first != @group.name
        @user.groups.delete(@group)
      end

    end
    redirect_to group_path(@group, anchor: "group_members")
  end

  def add_user
    if current_user.admin? || @group.admin?(current_user)
      user = User.find(params[:user_id])
{'fraction_non_alphanumeric': 0.12727666955767564, 'fraction_numerical': 0.0004336513443191674, 'mean_word_length': 3.311214953271028, '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': '7132529', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1497, 'n_words': 346}