From 6ca903719d45487ef657c06420f0ea70479bd8c5 Mon Sep 17 00:00:00 2001 From: gauravano Date: Mon, 12 Feb 2018 21:41:23 +0530 Subject: [PATCH 1/6] Status method --- app/models/node.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/models/node.rb b/app/models/node.rb index 969764fd09..800eecc918 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -862,4 +862,11 @@ def self.unlike(nid , user) end count end + + # status = 3 for draft nodes,visible to author only + def draft + self.status = 3 + save + self + end end From 41385e7086ca0a71f73e50fd8783fdc6b08d8154 Mon Sep 17 00:00:00 2001 From: gauravano Date: Wed, 14 Feb 2018 01:13:42 +0530 Subject: [PATCH 2/6] controller changed --- ...ify-github-io-ruby-style-guide-rubocop-yml | 3 --- app/controllers/notes_controller.rb | 27 +++++++++++-------- .../controllers/notes_controller/en.yml | 1 + 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.rubocop-http---shopify-github-io-ruby-style-guide-rubocop-yml b/.rubocop-http---shopify-github-io-ruby-style-guide-rubocop-yml index d3c946a143..36ce2ef9a9 100644 --- a/.rubocop-http---shopify-github-io-ruby-style-guide-rubocop-yml +++ b/.rubocop-http---shopify-github-io-ruby-style-guide-rubocop-yml @@ -1080,9 +1080,6 @@ Performance/FixedSize: Performance/FlatMap: EnabledForFlattenWithoutParams: false -Performance/HashEachMethods: - Enabled: true - Performance/LstripRstrip: Enabled: true diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index e17a9d8de7..5dfcdf9ff6 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -105,20 +105,25 @@ def create @node.add_tag('event:rsvp', current_user) @node.add_tag('date:' + params[:date], current_user) if params[:date] end - if current_user.first_time_poster - AdminMailer.notify_node_moderators(@node) - flash[:first_time_post] = true - if @node.has_power_tag('question') - flash[:notice] = I18n.t('notes_controller.thank_you_for_question').html_safe + if params[:draft] != true + if current_user.first_time_poster + AdminMailer.notify_node_moderators(@node) + flash[:first_time_post] = true + if @node.has_power_tag('question') + flash[:notice] = I18n.t('notes_controller.thank_you_for_question').html_safe + else + flash[:notice] = I18n.t('notes_controller.thank_you_for_contribution').html_safe + end else - flash[:notice] = I18n.t('notes_controller.thank_you_for_contribution').html_safe + if @node.has_power_tag('question') + flash[:notice] = I18n.t('notes_controller.question_note_published').html_safe + else + flash[:notice] = I18n.t('notes_controller.research_note_published').html_safe + end end else - if @node.has_power_tag('question') - flash[:notice] = I18n.t('notes_controller.question_note_published').html_safe - else - flash[:notice] = I18n.t('notes_controller.research_note_published').html_safe - end + @node.draft + flash[:notice] = I18n.t('notes_controller.saved_as_draft').html_safe end # Notice: Temporary redirect.Remove this condition after questions show page is complete. # Just keep @node.path(:question) diff --git a/config/locales/controllers/notes_controller/en.yml b/config/locales/controllers/notes_controller/en.yml index 8830dbc1f8..c3c210d44d 100644 --- a/config/locales/controllers/notes_controller/en.yml +++ b/config/locales/controllers/notes_controller/en.yml @@ -16,3 +16,4 @@ en: highly_liked_research_notes: "Highly liked research notes" popular_research_notes: "Popular research notes" more_than_one_contributor: "You cannot delete a wiki page once someone else has begun to contribute to it" + saved_as_draft: "Your contribution has been saved as draft and will be visisble to you only" \ No newline at end of file From ba87f38bc620493507a12165a030b9a3fe1a6ef9 Mon Sep 17 00:00:00 2001 From: gauravano Date: Fri, 16 Feb 2018 14:59:42 +0530 Subject: [PATCH 3/6] test added for access --- app/controllers/notes_controller.rb | 6 ++++++ test/fixtures/nodes.yml | 12 ++++++++++++ test/functional/notes_controller_test.rb | 14 ++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 5dfcdf9ff6..0fff134403 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -52,6 +52,12 @@ def show @node = Node.find params[:id] end + if @node.status == 3 && (current_user.nil? || @node.author != current_user) + flash[:notice] = "Only author can access the draft note" + redirect_to '/' + return + end + if @node.has_power_tag('question') redirect_to @node.path(:question) return diff --git a/test/fixtures/nodes.yml b/test/fixtures/nodes.yml index 0c528a7403..8a324d0cba 100644 --- a/test/fixtures/nodes.yml +++ b/test/fixtures/nodes.yml @@ -236,3 +236,15 @@ method: type: "page" cached_likes: 0 path: "/wiki/spectrometer" + +draft: + nid: 21 + uid: 1 + title: "Draft note" + path: "/notes/test/<%= Time.now.strftime("%m-%d-%Y") %>/draft-note" + created: <%= Time.now.to_i %> + changed: <%= Time.now.to_i %> + status: 3 + type: "note" + cached_likes: 0 + slug: test-<%= Time.now.strftime("%m-%d-%Y") %>-draft-note diff --git a/test/functional/notes_controller_test.rb b/test/functional/notes_controller_test.rb index 0d112fce5b..36313844df 100644 --- a/test/functional/notes_controller_test.rb +++ b/test/functional/notes_controller_test.rb @@ -625,5 +625,19 @@ def test_get_rss_feed assert_equal 'application/rss+xml', @response.content_type end + test 'draft should not be shown when no user' do + node = nodes(:draft) + post :show, id: '21',title: 'Draft note' + assert_redirected_to '/' + assert_equal "Only author can access the draft note", flash[:notice] + end + + test 'draft should not be shown when user is not author' do + node = nodes(:draft) + UserSession.create(users(:test_user)) + post :show, id: '21',title: 'Draft note' + assert_redirected_to '/' + assert_equal "Only author can access the draft note", flash[:notice] + end end From af6ea679845c64fdebef155336be26cca5391df9 Mon Sep 17 00:00:00 2001 From: Gaurav Sachdeva Date: Fri, 16 Feb 2018 15:03:26 +0530 Subject: [PATCH 4/6] update rubocop file --- .rubocop-http---shopify-github-io-ruby-style-guide-rubocop-yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop-http---shopify-github-io-ruby-style-guide-rubocop-yml b/.rubocop-http---shopify-github-io-ruby-style-guide-rubocop-yml index 36ce2ef9a9..232fc30753 100644 --- a/.rubocop-http---shopify-github-io-ruby-style-guide-rubocop-yml +++ b/.rubocop-http---shopify-github-io-ruby-style-guide-rubocop-yml @@ -1080,6 +1080,9 @@ Performance/FixedSize: Performance/FlatMap: EnabledForFlattenWithoutParams: false +Performance/HashEachMethods: + Enabled: true + Performance/LstripRstrip: Enabled: true From c3f603cb0431ed5af3c27fb2ca66c8a936f5184f Mon Sep 17 00:00:00 2001 From: gauravano Date: Fri, 16 Feb 2018 15:26:27 +0530 Subject: [PATCH 5/6] fixing test affected by new fixture --- test/fixtures/nodes.yml | 2 +- test/unit/node_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fixtures/nodes.yml b/test/fixtures/nodes.yml index 8a324d0cba..471613c8d8 100644 --- a/test/fixtures/nodes.yml +++ b/test/fixtures/nodes.yml @@ -239,7 +239,7 @@ method: draft: nid: 21 - uid: 1 + uid: 2 title: "Draft note" path: "/notes/test/<%= Time.now.strftime("%m-%d-%Y") %>/draft-note" created: <%= Time.now.to_i %> diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb index e9320c772a..1a53cf4dfe 100644 --- a/test/unit/node_test.rb +++ b/test/unit/node_test.rb @@ -203,7 +203,7 @@ class NodeTest < ActiveSupport::TestCase test 'should find all research notes' do notes = Node.research_notes - expected = [nodes(:one), nodes(:spam), nodes(:first_timer_note), nodes(:blog), nodes(:moderated_user_note), nodes(:activity), nodes(:upgrade)] + expected = [nodes(:one), nodes(:spam), nodes(:first_timer_note), nodes(:blog), nodes(:moderated_user_note), nodes(:activity), nodes(:upgrade), nodes(:draft)] assert_equal expected, notes end From b6a6d15f426ea2b45dadc71e1b003dfbd29dc11b Mon Sep 17 00:00:00 2001 From: Gaurav Sachdeva Date: Sat, 17 Feb 2018 03:55:49 +0530 Subject: [PATCH 6/6] update en.yml --- config/locales/controllers/notes_controller/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/controllers/notes_controller/en.yml b/config/locales/controllers/notes_controller/en.yml index c3c210d44d..19631adbbc 100644 --- a/config/locales/controllers/notes_controller/en.yml +++ b/config/locales/controllers/notes_controller/en.yml @@ -16,4 +16,4 @@ en: highly_liked_research_notes: "Highly liked research notes" popular_research_notes: "Popular research notes" more_than_one_contributor: "You cannot delete a wiki page once someone else has begun to contribute to it" - saved_as_draft: "Your contribution has been saved as draft and will be visisble to you only" \ No newline at end of file + saved_as_draft: "Your contribution has been saved as draft and will be visible to you only"