@@ -35,11 +35,20 @@ class CommentsController < ApplicationController
|
||||
private
|
||||
|
||||
def comment_params
|
||||
params.require(:comment).permit(:commentable_type, :commentable_id, :body)
|
||||
params.require(:comment).permit(:commentable_type, :commentable_id, :body, :as_moderator, :as_administrator)
|
||||
end
|
||||
|
||||
def build_comment
|
||||
@comment = Comment.build(debate, current_user, comment_params[:body])
|
||||
check_for_special_comments
|
||||
end
|
||||
|
||||
def check_for_special_comments
|
||||
if ["1", true].include?(comment_params[:as_administrator]) && can?(:comment_as_administrator, debate)
|
||||
@comment.administrator_id = current_user.administrator.id
|
||||
elsif ["1", true].include?(comment_params[:as_moderator]) && can?(:comment_as_moderator, debate)
|
||||
@comment.moderator_id = current_user.moderator.id
|
||||
end
|
||||
end
|
||||
|
||||
def debate
|
||||
|
||||
@@ -4,7 +4,7 @@ class Comment < ActiveRecord::Base
|
||||
acts_as_paranoid column: :hidden_at
|
||||
acts_as_votable
|
||||
|
||||
attr_accessor :comment_as_moderator, :comment_as_administrator
|
||||
attr_accessor :as_moderator, :as_administrator
|
||||
|
||||
validates :body, presence: true
|
||||
validates :user, presence: true
|
||||
|
||||
@@ -5,6 +5,12 @@
|
||||
<%= t("debates.comment.deleted") %>
|
||||
<% else %>
|
||||
|
||||
<% if comment.as_administrator? %>
|
||||
<%= image_tag("admin_avatar.png", size: 32, class: "admin-avatar left") %>
|
||||
<% elsif comment.as_moderator? %>
|
||||
<%= image_tag("moderator_avatar.png", size: 32, class: "moderator-avatar left") %>
|
||||
<% else %>
|
||||
|
||||
<% if comment.user.organization? %>
|
||||
<%= image_tag("collective_avatar.png", size: 32, class: "avatar left") %>
|
||||
<% else %>
|
||||
@@ -13,28 +19,22 @@
|
||||
<% if comment.user.hidden? %>
|
||||
<i class="icon-deleted user-deleted"></i>
|
||||
<% end %>
|
||||
<!--
|
||||
<% if comment.user.moderator? %> <!-- AND has activated CHECKBOX comment as moderator ->
|
||||
<%= image_tag("moderator_avatar.png", size: 32, class: "moderator-avatar left") %>
|
||||
<% elsif comment.user.administrator? %> <!-- AND has activated CHECKBOX comment as admin ->
|
||||
<%= image_tag("admin_avatar.png", size: 32, class: "admin-avatar left") %>
|
||||
|
||||
<% end %>
|
||||
-->
|
||||
|
||||
<div class="comment-body">
|
||||
<div class="comment-info">
|
||||
|
||||
<% if comment.as_administrator? %>
|
||||
<span class="user-name"><%= t("debates.comment.admin") %> #<%= comment.administrator_id%></span>
|
||||
<% elsif comment.as_moderator? %>
|
||||
<span class="user-name"><%= t("debates.comment.moderator") %> #<%= comment.moderator_id%></span>
|
||||
<% else %>
|
||||
|
||||
<% if comment.user.hidden? %>
|
||||
<span class="user-name"><%= t("debates.comment.user_deleted") %></span>
|
||||
<% else %>
|
||||
|
||||
<% if comment.user.moderator? %> <!-- AND activate moderator CHECKBOX -->
|
||||
<span class="user-name"><%= t("debates.comment.moderator") %> #ID</span> <!-- Add ID to Moderator name -->
|
||||
<% elsif comment.user.administrator? %> <!-- AND activate administrator CHECKBOX -->
|
||||
<span class="user-name"><%= t("debates.comment.admin") %> #ID</span> <!-- Add ID to Admin name -->
|
||||
<% else %>
|
||||
<span class="user-name"><%= comment.user.name %></span>
|
||||
<% end %>
|
||||
|
||||
<% if comment.user.official? %>
|
||||
•
|
||||
<span class="label round level-<%= comment.user.official_level %>">
|
||||
@@ -54,22 +54,24 @@
|
||||
<%= t("debates.comment.author") %>
|
||||
</span>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
|
||||
• <%= time_ago_in_words(comment.created_at) %>
|
||||
|
||||
<span class="right js-flag-as-inappropiate-actions">
|
||||
<%= render 'comments/flag_as_inappropiate_actions', comment: comment %>
|
||||
</span>
|
||||
|
||||
</div>
|
||||
|
||||
<% if comment.user.official? && comment.user_id == @debate.author_id %>
|
||||
<% if comment.as_administrator? %>
|
||||
<p class="comment-user is-admin"><%= comment.body %></p>
|
||||
<% elsif comment.as_moderator? %>
|
||||
<p class="comment-user is-moderator"><%= comment.body %></p>
|
||||
<% elsif comment.user.official? && comment.user_id == @debate.author_id %>
|
||||
<p class="comment-user level-<%= comment.user.official_level %> is-author"><%= comment.body %></p>
|
||||
<% elsif comment.user.official? %>
|
||||
<p class="comment-user level-<%= comment.user.official_level %>"><%= comment.body %></p>
|
||||
<% elsif comment.user.moderator? %> <!-- AND has activated CHECKBOX comment as moderator (all badges are hidden: 100% anonymous) -->
|
||||
<p class="comment-user is-moderator"><%= comment.body %></p>
|
||||
<% elsif comment.user.administrator? %> <!-- AND has activated CHECKBOX comment as admin (all badges are hidden: 100% anonymous) -->
|
||||
<p class="comment-user is-admin"><%= comment.body %></p>
|
||||
<% elsif comment.user_id == @debate.author_id %>
|
||||
<p class="comment-user is-author"><%= comment.body %></p>
|
||||
<% else %>
|
||||
|
||||
@@ -6,17 +6,17 @@
|
||||
|
||||
<%= f.submit comment_button_text(parent), class: "button radius small inline-block" %>
|
||||
|
||||
<!-- if user is moderator
|
||||
<% if can? :comment_as_moderator, @debate %>
|
||||
<div class="right">
|
||||
<%#= f.check_box :, label: false %>
|
||||
<%#= f.label :, t("comments.form.comment_as_moderator"), class: "checkbox" %>
|
||||
<%= f.check_box :as_moderator, label: false %>
|
||||
<%= f.label :as_moderator, t("comments.form.comment_as_moderator"), class: "checkbox" %>
|
||||
</div>
|
||||
end -->
|
||||
<!-- if user is admin
|
||||
<% end %>
|
||||
<% if can? :comment_as_administrator, @debate %>
|
||||
<div class="right">
|
||||
<%#= f.check_box :, label: false %>
|
||||
<%#= f.label :, t("comments.form.comment_as_admin"), class: "checkbox" %>
|
||||
<%= f.check_box :as_administrator, label: false %>
|
||||
<%= f.label :as_administrator, t("comments.form.comment_as_admin"), class: "checkbox" %>
|
||||
</div>
|
||||
end -->
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -168,4 +168,122 @@ feature 'Comments' do
|
||||
expect(InappropiateFlag.flagged?(user, comment)).to_not be
|
||||
end
|
||||
|
||||
feature "Moderators" do
|
||||
scenario "can create comment as a moderator", :js do
|
||||
moderator = create(:moderator)
|
||||
debate = create(:debate)
|
||||
|
||||
login_as(moderator.user)
|
||||
visit debate_path(debate)
|
||||
|
||||
fill_in "comment_body", with: "I am moderating!"
|
||||
check "comment_as_moderator"
|
||||
click_button "Publish comment"
|
||||
|
||||
within "#comments" do
|
||||
expect(page).to have_content "I am moderating!"
|
||||
expect(page).to have_content "Moderator ##{moderator.id}"
|
||||
expect(page).to have_css "p.is-moderator"
|
||||
expect(page).to have_css "img.moderator-avatar"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "can create reply as a moderator", :js do
|
||||
citizen = create(:user, username: "Ana")
|
||||
manuela = create(:user, username: "Manuela")
|
||||
moderator = create(:moderator, user: manuela)
|
||||
debate = create(:debate)
|
||||
comment = create(:comment, commentable: debate, user: citizen)
|
||||
|
||||
login_as(manuela)
|
||||
visit debate_path(debate)
|
||||
|
||||
click_link "Reply"
|
||||
|
||||
within "#js-comment-form-comment_#{comment.id}" do
|
||||
fill_in "comment_body", with: "I am moderating!"
|
||||
check "comment_as_moderator"
|
||||
click_button 'Publish reply'
|
||||
end
|
||||
|
||||
within "#comment_#{comment.id}" do
|
||||
expect(page).to have_content "I am moderating!"
|
||||
expect(page).to have_content "Moderator ##{moderator.id}"
|
||||
expect(page).to have_css "p.is-moderator"
|
||||
expect(page).to have_css "img.moderator-avatar"
|
||||
end
|
||||
|
||||
expect(page).to_not have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
|
||||
end
|
||||
|
||||
scenario "can not comment as an administrator" do
|
||||
moderator = create(:moderator)
|
||||
debate = create(:debate)
|
||||
|
||||
login_as(moderator.user)
|
||||
visit debate_path(debate)
|
||||
|
||||
expect(page).to_not have_content "Comment as administrator"
|
||||
end
|
||||
end
|
||||
|
||||
feature "Administrators" do
|
||||
scenario "can create comment as an administrator", :js do
|
||||
admin = create(:administrator)
|
||||
debate = create(:debate)
|
||||
|
||||
login_as(admin.user)
|
||||
visit debate_path(debate)
|
||||
|
||||
fill_in "comment_body", with: "I am your Admin!"
|
||||
check "comment_as_administrator"
|
||||
click_button "Publish comment"
|
||||
|
||||
within "#comments" do
|
||||
expect(page).to have_content "I am your Admin!"
|
||||
expect(page).to have_content "Administrator ##{admin.id}"
|
||||
expect(page).to have_css "p.is-admin"
|
||||
expect(page).to have_css "img.admin-avatar"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "can create reply as an administrator", :js do
|
||||
citizen = create(:user, username: "Ana")
|
||||
manuela = create(:user, username: "Manuela")
|
||||
admin = create(:administrator, user: manuela)
|
||||
debate = create(:debate)
|
||||
comment = create(:comment, commentable: debate, user: citizen)
|
||||
|
||||
login_as(manuela)
|
||||
visit debate_path(debate)
|
||||
|
||||
click_link "Reply"
|
||||
|
||||
within "#js-comment-form-comment_#{comment.id}" do
|
||||
fill_in "comment_body", with: "Top of the world!"
|
||||
check "comment_as_administrator"
|
||||
click_button 'Publish reply'
|
||||
end
|
||||
|
||||
within "#comment_#{comment.id}" do
|
||||
expect(page).to have_content "Top of the world!"
|
||||
expect(page).to have_content "Administrator ##{admin.id}"
|
||||
expect(page).to have_css "p.is-admin"
|
||||
expect(page).to have_css "img.admin-avatar"
|
||||
end
|
||||
|
||||
expect(page).to_not have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
|
||||
end
|
||||
|
||||
scenario "can not comment as a moderator" do
|
||||
admin = create(:administrator)
|
||||
debate = create(:debate)
|
||||
|
||||
login_as(admin.user)
|
||||
visit debate_path(debate)
|
||||
|
||||
expect(page).to_not have_content "Comment as moderator"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user