Refactor topics controller. Add Common abilities. Add destroy action.
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
class TopicsController < ApplicationController
|
class TopicsController < ApplicationController
|
||||||
include CommentableActions
|
include CommentableActions
|
||||||
include FlagActions
|
|
||||||
|
|
||||||
before_action :load_community
|
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
|
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
|
def new
|
||||||
@topic = Topic.new
|
@topic = Topic.new
|
||||||
@@ -39,6 +39,11 @@ class TopicsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@topic.destroy
|
||||||
|
redirect_to community_path(@community), notice: I18n.t('flash.actions.destroy.topic')
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def topic_params
|
def topic_params
|
||||||
|
|||||||
@@ -71,6 +71,9 @@ module Abilities
|
|||||||
|
|
||||||
can :create, Annotation
|
can :create, Annotation
|
||||||
can [:update, :destroy], Annotation, user_id: user.id
|
can [:update, :destroy], Annotation, user_id: user.id
|
||||||
|
|
||||||
|
can [:create], Topic
|
||||||
|
can [:update, :destroy], Topic, author_id: user.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
class Topic < ActiveRecord::Base
|
class Topic < ActiveRecord::Base
|
||||||
include Flaggable
|
|
||||||
|
|
||||||
acts_as_paranoid column: :hidden_at
|
acts_as_paranoid column: :hidden_at
|
||||||
include ActsAsParanoidAliases
|
include ActsAsParanoidAliases
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<% topics.each do |topic| %>
|
<% topics.each do |topic| %>
|
||||||
|
|
||||||
<div id="<%= dom_id(topic) %>" class="panel column">
|
<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>
|
<h3><%= link_to topic.title, community_topic_path(@community, topic) %></h3>
|
||||||
|
|
||||||
@@ -24,9 +24,10 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-2 column text-right">
|
<div class="small-4 column text-right">
|
||||||
<% if topic.author == current_user %>
|
<% 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.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 %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ en:
|
|||||||
disabled_info_title: You need to be logged to create a new topic
|
disabled_info_title: You need to be logged to create a new topic
|
||||||
topic:
|
topic:
|
||||||
edit_button: Edit
|
edit_button: Edit
|
||||||
|
destroy_button: Destroy
|
||||||
comments:
|
comments:
|
||||||
one: 1 comment
|
one: 1 comment
|
||||||
other: "%{count} comments"
|
other: "%{count} comments"
|
||||||
|
|||||||
@@ -29,3 +29,4 @@ en:
|
|||||||
spending_proposal: "Spending proposal deleted succesfully."
|
spending_proposal: "Spending proposal deleted succesfully."
|
||||||
budget_investment: "Investment project deleted succesfully."
|
budget_investment: "Investment project deleted succesfully."
|
||||||
error: "Could not delete"
|
error: "Could not delete"
|
||||||
|
topic: "Topic deleted successfully."
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ es:
|
|||||||
disabled_info_title: Necesitas estar logueado para crear un nuevo tema
|
disabled_info_title: Necesitas estar logueado para crear un nuevo tema
|
||||||
topic:
|
topic:
|
||||||
edit_button: Editar
|
edit_button: Editar
|
||||||
|
destroy_button: Eliminar
|
||||||
comments:
|
comments:
|
||||||
one: 1 Comentario
|
one: 1 Comentario
|
||||||
other: "%{count} Comentarios"
|
other: "%{count} Comentarios"
|
||||||
|
|||||||
@@ -29,3 +29,4 @@ es:
|
|||||||
spending_proposal: "Propuesta de inversión eliminada."
|
spending_proposal: "Propuesta de inversión eliminada."
|
||||||
budget_investment: "Propuesta de inversión eliminada."
|
budget_investment: "Propuesta de inversión eliminada."
|
||||||
error: "No se pudo borrar"
|
error: "No se pudo borrar"
|
||||||
|
topic: "Tema eliminado."
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ Setting['feature.public_stats'] = true
|
|||||||
Setting['feature.budgets'] = true
|
Setting['feature.budgets'] = true
|
||||||
Setting['feature.signature_sheets'] = true
|
Setting['feature.signature_sheets'] = true
|
||||||
Setting['feature.legislation'] = true
|
Setting['feature.legislation'] = true
|
||||||
Setting['feature.community'] = nil
|
Setting['feature.community'] = true
|
||||||
|
|
||||||
# Spending proposals feature flags
|
# Spending proposals feature flags
|
||||||
Setting['feature.spending_proposal_features.voting_allowed'] = nil
|
Setting['feature.spending_proposal_features.voting_allowed'] = nil
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ feature 'Topics' do
|
|||||||
expect(page).to have_selector(".button.expanded.disabled")
|
expect(page).to have_selector(".button.expanded.disabled")
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Should can access to new topic page with user logged', :js do
|
scenario 'Can access to new topic page with user logged', :js do
|
||||||
proposal = create(:proposal)
|
proposal = create(:proposal)
|
||||||
community = proposal.community
|
community = proposal.community
|
||||||
user = create(:user)
|
user = create(:user)
|
||||||
@@ -47,7 +47,7 @@ feature 'Topics' do
|
|||||||
|
|
||||||
context 'Create' do
|
context 'Create' do
|
||||||
|
|
||||||
scenario 'Should can create a new topic', :js do
|
scenario 'Can create a new topic', :js do
|
||||||
proposal = create(:proposal)
|
proposal = create(:proposal)
|
||||||
community = proposal.community
|
community = proposal.community
|
||||||
user = create(:user)
|
user = create(:user)
|
||||||
@@ -62,11 +62,20 @@ feature 'Topics' do
|
|||||||
expect(current_path).to eq(community_path(community))
|
expect(current_path).to eq(community_path(community))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario 'Can not create a new topic when user not logged', :js do
|
||||||
|
proposal = create(:proposal)
|
||||||
|
community = proposal.community
|
||||||
|
|
||||||
|
visit new_community_topic_path(community)
|
||||||
|
|
||||||
|
expect(page).to have_content "You do not have permission to carry out the action 'new' on topic."
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Edit' do
|
context 'Edit' do
|
||||||
|
|
||||||
scenario 'Should can edit a topic' do
|
scenario 'Can edit a topic' do
|
||||||
proposal = create(:proposal)
|
proposal = create(:proposal)
|
||||||
community = proposal.community
|
community = proposal.community
|
||||||
user = create(:user)
|
user = create(:user)
|
||||||
@@ -82,11 +91,23 @@ feature 'Topics' do
|
|||||||
expect(current_path).to eq(community_path(community))
|
expect(current_path).to eq(community_path(community))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario 'Can not edit a topic when user logged is not an author' do
|
||||||
|
proposal = create(:proposal)
|
||||||
|
community = proposal.community
|
||||||
|
topic = create(:topic, community: community)
|
||||||
|
user = create(:user)
|
||||||
|
login_as(user)
|
||||||
|
|
||||||
|
visit edit_community_topic_path(community, topic)
|
||||||
|
|
||||||
|
expect(page).to have_content "You do not have permission to carry out the action 'edit' on topic."
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Show' do
|
context 'Show' do
|
||||||
|
|
||||||
scenario 'Should can show topic' do
|
scenario 'Can show topic' do
|
||||||
proposal = create(:proposal)
|
proposal = create(:proposal)
|
||||||
community = proposal.community
|
community = proposal.community
|
||||||
topic = create(:topic, community: community)
|
topic = create(:topic, community: community)
|
||||||
@@ -99,4 +120,35 @@ feature 'Topics' do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'Destroy' do
|
||||||
|
|
||||||
|
scenario 'Can destroy a topic' do
|
||||||
|
proposal = create(:proposal)
|
||||||
|
community = proposal.community
|
||||||
|
user = create(:user)
|
||||||
|
topic = create(:topic, community: community, author: user)
|
||||||
|
login_as(user)
|
||||||
|
visit community_path(community)
|
||||||
|
|
||||||
|
click_link "Destroy"
|
||||||
|
|
||||||
|
expect(page).to have_content "Topic deleted successfully."
|
||||||
|
expect(page).not_to have_content topic.title
|
||||||
|
expect(current_path).to eq(community_path(community))
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Can not destroy a topic when user logged is not an author' do
|
||||||
|
proposal = create(:proposal)
|
||||||
|
community = proposal.community
|
||||||
|
topic = create(:topic, community: community)
|
||||||
|
user = create(:user)
|
||||||
|
login_as(user)
|
||||||
|
|
||||||
|
visit community_path(community)
|
||||||
|
|
||||||
|
expect(page).not_to have_link "Destroy"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user