From 31c39a59d1f1d3053ce1c2af3d9711f08cf7af21 Mon Sep 17 00:00:00 2001 From: Faldrian Date: Sun, 11 Jan 2015 20:04:26 +0100 Subject: [PATCH] Added post moderation buttons in SPV --- Changelog.md | 1 + .../javascripts/app/views/feedback_view.js | 46 ++++++++++++- .../single_post_content_view.js | 2 + .../single_post_moderation.js | 47 +++++++++++++ .../app/views/stream_post_views.js | 13 +++- .../stylesheets/single-post-view.css.scss | 18 +++++ .../single-post-actions_tpl.jst.hbs | 6 -- .../single-post-content_tpl.jst.hbs | 1 + .../single-post-moderation_tpl.jst.hbs | 19 ++++++ config/locales/javascript/javascript.en.yml | 3 + .../single_post_view_moderation.feature | 66 +++++++++++++++++++ .../single_post_view_steps.rb | 15 +++++ 12 files changed, 226 insertions(+), 11 deletions(-) create mode 100644 app/assets/javascripts/app/views/single-post-viewer/single_post_moderation.js create mode 100644 app/assets/templates/single-post-viewer/single-post-moderation_tpl.jst.hbs create mode 100644 features/desktop/single_post_view_moderation.feature create mode 100644 features/step_definitions/single_post_view_steps.rb diff --git a/Changelog.md b/Changelog.md index f82bb1bf9..d66913373 100644 --- a/Changelog.md +++ b/Changelog.md @@ -153,6 +153,7 @@ diaspora.yml file**. The existing settings from 0.4.x and before will not work a * Strip EXIF data from newly uploaded images [#5510](https://github.com/diaspora/diaspora/pull/5510) * Hide user setting if the community spotlight is not enabled on the pod [#5562](https://github.com/diaspora/diaspora/pull/5562) * Add HTML view for pod statistics [#5464](https://github.com/diaspora/diaspora/pull/5464) +* Added/Moved hide, block user, report and delete button in SPV [#5547](https://github.com/diaspora/diaspora/pull/5547) # 0.4.1.2 diff --git a/app/assets/javascripts/app/views/feedback_view.js b/app/assets/javascripts/app/views/feedback_view.js index a224bfd94..200a11830 100644 --- a/app/assets/javascripts/app/views/feedback_view.js +++ b/app/assets/javascripts/app/views/feedback_view.js @@ -8,7 +8,10 @@ app.views.Feedback = app.views.Base.extend({ events: { "click .like" : "toggleLike", "click .reshare" : "resharePost", - "click .post_report" : "report" + + "click .post_report" : "report", + "click .block_user" : "blockUser", + "click .hide_post" : "hidePost", }, tooltipSelector : ".label", @@ -40,7 +43,46 @@ app.views.Feedback = app.views.Base.extend({ if(evt) { evt.preventDefault(); } if(!window.confirm(Diaspora.I18n.t("reshares.post", {name: this.model.reshareAuthor().name}))) { return } this.model.interactions.reshare(); - } + }, + + blockUser: function(evt) { + if(evt) { evt.preventDefault(); } + if(!confirm(Diaspora.I18n.t('ignore_user'))) { return; } + + this.model.blockAuthor() + .done(function() { + // return to stream + document.location.href = "/stream"; + }) + .fail(function() { + Diaspora.page.flashMessages.render({ + success: false, + notice: Diaspora.I18n.t('hide_post_failed') + }); + }); + }, + + hidePost : function(evt) { + if(evt) { evt.preventDefault(); } + if(!confirm(Diaspora.I18n.t('hide_post'))) { return; } + + $.ajax({ + url : "/share_visibilities/42", + type : "PUT", + data : { + post_id : this.model.id + } + }).done(function() { + // return to stream + document.location.href = "/stream"; + }) + .fail(function() { + Diaspora.page.flashMessages.render({ + success: false, + notice: Diaspora.I18n.t('ignore_post_failed') + }); + }); + }, }); // @license-end diff --git a/app/assets/javascripts/app/views/single-post-viewer/single_post_content_view.js b/app/assets/javascripts/app/views/single-post-viewer/single_post_content_view.js index dba3b08e9..67f83f3b5 100644 --- a/app/assets/javascripts/app/views/single-post-viewer/single_post_content_view.js +++ b/app/assets/javascripts/app/views/single-post-viewer/single_post_content_view.js @@ -6,6 +6,7 @@ app.views.SinglePostContent = app.views.Base.extend({ subviews : { "#single-post-actions" : "singlePostActionsView", + '#single-post-moderation': "singlePostModerationView", '#real-post-content' : 'postContentView', ".oembed" : "oEmbedView", ".opengraph" : "openGraphView", @@ -15,6 +16,7 @@ app.views.SinglePostContent = app.views.Base.extend({ initialize : function() { this.singlePostActionsView = new app.views.SinglePostActions({model: this.model}); + this.singlePostModerationView = new app.views.SinglePostModeration({model: this.model}); this.oEmbedView = new app.views.OEmbed({model : this.model}); this.openGraphView = new app.views.SPVOpenGraph({model : this.model}); this.postContentView = new app.views.ExpandedStatusMessage({model: this.model}); diff --git a/app/assets/javascripts/app/views/single-post-viewer/single_post_moderation.js b/app/assets/javascripts/app/views/single-post-viewer/single_post_moderation.js new file mode 100644 index 000000000..4bece481a --- /dev/null +++ b/app/assets/javascripts/app/views/single-post-viewer/single_post_moderation.js @@ -0,0 +1,47 @@ +app.views.SinglePostModeration = app.views.Feedback.extend({ + templateName: "single-post-viewer/single-post-moderation", + + events: function() { + return _.defaults({ + "click .remove_post": "destroyModel", + }, app.views.Feedback.prototype.events); + }, + + presenter: function() { + var interactions = this.model.interactions; + + return _.extend(this.defaultPresenter(), { + authorIsCurrentUser : this.authorIsCurrentUser(), + }); + }, + + renderPluginWidgets : function() { + app.views.Base.prototype.renderPluginWidgets.apply(this); + this.$('a').tooltip({placement: 'bottom'}); + }, + + authorIsCurrentUser: function() { + return app.currentUser.authenticated() && this.model.get("author").id == app.user().id; + }, + + destroyModel: function(evt) { + if(evt) { evt.preventDefault(); } + var url = this.model.urlRoot + '/' + this.model.id; + + if (confirm(Diaspora.I18n.t("remove_post"))) { + this.model.destroy({ url: url }) + .done(function() { + // return to stream + document.location.href = "/stream"; + }) + .fail(function() { + var flash = new Diaspora.Widgets.FlashMessages; + flash.render({ + success: false, + notice: Diaspora.I18n.t('failed_to_remove') + }); + }); + } + } + +}); diff --git a/app/assets/javascripts/app/views/stream_post_views.js b/app/assets/javascripts/app/views/stream_post_views.js index 3270521bd..3fe47f3e8 100644 --- a/app/assets/javascripts/app/views/stream_post_views.js +++ b/app/assets/javascripts/app/views/stream_post_views.js @@ -95,15 +95,22 @@ app.views.StreamPost = app.views.Post.extend({ if(evt) { evt.preventDefault(); } if(!confirm(Diaspora.I18n.t('confirm_dialog'))) { return } + var self = this; $.ajax({ url : "/share_visibilities/42", type : "PUT", data : { post_id : this.model.id } - }) - - this.remove(); + }).done(function() { + self.remove(); + }) + .fail(function() { + Diaspora.page.flashMessages.render({ + success: false, + notice: Diaspora.I18n.t('hide_post_failed') + }); + }); }, focusCommentTextarea: function(evt){ diff --git a/app/assets/stylesheets/single-post-view.css.scss b/app/assets/stylesheets/single-post-view.css.scss index ec43c8a1a..61792c806 100644 --- a/app/assets/stylesheets/single-post-view.css.scss +++ b/app/assets/stylesheets/single-post-view.css.scss @@ -84,6 +84,24 @@ } } } + #single-post-moderation { + a:hover { + text-decoration: none; + } + i { + padding-right: 5px; + vertical-align: top; + &:hover { + color: #424242; + } + } + a.post_report > i { + font-size: 14px; + } + i.cross { + font-size: 20px; + } + } } #body { diff --git a/app/assets/templates/single-post-viewer/single-post-actions_tpl.jst.hbs b/app/assets/templates/single-post-viewer/single-post-actions_tpl.jst.hbs index 908c2d4ab..a183acba3 100644 --- a/app/assets/templates/single-post-viewer/single-post-actions_tpl.jst.hbs +++ b/app/assets/templates/single-post-viewer/single-post-actions_tpl.jst.hbs @@ -23,11 +23,5 @@ {{/if}} {{/if}} - - {{#if authorIsNotCurrentUser}} - - ! - - {{/if}} {{/if}} diff --git a/app/assets/templates/single-post-viewer/single-post-content_tpl.jst.hbs b/app/assets/templates/single-post-viewer/single-post-content_tpl.jst.hbs index e804b3c95..8a4dacb4a 100644 --- a/app/assets/templates/single-post-viewer/single-post-content_tpl.jst.hbs +++ b/app/assets/templates/single-post-viewer/single-post-content_tpl.jst.hbs @@ -58,6 +58,7 @@ {{/if}}
+
{{#unless root}} diff --git a/app/assets/templates/single-post-viewer/single-post-moderation_tpl.jst.hbs b/app/assets/templates/single-post-viewer/single-post-moderation_tpl.jst.hbs new file mode 100644 index 000000000..918120a24 --- /dev/null +++ b/app/assets/templates/single-post-viewer/single-post-moderation_tpl.jst.hbs @@ -0,0 +1,19 @@ +
+ {{#if loggedIn}} + {{#if authorIsCurrentUser}} + + + + {{else}} + + ! + + + 🚫 + + + + + {{/if}} + {{/if}} +
\ No newline at end of file diff --git a/config/locales/javascript/javascript.en.yml b/config/locales/javascript/javascript.en.yml index 77fbeb3d1..349df2b36 100644 --- a/config/locales/javascript/javascript.en.yml +++ b/config/locales/javascript/javascript.en.yml @@ -18,6 +18,9 @@ en: exists: "The report already exists" ignore_user: "Ignore this user?" ignore_failed: "Unable to ignore this user" + hide_post: "Hide this post?" + hide_post_failed: "Unable to hide this post" + remove_post: "Remove this post?" unblock_failed: "Unblocking this user has failed" and: "and" comma: "," diff --git a/features/desktop/single_post_view_moderation.feature b/features/desktop/single_post_view_moderation.feature new file mode 100644 index 000000000..62ca4922f --- /dev/null +++ b/features/desktop/single_post_view_moderation.feature @@ -0,0 +1,66 @@ +@javascript + Feature: using SPV moderation buttons + + Background: + Given following users exist: + | username | + | bob | + | alice | + And I sign in as "bob@bob.bob" + And a user with username "bob" is connected with "alice" + And I am on the home page + + Scenario: hide a contact's post + Given I expand the publisher + When I write the status message "Here is a post to test with" + And I submit the publisher + + And I log out + And I sign in as "alice@alice.alice" + + And I open the show page of the "Here is a post to test with" post + And I click to hide the post + And I confirm the alert + + Then I should be on the stream page + + Scenario: block a contact + Given I expand the publisher + When I write the status message "Here is a post to test with" + And I submit the publisher + + And I log out + And I sign in as "alice@alice.alice" + + And I open the show page of the "Here is a post to test with" post + And I click to block the user + And I confirm the alert + + Then I should be on the stream page + + Scenario: report a contact + Given I expand the publisher + When I write the status message "Here is a post to test with" + And I submit the publisher + + And I log out + And I sign in as "alice@alice.alice" + + And I open the show page of the "Here is a post to test with" post + And I click to report the post + And I confirm the alert + + And I should see a flash message containing "The report was successfully created" + + Scenario: delete own post + Given I expand the publisher + When I write the status message "Here is a post to test with" + And I submit the publisher + + And I open the show page of the "Here is a post to test with" post + And I click to delete the post + And I confirm the alert + + Then I should be on the stream page + + \ No newline at end of file diff --git a/features/step_definitions/single_post_view_steps.rb b/features/step_definitions/single_post_view_steps.rb new file mode 100644 index 000000000..470131e5d --- /dev/null +++ b/features/step_definitions/single_post_view_steps.rb @@ -0,0 +1,15 @@ +And /^I click to hide the post/ do + find('.hide_post').click +end + +And /^I click to block the user/ do + find('.block_user').click +end + +And /^I click to report the post/ do + find('.post_report').click +end + +And /^I click to delete the post/ do + find('.remove_post').click +end \ No newline at end of file