You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: studies_controller.rb
    path of file: ./repos/sequencescape/app/controllers
    
    the code of the file until where you have to start completion: # frozen_string_literal: true
require 'rexml/document'

# rubocop:todo Metrics/ClassLength
class StudiesController < ApplicationController
  # WARNING! This filter bypasses security mechanisms in rails 4 and mimics rails 2 behviour.
  # It should be removed wherever possible and the correct Strong  Parameter options applied in its place.
  before_action :evil_parameter_hack!
    
  def index
    # Please do not user current_user outside this block, you kill the API calls
    setup_studies_from_scope(@exclude_nested_resource)
    respond_to do |format|
      format.html
      format.xml { render(action: (@exclude_nested_resource ? 'index' : 'index_deprecated_xml')) }
      format.json { render json: Study.all.to_json }
    end
  end

  def study_list
    return redirect_to(studies_path) unless request.xhr?

    setup_studies_from_scope
    render partial: 'study_list', locals: { studies: @studies.with_related_owners_included }
  end

  def show
    @study = Study.find(params[:id])
    flash.keep
    respond_to do |format|
      format.html { redirect_to study_information_path(@study) }
      format.xml { render layout: false }
      format.json { render json: @study.to_json }
    end
  end
  def new
    @study = Study.new
    respond_to { |format| format.html }
  end

  def edit
    @study = Study.find(params[:id])
    flash.now[:warning] = @study.warnings if @study.warnings.present?
    @users = User.all
  end

  ## Create the Study from new with the details from its form.
  ## Redirect to the index page with a notice.
  def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
    ActiveRecord::Base.transaction do
      @study = Study.new(params['study'].merge(user: current_user))
      @study.save!
      current_user.grant_manager(@study)
      User.find(params[:study_owner_id]).grant_owner(@study) if params[:study_owner_id].present?
    end

    flash[:notice] = 'Your study has been created'
    respond_to do |format|
      format.html { redirect_to study_path(@study) }
      format.xml { render xml: @study, status: :created, location: @study }
      format.json { render json: @study, status: :created, location: @study }
    end
  rescue ActiveRecord::RecordInvalid => e
    flash.now[:error] = 'Problems creating your new study'
    respond_to do |format|
      format.html { render action: 'new' }
      format.xml { render xml: @study.errors, status: :unprocessable_entity }
      format.json { render json: @study.errors, status: :unprocessable_entity }
    end
  end

  # rubocop:todo Metrics/MethodLength
  def update # rubocop:todo Metrics/AbcSize
    @study = Study.find(params[:id])

    ActiveRecord::Base.transaction do
      @study.update!(params[:study])
      if params[:study_owner_id].present?
        owner = User.find(params[:study_owner_id])
        unless owner.owner_of?(@study)
          @study.owners.first.remove_role('owner', @study) if @study.owners.size == 1
          owner.grant_owner(@study)
        end
      end

      flash[:notice] = 'Your study has been updated'

      redirect_to study_path(@study)
    end