<commit_before>class NodesController < ApplicationController

  before_action :authenticate_user!
  before_action :set_node
  before_action :require_node_ownership!

  # GET /nodes/:id/edit
  def edit
    # TODO!!! Check if current_user is the owner of this node
    if current_user.nil?
      #redirect_to new_user_session_path()
    end
  end

  # GET /nodes/:id/edit/description
  def edit_description
    # TODO!!! Check if current_user is the owner of this node
    if current_user.nil?
      #redirect_to new_user_session_path()
    end
    render layout: false
  end

  # GET /nodes/:id/edit/image
  def edit_image
    # TODO!!! Check if current_user is the owner of this node
    if current_user.nil?
      #redirect_to new_user_session_path()
    end
    render layout: false
  end

  # PATCH /nodes/:id/
  def update
    @node.update_attributes( node_params )
    location = edit_visualization_path(@node.visualization)
    render json: { location: location } and return if xhr_request?
    redirect_to location
  end

  # PATCH /nodes/:id/image
  def update_image
    @node.update_attributes( node_params )
    redirect_to edit_node_path(@node)
  end

  private

  # Use callbacks to share common setup or constraints between actions.
  def set_node
    @node = Node.find(params[:id])
  end

  def require_node_ownership!
    redirect_to visualization_path(@node.visualization) unless authorized
  end

  def authorized
    (@node.visualization.author == current_user) || (@node.visualization.author == demo_user)
  end

  def node_params
    params.require(:node).permit(:name, :description, :image, :image_cache, :remote_image_url, :remove_image, custom_fields: params[:node][:custom_fields].try(:keys))
  end
end<commit_msg>Add node_type to params require in NodesController<commit_after>class NodesController < ApplicationController

  before_action :authenticate_user!
  before_action :set_node
  before_action :require_node_ownership!

  # GET /nodes/:id/edit
  def edit
    # TODO!!! Check if current_user is the owner of this node
    if current_user.nil?
      #redirect_to new_user_session_path()
    end
  end

  # GET /nodes/:id/edit/description
  def edit_description
    # TODO!!! Check if current_user is the owner of this node
    if current_user.nil?
      #redirect_to new_user_session_path()
    end
    render layout: false
  end

  # GET /nodes/:id/edit/image
  def edit_image
    # TODO!!! Check if current_user is the owner of this node
    if current_user.nil?
      #redirect_to new_user_session_path()
    end
    render layout: false
  end

  # PATCH /nodes/:id/
  def update
    @node.update_attributes( node_params )
    location = edit_visualization_path(@node.visualization)
    render json: { location: location } and return if xhr_request?
    redirect_to location
  end

  # PATCH /nodes/:id/image
  def update_image
    @node.update_attributes( node_params )
    redirect_to edit_node_path(@node)
  end

  private

  # Use callbacks to share common setup or constraints between actions.
  def set_node
    @node = Node.find(params[:id])
  end

  def require_node_ownership!
    redirect_to visualization_path(@node.visualization) unless authorized
  end

  def authorized
    (@node.visualization.author == current_user) || (@node.visualization.author == demo_user)
  end

  def node_params
    params.require(:node).permit(:name, :description, :image, :node_type, :image_cache, :remote_image_url, :remove_image, custom_fields: params[:node][:custom_fields].try(:keys))
  end
end
{'fraction_non_alphanumeric': 0.08397163120567376, 'fraction_numerical': 0.0, 'mean_word_length': 3.7777777777777777, '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': '229423', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1081, 'n_words': 296}