<commit_before>class PoliciesController < OrganizationAwareController
  #before_filter :authorize_admin
  before_filter :check_for_cancel, :only => [:create, :update]
  before_filter :get_policy, :except => [:index, :create, :new]
  
  SESSION_VIEW_TYPE_VAR = 'policies_subnav_view_type'
    
  def index

    @page_title = 'Policies'
   
    # get the policies for this agency 
    @policies = []
    @organization.policies.each do |p|
      @policies << p
    end   
    
    # remember the view type
    @view_type = get_view_type(SESSION_VIEW_TYPE_VAR)

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

  def show

    @page_title = @policy.name

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

  
  def new
    #right now, no blank policies can be created - just copying existing policies
  end

  def edit
    
    @page_title = "Update #{@policy.name}"
    
  end

  # Copy a policy to a new policy. This could be copying from a parent agency to a member agency or
  # vis versa
  def copy
    
    old_policy_name = @policy.name
    new_policy = @policy.dup
    new_policy.organization = current_user.organization
    new_policy.name = "Copy of " + @policy.name
    new_policy.description = "Copy of " + @policy.description
    
    new_policy.policy_items.clear
    @policy.policy_items.each do |pi|
      new_pi = pi.dup
      new_policy.policy_items << new_pi
    end

    new_policy.save

    # now attempt to load the newly created record
    @policy = Policy.find(new_policy.id)
    respond_to do |format|
      if @policy
        notify_user(:notice, "Policy #{old_policy_name} was successfully copied.")
        format.html { redirect_to edit_policy_url(@policy) }
        format.json { render :json => @policy, :status => :created, :location => @policy }<commit_msg>Make sure that the copied policy is not marked as current [fixes #68740280]<commit_after>class PoliciesController < OrganizationAwareController
  #before_filter :authorize_admin
  before_filter :check_for_cancel, :only => [:create, :update]
  before_filter :get_policy, :except => [:index, :create, :new]
  
  SESSION_VIEW_TYPE_VAR = 'policies_subnav_view_type'
    
  def index

    @page_title = 'Policies'
   
    # get the policies for this agency 
    @policies = []
    @organization.policies.each do |p|
      @policies << p
    end   
    
    # remember the view type
    @view_type = get_view_type(SESSION_VIEW_TYPE_VAR)

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

  def show

    @page_title = @policy.name

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

  
  def new
    #right now, no blank policies can be created - just copying existing policies
  end

  def edit
    
    @page_title = "Update #{@policy.name}"
    
  end

  # Copy a policy to a new policy. This could be copying from a parent agency to a member agency or
  # vis versa
  def copy
    
    old_policy_name = @policy.name
    new_policy = @policy.dup
    new_policy.organization = current_user.organization
    new_policy.name = "Copy of " + @policy.name
    new_policy.description = "Copy of " + @policy.description
    new_policy.current = false
    
    new_policy.policy_items.clear
    @policy.policy_items.each do |pi|
      new_pi = pi.dup
      new_policy.policy_items << new_pi
    end

    new_policy.save

    # now attempt to load the newly created record
    @policy = Policy.find(new_policy.id)
    respond_to do |format|
      if @policy
        notify_user(:notice, "Policy #{old_policy_name} was successfully copied.")
        format.html { redirect_to edit_policy_url(@policy) }
        format.json { render :json => @policy, :status => :created, :location => @policy }
{'fraction_non_alphanumeric': 0.09067946451124022, 'fraction_numerical': 0.002020712301086133, 'mean_word_length': 2.8409311348205626, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '6944833', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1238, 'n_words': 350}