Sha256: 54146b517a94bff4e6389947e3a356a88c37393a4faffa7c94469250887738fc

Contents?: true

Size: 1.53 KB

Versions: 12

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

module Thredded
  class MessageboardsController < Thredded::ApplicationController
    before_action :thredded_require_login!, only: %i[new create edit update]

    after_action :verify_authorized, except: %i[index]
    after_action :verify_policy_scoped, except: %i[new create edit update]

    def index
      @groups = Thredded::MessageboardGroupView.grouped(
        policy_scope(Thredded::Messageboard.all),
        user: thredded_current_user
      )
    end

    def new
      @new_messageboard = Thredded::Messageboard.new
      authorize_creating @new_messageboard
    end

    def create
      @new_messageboard = Thredded::Messageboard.new(messageboard_params)
      authorize_creating @new_messageboard
      if Thredded::CreateMessageboard.new(@new_messageboard, thredded_current_user).run
        redirect_to root_path
      else
        render :new
      end
    end

    def edit
      @messageboard = Thredded::Messageboard.friendly_find!(params[:id])
      authorize @messageboard, :update?
    end

    def update
      @messageboard = Thredded::Messageboard.friendly_find!(params[:id])
      authorize @messageboard, :update?
      if @messageboard.update(messageboard_params)
        redirect_to messageboard_topics_path(@messageboard), notice: I18n.t('thredded.messageboard.updated_notice')
      else
        render :edit
      end
    end

    private

    def messageboard_params
      params
        .require(:messageboard)
        .permit(:name, :description, :messageboard_group_id, :locked)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
thredded-0.16.12 app/controllers/thredded/messageboards_controller.rb
thredded-0.16.11 app/controllers/thredded/messageboards_controller.rb
thredded-0.16.10 app/controllers/thredded/messageboards_controller.rb
thredded-0.16.9 app/controllers/thredded/messageboards_controller.rb
thredded-0.16.8 app/controllers/thredded/messageboards_controller.rb
thredded-0.16.7 app/controllers/thredded/messageboards_controller.rb
thredded-0.16.6 app/controllers/thredded/messageboards_controller.rb
thredded-0.16.5 app/controllers/thredded/messageboards_controller.rb
thredded-0.16.4 app/controllers/thredded/messageboards_controller.rb
thredded-0.16.3 app/controllers/thredded/messageboards_controller.rb
thredded-0.16.1 app/controllers/thredded/messageboards_controller.rb
thredded-0.16.0 app/controllers/thredded/messageboards_controller.rb