<commit_before>class Edits < Application  
  before :authenticate

  # Accessed by: GET /edits
  #--
  # FIXME What happens if we get here and there are no edits?
  def index
    @edits = Version.most_recent_unmoderated
    display @edits
  end

  # Accessed by: PUT /edits/1
  def update
    @edit = Version.first(params[:id])
    raise NotFound unless @edit
    # FIXME Needs to call out to Defensio
    if @edit.update_attributes(:moderated => true)
      if request.xhr?
        render :nothing => 200
      else
        redirect url(:edits)
      end
    else
      raise BadRequest
    end
  end
  
private
  def authenticate
    authenticate_or_request_with_http_basic("login") do |username, password|
      # ==============================================================================
      # = TODO: load password from an external file (set in place during deployment) =
      # ==============================================================================
      username == "merbivore" && password == "<PASSWORD>"
    end
  end
end<commit_msg>Put Defensio integration back in edits controller (as the merge of jherdman/master removed it)<commit_after>class Edits < Application  
  before :authenticate

  # Accessed by: GET /edits
  #--
  # FIXME What happens if we get here and there are no edits?
  def index
    @edits = Version.most_recent_unmoderated
    display @edits
  end

  # Accessed by: PUT /edits/1
  def update
    @edit = Version.first(params[:id])
    raise NotFound unless @edit
    if(@edit.spam)
      DEFENSIO_GATEWAY.mark_as_ham(:signatures => @edit.signature)
    else
      DEFENSIO_GATEWAY.mark_as_spam(:signatures => @edit.signature)
    end
    if @edit.update_attributes(:moderated => true)
      if request.xhr?
        render :nothing => 200
      else
        redirect url(:edits)
      end
    else
      raise BadRequest
    end
  end
  
private
  def authenticate
    authenticate_or_request_with_http_basic("login") do |username, password|
      # ==============================================================================
      # = TODO: load password from an external file (set in place during deployment) =
      # ==============================================================================
      username == "merbivore" && password == "<PASSWORD>"
    end
  end
end
{'fraction_non_alphanumeric': 0.20654044750430292, 'fraction_numerical': 0.0034423407917383822, 'mean_word_length': 3.281767955801105, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '204249', 'n_tokens_mistral': 675, 'n_tokens_neox': 634, 'n_words': 192}