<commit_before>class GroupsController < ApplicationController
  load_and_authorize_resource
  # GET /groups
  # GET /groups.json
  def index
    if current_user.role?(:superadmin) # TODO use a cancan ability here instead
      @groups = Group.all
    else
      @grups = current_user.groups
    end

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @groups }
    end
  end

  # GET /groups/1
  # GET /groups/1.json
  def show
    @group = Group.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @group }
    end
  end

  # GET /groups/new
  # GET /groups/new.json
  def new
    @group = Group.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @group }
    end
  end

  # GET /groups/1/edit
  def edit
    @group = Group.find(params[:id])
  end

  # POST /groups
  # POST /groups.json
  def create
    @group = Group.new(params[:group])

    respond_to do |format|
      if (emails=params[:user_emails])
        errors = @group.save_users_by_emails(emails)
      end
      @group.users << current_user if errors.empty?
      if errors.empty? and @group.save
        format.html { redirect_to @group, notice: 'Group was successfully created.' }
        format.json { render json: @group, status: :created, location: @group }
      else
        @group.errors.add(:users, errors)
        format.html { render action: "new" }
        format.json { render json: @group.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /groups/1
  # PUT /groups/1.json
  def update
    @group = Group.find(params[:id])

    respond_to do |format|
      errors = []
      if (emails=params[:user_emails])
        errors = @group.save_users_by_emails(emails)
      end

      if errors.empty? and @group.update_attributes(params[:group]) 
        format.html { redirect_to @group, notice: 'Group was successfully updated.' }
        format.json { head :no_content }
      else 
        @group.errors.add(:users, errors)
        format.html { render action: "edit" }
        format.json { render json: @group.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /groups/1
  # DELETE /groups/1.json
  def destroy
    @group = Group.find(params[:id])
    @group.destroy

    respond_to do |format|
      format.html { redirect_to groups_url }
      format.json { head :no_content }
    end
  end
end
<commit_msg>Initialize errors array to prevent errors when no users added to group AGAIN wtf<commit_after>class GroupsController < ApplicationController
  load_and_authorize_resource
  # GET /groups
  # GET /groups.json
  def index
    if current_user.role?(:superadmin) # TODO use a cancan ability here instead
      @groups = Group.all
    else
      @grups = current_user.groups
    end

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @groups }
    end
  end

  # GET /groups/1
  # GET /groups/1.json
  def show
    @group = Group.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @group }
    end
  end

  # GET /groups/new
  # GET /groups/new.json
  def new
    @group = Group.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @group }
    end
  end

  # GET /groups/1/edit
  def edit
    @group = Group.find(params[:id])
  end

  # POST /groups
  # POST /groups.json
  def create
    @group = Group.new(params[:group])

    respond_to do |format|
      errors = []
      if (emails=params[:user_emails])
        errors = @group.save_users_by_emails(emails)
      end
      @group.users << current_user if errors.empty?
      if errors.empty? and @group.save
        format.html { redirect_to @group, notice: 'Group was successfully created.' }
        format.json { render json: @group, status: :created, location: @group }
      else
        @group.errors.add(:users, errors)
        format.html { render action: "new" }
        format.json { render json: @group.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /groups/1
  # PUT /groups/1.json
  def update
    @group = Group.find(params[:id])

    respond_to do |format|
      errors = []
      if (emails=params[:user_emails])
        errors = @group.save_users_by_emails(emails)
      end

      if errors.empty? and @group.update_attributes(params[:group]) 
        format.html { redirect_to @group, notice: 'Group was successfully updated.' }
        format.json { head :no_content }
      else 
        @group.errors.add(:users, errors)
        format.html { render action: "edit" }
        format.json { render json: @group.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /groups/1
  # DELETE /groups/1.json
  def destroy
    @group = Group.find(params[:id])
    @group.destroy

    respond_to do |format|
      format.html { redirect_to groups_url }
      format.json { head :no_content }
    end
  end
end

{'fraction_non_alphanumeric': 0.10733346511168215, 'fraction_numerical': 0.0027673453251630758, 'mean_word_length': 2.4258632362897767, 'pattern_counts': {'":': 0, '<': 9, '<?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': '912718', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1609, 'n_words': 426}