<commit_before>class ResourceContextsController < ApplicationController

  before_action :require_login
  before_action :check_customization_editor
  before_action :check_editor_for_this_customization, only: [:edit, :update]


  def index
    resource_customizations
  end


  # GET /resource_templates/new
  def new
    
    redirect_to :back and return if params[:requirements_template_id].blank?
    #institution_id, requirements_template_id, resource_id is NULL
    if user_role_in?(:dmp_admin) && params[:institution_id].blank?
      redirect_to({:action => :choose_institution, :requirements_template_id => params[:requirements_template_id]}) and return
    end
    @req_temp = RequirementsTemplate.find(params[:requirements_template_id])
    redirect_to :back and return if @req_temp.nil?
    @resource_context = ResourceContext.new
    @resource_context.requirements_template_id = @req_temp.id
    @resource_context.review_type = @req_temp.review_type

    #if it is for the template or for a a different institution
    if user_role_in?(:dmp_admin)
      if params[:institution_id] == "none"
        @resource_context.name = "#{@req_temp.name}"
      else
        that_inst = Institution.find(params[:institution_id])
        @resource_context.name = "#{@req_temp.name} for #{that_inst.name}"
      end
    else
      @resource_context.name = "#{@req_temp.name} for #{current_user.institution.name}"
    end

    #the institution_id should be nil if it's none, otherwise set it
    if user_role_in?(:dmp_admin)
      @resource_context.institution_id = ( params[:institution_id] == "none" ? nil : params[:institution_id])
    else
      @resource_context.institution_id = current_user.institution_id
    end
    @resource_context.contact_email = @req_temp.institution.contact_email
    @resource_context.contact_info = @req_temp.institution.contact_info

    existing = ResourceContext.where(institution_id:        @resource_context.institution_id).
                        where(requirements_template_id:     @resource_context.requirements_template_id).
                        where('requirement_id IS NULL').
                        where('resource_id IS NULL')
    if existing.length > 0
      redirect_to(edit_resource_context_path(existing.first.id) ) and return
    end

    make_institution_dropdown_list
  end

<commit_msg>Customizations default to institution customizing for user/email.<commit_after>class ResourceContextsController < ApplicationController

  before_action :require_login
  before_action :check_customization_editor
  before_action :check_editor_for_this_customization, only: [:edit, :update]


  def index
    resource_customizations
  end


  # GET /resource_templates/new
  def new
    
    redirect_to :back and return if params[:requirements_template_id].blank?
    #institution_id, requirements_template_id, resource_id is NULL
    if user_role_in?(:dmp_admin) && params[:institution_id].blank?
      redirect_to({:action => :choose_institution, :requirements_template_id => params[:requirements_template_id]}) and return
    end
    @req_temp = RequirementsTemplate.find(params[:requirements_template_id])
    redirect_to :back and return if @req_temp.nil?
    @resource_context = ResourceContext.new
    @resource_context.requirements_template_id = @req_temp.id
    @resource_context.review_type = @req_temp.review_type

    #if it is for the template or for a a different institution
    if user_role_in?(:dmp_admin)
      if params[:institution_id] == "none"
        @resource_context.name = "#{@req_temp.name}"
      else
        that_inst = Institution.find(params[:institution_id])
        @resource_context.name = "#{@req_temp.name} for #{that_inst.name}"
      end
    else
      @resource_context.name = "#{@req_temp.name} for #{current_user.institution.name}"
    end

    #the institution_id should be nil if it's none, otherwise set it
    if user_role_in?(:dmp_admin)
      @resource_context.institution_id = ( params[:institution_id] == "none" ? nil : params[:institution_id])
    else
      @resource_context.institution_id = current_user.institution_id
    end
    if @resource_context.institution_id
      inst = Institution.find(@resource_context.institution_id)
      @resource_context.contact_email = inst.contact_email
      @resource_context.contact_info = inst.contact_info
    end

    existing = ResourceContext.where(institution_id:        @resource_context.institution_id).
                        where(requirements_template_id:     @resource_context.requirements_template_id).
                        where('requirement_id IS NULL').
                        where('resource_id IS NULL')
    if existing.length > 0
      redirect_to(edit_resource_context_path(existing.first.id) ) and return
    end

    make_institution_dropdown_list
  end


{'fraction_non_alphanumeric': 0.08683007893643539, 'fraction_numerical': 0.0004154549231408392, 'mean_word_length': 3.8440643863179074, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6952406', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1401, 'n_words': 279}