Add /mod views (#299)

* Fix boosted issue

* Add /mod views

* Fix format issue

* Remove unnecessary articles controller code
This commit is contained in:
Ben Halpern 2018-05-09 18:26:36 -04:00 committed by GitHub
parent 1a23658578
commit 6cff2e68d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 142 additions and 0 deletions

View file

@ -0,0 +1,20 @@
class ModerationsController < ApplicationController
before_action :check_trusted
def article
@moderatable = Article.find_by_slug(params[:slug])
render template: "moderations/mod"
end
def comment
@moderatable = Comment.find(params[:id_code].to_i(26))
render template: "moderations/mod"
end
private
def check_trusted
not_found unless current_user&.has_role?(:trusted)
end
end

View file

@ -21,6 +21,7 @@ module ApplicationHelper
controller_name == "users" ||
controller_name == "pages" ||
controller_name == "dashboards"||
controller_name == "moderations"||
controller_name == "stories" ||
controller_name == "comments" ||
controller_name == "notifications" ||

View file

@ -0,0 +1,74 @@
<style>
.reaction-button{
position: relative;
width: 60px;
height: 60px;
background: white;
border-color: white;
margin: 100px 40px;
border-radius:200px;
}
.reaction-button img {
position: absolute;
top: 0;
width: 60px;
left: 0;
}
.reaction-button .reacted-emoji {
display: none;
}
.reaction-button.reacted .reacted-emoji {
display: block;
}
</style>
<div class="container" style="text-align: center">
<h2>MODERATE: <a href="<%= @moderatable.path %>"><%= @moderatable.title %></a></h2>
<button class="reaction-button <%= Reaction.cached_any_reactions_for?(@moderatable, current_user, "thumbsdown") ? "reacted" : "" %>" data-reactable-id="<%= @moderatable.id %>" data-category="thumbsdown" data-reactable-type="<%= @moderatable.class.name %>">
<%= image_tag "emoji/emoji-one-thumbs-down-gray.png" %>
<img class="reacted-emoji" src="<%= asset_path("emoji/emoji-one-thumbs-down.png") %>"/>
</button>
<button class="reaction-button <%= Reaction.cached_any_reactions_for?(@moderatable, current_user, "vomit") ? "reacted" : "" %>" data-reactable-id="<%= @moderatable.id %>" data-category="vomit" data-reactable-type="<%= @moderatable.class.name %>">
<%= image_tag "emoji/emoji-one-nausea-face-gray.png" %>
<img class="reacted-emoji" src="<%= asset_path("emoji/emoji-one-nausea-face.png") %>"/>
</button>
<p style="width: 80%;margin:50px auto">
Negative reactions are private. Use the :thumbsdown: to move something "down" for any reason. The :vomit: is for clear code of conduct violations.
</p>
</div>
<script defer>
setTimeout(function(){
var butts = document.getElementsByClassName('reaction-button');
for (var i = 0; i < butts.length; i++) {
var butt = butts[i];
butt.onclick = function (event) {
event.preventDefault();
var thisButt = this;
thisButt.classList.add('reacted');
function successCb(response) {
if (response.result === 'create') {
thisButt.classList.add('reacted');
} else {
thisButt.classList.remove('reacted');
}
}
var formData = new FormData();
formData.append('reactable_type', thisButt.dataset.reactableType);
formData.append('category', thisButt.dataset.category);
formData.append('reactable_id', thisButt.dataset.reactableId);
getCsrfToken()
.then(sendFetch('reaction-creation', formData))
.then(function (response) {
if (response.status === 200) {
response.json().then(successCb);
}
});
};
}
}, 200)
</script>

View file

@ -220,6 +220,7 @@ Rails.application.routes.draw do
get "/:timeframe" => "stories#index", constraints: { timeframe: /latest/}
#Lagacy comment format (might still be floating around app, and external links)
get "/:username/:slug/comments/new/:parent_id_code" => "comments#new"
get "/:username/:slug/comments/new" => "comments#new"
get "/:username/:slug/comments" => "comments#index"
@ -227,11 +228,15 @@ Rails.application.routes.draw do
get "/:username/:slug/comments/:id_code/edit" => "comments#edit"
get "/:username/:slug/comments/:id_code/delete_confirm" => "comments#delete_confirm"
#Proper link format
get "/:username/comment/:id_code" => "comments#index"
get "/:username/comment/:id_code/edit" => "comments#edit"
get "/:username/comment/:id_code/delete_confirm" => "comments#delete_confirm"
get "/:username/comment/:id_code/mod" => "moderations#comment"
get "/:username/:slug/:view" => "stories#show", constraints: { view: /moderate/}
get "/:username/:slug/mod" => "moderations#article"
get "/:username/:slug/edit" => "articles#edit"
get "/:username/:slug/delete_confirm" => "articles#delete_confirm"
get "/:username/:view" => "stories#index", constraints: { view: /comments|moderate|admin/}

View file

@ -0,0 +1,42 @@
require "rails_helper"
RSpec.describe "Moderations", type: :request do
let(:user) { create(:user) }
let(:article) { create(:article, user_id: user.id) }
let(:comment) do
create(:comment,
commentable_id: article.id,
commentable_type: "Article",
user_id: user.id)
end
before do
sign_in user
end
describe "GET moderations article" do
it "returns 200 if user trusted" do
user.add_role :trusted
get article.path + "/mod"
expect(response).to have_http_status(200)
end
it "returns 404 if user trusted not trusted" do
expect do
get article.path + "/mod"
end.to raise_error(ActionController::RoutingError)
end
end
describe "GET moderations comment" do
it "returns 200 if user trusted" do
user.add_role :trusted
get comment.path + "/mod"
expect(response).to have_http_status(200)
end
it "returns 404 if user trusted not trusted" do
expect do
get comment.path + "/mod"
end.to raise_error(ActionController::RoutingError)
end
end
end