<commit_before>require 'net/http'
require 'uri'

class Content::CasebooksController < Content::NodeController
  before_action :set_editable, only: [:show, :index]
  before_action :require_user, only: [:clone]

  def new
    @casebook = Content::Casebook.create(public: false, collaborators: [Content::Collaborator.new(user: current_user, role: 'owner')])
    logger.debug @casebook.errors.inspect
    @content = @casebook
    redirect_to layout_casebook_path(@content)
  end

  def show
    @decorated_content = @casebook.decorate(context: {action_name: action_name, casebook: @casebook, type: 'casebooks'})
    render 'content/show'
  end

  # def edit
  #   @casebook.update_attributes public: false
  #   @content = @casebook
  #   redirect_to layout_casebook_path(@content)
  # end

  def edit
    # editing a casebook takes you to a cloned casebook and
    # the original casebook stays published
    @clone = @casebook.clone(owner: current_user, draft_mode: true)
    redirect_to layout_casebook_path(@clone)
  end

  def revise
    # revise without creating a draft
    redirect_to layout_casebook_path(@casebook)
  end

  def clone
    @clone = @casebook.clone(owner: current_user)
    redirect_to layout_casebook_path(@clone)
  end<commit_msg>Rename casebook controller methods to make more sense with the draft process.<commit_after>require 'net/http'
require 'uri'

class Content::CasebooksController < Content::NodeController
  before_action :set_editable, only: [:show, :index]
  before_action :require_user, only: [:clone]

  def new
    @casebook = Content::Casebook.create(public: false, collaborators: [Content::Collaborator.new(user: current_user, role: 'owner')])
    logger.debug @casebook.errors.inspect
    @content = @casebook
    redirect_to layout_casebook_path(@content)
  end

  def show
    @decorated_content = @casebook.decorate(context: {action_name: action_name, casebook: @casebook, type: 'casebooks'})
    render 'content/show'
  end

  def edit
    @casebook.update_attributes public: false
    @content = @casebook
    redirect_to layout_casebook_path(@content)
  end

  def create_draft
    @clone = @casebook.clone(owner: current_user, draft_mode: true)
    redirect_to layout_casebook_path(@clone)
  end

  def clone
    @clone = @casebook.clone(owner: current_user)
    redirect_to layout_casebook_path(@clone)
  end
{'fraction_non_alphanumeric': 0.09847198641765705, 'fraction_numerical': 0.0, 'mean_word_length': 4.707021791767555, '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': '926522', 'n_tokens_mistral': 750, 'n_tokens_neox': 733, 'n_words': 183}