Refactor topics controller. Add Common abilities. Add destroy action.
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
class TopicsController < ApplicationController
|
||||
include CommentableActions
|
||||
include FlagActions
|
||||
|
||||
before_action :load_community
|
||||
before_action :load_topic, only: [:show, :edit, :update]
|
||||
before_action :load_topic, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
has_orders %w{most_voted newest oldest}, only: :show
|
||||
|
||||
skip_authorization_check
|
||||
skip_authorization_check only: :show
|
||||
load_and_authorize_resource except: :show
|
||||
|
||||
def new
|
||||
@topic = Topic.new
|
||||
@@ -39,6 +39,11 @@ class TopicsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@topic.destroy
|
||||
redirect_to community_path(@community), notice: I18n.t('flash.actions.destroy.topic')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def topic_params
|
||||
|
||||
@@ -71,6 +71,9 @@ module Abilities
|
||||
|
||||
can :create, Annotation
|
||||
can [:update, :destroy], Annotation, user_id: user.id
|
||||
|
||||
can [:create], Topic
|
||||
can [:update, :destroy], Topic, author_id: user.id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
class Topic < ActiveRecord::Base
|
||||
include Flaggable
|
||||
|
||||
acts_as_paranoid column: :hidden_at
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<% topics.each do |topic| %>
|
||||
|
||||
<div id="<%= dom_id(topic) %>" class="panel column">
|
||||
<div class="small-10 column">
|
||||
<div class="small-8 column">
|
||||
|
||||
<h3><%= link_to topic.title, community_topic_path(@community, topic) %></h3>
|
||||
|
||||
@@ -24,9 +24,10 @@
|
||||
|
||||
</div>
|
||||
|
||||
<div class="small-2 column text-right">
|
||||
<div class="small-4 column text-right">
|
||||
<% if topic.author == current_user %>
|
||||
<%= link_to t("community.show.topic.edit_button"), edit_community_topic_path(@community.id, topic), class: 'button small hollow' %>
|
||||
<%= link_to t("community.show.topic.destroy_button"), community_topic_path(@community.id, topic), method: :delete, class: 'button hollow alert small' %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user