Skip to content

Commit

Permalink
It is now possible to report comments
Browse files Browse the repository at this point in the history
* Renamed PostReport to Report
* Added report button to SPV
* Updated rspec

refs #4732
refs #4710
refs #4711
refs #4517
  • Loading branch information
Lukas Matt committed May 15, 2014
1 parent ee6212c commit 1748d3b
Show file tree
Hide file tree
Showing 35 changed files with 406 additions and 239 deletions.
File renamed without changes
3 changes: 0 additions & 3 deletions app/assets/javascripts/app/models/post_report.js

This file was deleted.

8 changes: 8 additions & 0 deletions app/assets/javascripts/app/models/report.js
@@ -0,0 +1,8 @@
app.models.Report = Backbone.Model.extend({
urlRoot: '/report',

getReason: function() {
return prompt(Diaspora.I18n.t('report_prompt'), Diaspora.I18n.t('report_prompt_default'));
}

});
17 changes: 16 additions & 1 deletion app/assets/javascripts/app/views/comment_view.js
Expand Up @@ -5,7 +5,8 @@ app.views.Comment = app.views.Content.extend({

events : function() {
return _.extend({}, app.views.Content.prototype.events, {
"click .comment_delete": "destroyModel"
"click .comment_delete": "destroyModel",
"click .comment_report": "report"
});
},

Expand All @@ -31,6 +32,20 @@ app.views.Comment = app.views.Content.extend({

canRemove : function() {
return app.currentUser.authenticated() && (this.ownComment() || this.postOwner())
},

report: function(evt) {
if(evt) { evt.preventDefault(); }
var report = new app.models.Report();
var msg = report.getReason();
if (msg !== null) {
var id = this.model.id;
var type = $(evt.currentTarget).data("type");
report.fetch({
data: { id: id, type: type, text: msg },
type: 'POST'
});
}
}
});

Expand Down
17 changes: 16 additions & 1 deletion app/assets/javascripts/app/views/feedback_view.js
Expand Up @@ -6,7 +6,8 @@ app.views.Feedback = app.views.Base.extend({
events: {
"click *[rel='auth-required']" : "requireAuth",
"click .like" : "toggleLike",
"click .reshare" : "resharePost"
"click .reshare" : "resharePost",
"click .post_report" : "report"
},

tooltipSelector : ".label",
Expand Down Expand Up @@ -44,5 +45,19 @@ app.views.Feedback = app.views.Base.extend({
if( app.currentUser.authenticated() ) { return }
alert("you must be logged in to do that!")
return false;
},

report: function(evt) {
if(evt) { evt.preventDefault(); }
var report = new app.models.Report();
var msg = report.getReason();
if (msg !== null) {
var id = this.model.id;
var type = $(evt.currentTarget).data("type");
report.fetch({
data: { id: id, type: type, text: msg },
type: 'POST'
});
}
}
});
15 changes: 15 additions & 0 deletions app/assets/javascripts/app/views/post_view.js
Expand Up @@ -13,5 +13,20 @@ app.views.Post = app.views.Base.extend({

showPost : function() {
return (app.currentUser.get("showNsfw")) || !this.model.get("nsfw")
},

report: function(evt) {
if(evt) { evt.preventDefault(); }
var report = new app.models.Report();
var msg = report.getReason();
if (msg !== null) {
var id = this.model.id;
var type = $(evt.currentTarget).data("type");
report.fetch({
data: { id: id, type: type, text: msg },
type: 'POST'
});
}
}

});
17 changes: 1 addition & 16 deletions app/assets/javascripts/app/views/stream_post_views.js
Expand Up @@ -20,7 +20,7 @@ app.views.StreamPost = app.views.Post.extend({

"click .remove_post": "destroyModel",
"click .hide_post": "hidePost",
"click .post_report": "postReport",
"click .post_report": "report",
"click .block_user": "blockUser"
},

Expand Down Expand Up @@ -108,21 +108,6 @@ app.views.StreamPost = app.views.Post.extend({
this.remove();
},

postReport : function(evt) {
if(evt) { evt.preventDefault(); }
var text = prompt(Diaspora.I18n.t('post_report_prompt'),
Diaspora.I18n.t('post_report_prompt_default'));

var postReport = new app.models.PostReport();
postReport.fetch({
data: {
post_id: this.model.id,
text: text
},
type: 'POST'
});
},

focusCommentTextarea: function(evt){
evt.preventDefault();
this.$(".new_comment_form_wrapper").removeClass("hidden");
Expand Down
6 changes: 3 additions & 3 deletions app/assets/stylesheets/application.css.sass
Expand Up @@ -17,8 +17,8 @@
@import 'facebox'
@import 'aspects'
@import 'popover'
@import 'post_report'
@import 'stream_element'
@import 'report'

/* ====== media ====== */
.media
Expand Down Expand Up @@ -211,10 +211,10 @@ ul.as-selections
:z-index 6
:float right

.post_report
.post_report, .comment_report
:display inline-block

.icons-postreport
.icons-report
:height 14px
:width 14px

Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/entypo.css.scss
Expand Up @@ -141,6 +141,7 @@
&.globe:before { content: '\1f30e'; } /* 1f30e */
&.graduation-cap:before { content: '\1f393 '; } /* 1f393 */
&.heart-empty:before { content: '\2661'; } /* 2661 */
&.report:before { content: '\21'; } /* 21 */
&.heart:before { content: '\2665'; } /* 2665 */
&.help:before { content: '\2753'; } /* 2753 */
&.home:before { content: '\2302'; } /* 2302 */
Expand Down
@@ -1,4 +1,4 @@
#post_report {
#report {
padding-top: 2em;
span {
display: block;
Expand All @@ -11,6 +11,8 @@
}
.clear {
clear: both;
border-bottom: 1px solid #808080;
padding-bottom: 1em;
margin-bottom: 1em;
}
}
6 changes: 6 additions & 0 deletions app/assets/stylesheets/single-post-view.css.scss
Expand Up @@ -61,6 +61,12 @@
i.comment:hover {
color: #424242;
}
i.report.gray:hover {
color: $red;
}
i.report.red:hover {
color: #f55f5a;
}
i.heart.gray:hover {
color: $red;
}
Expand Down
14 changes: 9 additions & 5 deletions app/assets/templates/comment_tpl.jst.hbs
Expand Up @@ -6,13 +6,17 @@
</div>

<div class="bd">
<div class="controls">
{{#if canRemove}}
<div class="controls">
<a href="#" class="delete comment_delete" title="{{t "delete"}}">
<div alt="Deletelabel" class="icons-deletelabel" />
<a/>
</div>
<a href="#" class="delete comment_delete" title="{{t "delete"}}">
<div alt="Deletelabel" class="icons-deletelabel" />
<a/>
{{else}}
<a href="#" data-type="comment" class="comment_report" title="{{t "report"}}">
<div class="icons-report control_icon"/>
</a>
{{/if}}
</div>

{{#with author}}
<a href="/people/{{guid}}" class="author author-name {{hovercardable this}}">
Expand Down
Expand Up @@ -22,5 +22,9 @@
</a>
{{/if}}
{{/if}}

<a href="#" rel="auth-required" data-type="post" class="post_report" title="{{t "report"}}">
<i class="entypo report gray large"/>
</a>
</div>
</div>
4 changes: 2 additions & 2 deletions app/assets/templates/stream-element_tpl.jst.hbs
Expand Up @@ -10,8 +10,8 @@
{{#if loggedIn}}
<div class="controls">
{{#unless authorIsCurrentUser}}
<a href="#" rel="nofollow" class="post_report" title="{{t "post_report"}}">
<div class="icons-postreport control_icon"/>
<a href="#" rel="nofollow" data-type="post" class="post_report" title="{{t "report"}}">
<div class="icons-report control_icon"/>
</a>
<a href="#" rel="nofollow" class="block_user" title="{{t "ignore"}}">
<div class="icons-ignoreuser control_icon"></div>
Expand Down
61 changes: 0 additions & 61 deletions app/controllers/post_report_controller.rb

This file was deleted.

67 changes: 67 additions & 0 deletions app/controllers/report_controller.rb
@@ -0,0 +1,67 @@
class ReportController < ApplicationController
before_filter :authenticate_user!
before_filter :redirect_unless_admin, :except => [:create]

def index
@report = Report.where(reviewed: false).all
end

def update
if Report.where(post_type: params[:type]).exists?(post_id: params[:id])
mark_as_reviewed
end
redirect_to :action => :index and return
end

def destroy
if (params[:type].eql? "post")
if Post.exists?(params[:id])
delete_post
end
elsif (params[:type].eql? "comment")
if Comment.exists?(params[:id])
delete_comment
end
end
redirect_to :action => :index and return
end

def create
code = 400
username = current_user.username
post = Report.new(
:post_id => params[:id],
:post_type => params[:type],
:user_id => username,
:text => params[:text])
unless Report.where("post_id = ? AND post_type = ?", params[:id], params[:type]).exists?(user_id: username)
result = post.save
code = 200 if result
end
render :nothing => true, :status => code
end

private
def delete_post
post = Post.find(params[:id])
current_user.retract(post)
mark_as_reviewed
flash[:notice] = I18n.t 'report.status.destroyed'
end

def delete_comment
comment = Comment.find(params[:id])
#current_user.retract(comment)
comment.destroy
mark_as_reviewed
flash[:notice] = I18n.t 'report.status.destroyed'
end

def mark_as_reviewed
posts = Report.where("post_id = ? AND post_type = ?", params[:id], params[:type])
posts.each do |post|
post.update_attributes(reviewed: true)
end
flash[:notice] = I18n.t 'report.status.marked'
end
end
13 changes: 13 additions & 0 deletions app/helpers/report_helper.rb
@@ -0,0 +1,13 @@
# Copyright (c) 2012, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.

module ReportHelper
def report_content(id, type)
if type.eql? "post"
raw t('report.post_label', title: link_to(post_page_title(Post.find_by_id(id)), post_path(id)))
elsif type.eql? "comment"
raw t('report.comment_label', data: comment_message(Comment.find_by_id(id)))
end
end
end
18 changes: 0 additions & 18 deletions app/mailers/post_report_mailer.rb

This file was deleted.

0 comments on commit 1748d3b

Please sign in to comment.