Sha256: 4efd7973319800d8163875e1d7152ae128d35c493591026fba1465e3db049dbc

Contents?: true

Size: 1.72 KB

Versions: 24

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true

class Admin::NotesController < Admin::BaseController
  layout "administration"

  before_action :load_existing_notes, only: [:index, :edit]
  before_action :find_note, only: [:edit, :update, :show, :destroy]

  def index
    @note = new_note
  end

  def show
    unless @note.access_by?(current_user)
      flash[:error] = I18n.t("admin.base.not_allowed")
      redirect_to admin_notes_url
    end
  end

  def edit; end

  def create
    note = new_note

    note.state = "published"
    note.attributes = params[:note].permit!
    note.text_filter ||= default_text_filter
    note.published_at ||= Time.zone.now
    if note.save
      if params[:push_to_twitter] && note.twitter_id.blank?
        unless note.send_to_twitter
          flash[:error] = I18n.t("errors.problem_sending_to_twitter")
          flash[:error] += " : #{note.errors.full_messages.join(" ")}"
        end
      end
      flash[:notice] = I18n.t("notice.note_successfully_created")
    else
      flash[:error] = note.errors.full_messages
    end
    redirect_to admin_notes_url
  end

  def update
    @note.attributes = params[:note].permit!
    @note.save
    redirect_to admin_notes_url
  end

  def destroy
    @note.destroy
    flash[:notice] = I18n.t("admin.base.successfully_deleted", name: "note")
    redirect_to admin_notes_url
  end

  private

  def load_existing_notes
    @notes = Note.page(params[:page]).per(this_blog.limit_article_display)
  end

  def find_note
    @note = Note.find(params[:id])
  end

  def new_note
    this_blog.notes.build(author: current_user,
                          text_filter_name: default_text_filter)
  end

  def default_text_filter
    current_user.text_filter_name || this_blog.text_filter
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
publify_core-10.0.2 app/controllers/admin/notes_controller.rb
HornsAndHooves-publify_core-10.5.0 app/controllers/admin/notes_controller.rb
HornsAndHooves-publify_core-10.4.0 app/controllers/admin/notes_controller.rb
HornsAndHooves-publify_core-10.3.0 app/controllers/admin/notes_controller.rb
HornsAndHooves-publify_core-10.2.0 app/controllers/admin/notes_controller.rb
publify_core-10.0.1 app/controllers/admin/notes_controller.rb
publify_core-10.0.0 app/controllers/admin/notes_controller.rb
publify_core-9.2.10 app/controllers/admin/notes_controller.rb
HornsAndHooves-publify_core-10.1.1 app/controllers/admin/notes_controller.rb
HornsAndHooves-publify_core-10.1.0 app/controllers/admin/notes_controller.rb
HornsAndHooves-publify_core-10.0.3 app/controllers/admin/notes_controller.rb
HornsAndHooves-publify_core-10.0.2 app/controllers/admin/notes_controller.rb
HornsAndHooves-publify_core-10.0.1 app/controllers/admin/notes_controller.rb
HornsAndHooves-publify_core-10.0.0 app/controllers/admin/notes_controller.rb
publify_core-9.2.9 app/controllers/admin/notes_controller.rb
publify_core-9.2.8 app/controllers/admin/notes_controller.rb
publify_core-9.2.7 app/controllers/admin/notes_controller.rb
publify_core-9.2.6 app/controllers/admin/notes_controller.rb
publify_core-9.2.5 app/controllers/admin/notes_controller.rb
publify_core-9.2.4 app/controllers/admin/notes_controller.rb