<commit_before>class PointController < ApplicationController
  protect_from_forgery

  def show
    point = Point.find params[:id]
    authorize! :read, point

    dirty_key "/point/#{params[:id]}"
    render :json => []
  end


  def create
    # Validate by filtering out unwanted fields
    # todo: validate data types too
    fields = ['nutshell', 'text', 'is_pro', 'hide_name', 'proposal']
    point = params.select{|k,v| fields.include? k}

    # Set private values
    point['proposal'] = proposal = Proposal.find(key_id(point['proposal']))
    point['comment_count'] = 0
    point['long_id'] = point['proposal'].long_id
    point['published'] = false
    point['user_id'] = current_user && current_user.id || nil

    point = Point.new ActionController::Parameters.new(point).permit!

    #TODO: look into cancan to figure out how we can move this earlier in the method
    authorize! :create, point

    opinion = Opinion.where(:user_id => current_user.id,
                            :proposal => proposal).first

    if !proposal
      raise "Error! No proposal matching '#{point['proposal']}'"
    end
    if !opinion
      raise "Error! No opinion for user #{current_user.id} and proposal #{proposal.id}"
    end

    if opinion.published
      point.publish
    else
      point.save
    end

    # Include into the user's opinion
    opinion.include(point)

    original_id = key_id(params[:key])
    result = point.as_json
    result['key'] = "/point/#{point.id}?original_id=#{original_id}"
<commit_msg>Make a new opinion... for cases where session is lost. But we still need to fix session losing.<commit_after>class PointController < ApplicationController
  protect_from_forgery

  def show
    point = Point.find params[:id]
    authorize! :read, point

    dirty_key "/point/#{params[:id]}"
    render :json => []
  end


  def create
    # Validate by filtering out unwanted fields
    # todo: validate data types too
    fields = ['nutshell', 'text', 'is_pro', 'hide_name', 'proposal']
    point = params.select{|k,v| fields.include? k}

    # Set private values
    point['proposal'] = proposal = Proposal.find(key_id(point['proposal']))
    point['comment_count'] = 0
    point['long_id'] = point['proposal'].long_id
    point['published'] = false
    point['user_id'] = current_user && current_user.id || nil

    point = Point.new ActionController::Parameters.new(point).permit!

    #TODO: look into cancan to figure out how we can move this earlier in the method
    authorize! :create, point

    opinion = Opinion.get_or_make(proposal, current_user)

    if !proposal
      raise "Error! No proposal matching '#{point['proposal']}'"
    end
    if !opinion
      raise "Error! No opinion for user #{current_user.id} and proposal #{proposal.id}"
    end

    if opinion.published
      point.publish
    else
      point.save
    end

    # Include into the user's opinion
    opinion.include(point)

    original_id = key_id(params[:key])
    result = point.as_json
    result['key'] = "/point/#{point.id}?original_id=#{original_id}"

{'fraction_non_alphanumeric': 0.12173629242819843, 'fraction_numerical': 0.0006527415143603133, 'mean_word_length': 3.2747559274755926, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '511336', 'n_tokens_mistral': 949, 'n_tokens_neox': 902, 'n_words': 261}