Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft creation for nodes #2308

Merged
merged 6 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ Performance/FlatMap:

Performance/HashEachMethods:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what does this removal do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I don't know Jeff, every time I change code this file changes automatically. Can you specify the purpose of this file? Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah -- @ryzokuken @siaw23 do you know why?

Enabled: true

Performance/LstripRstrip:
Enabled: true

Expand Down
33 changes: 22 additions & 11 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -105,20 +111,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)
Expand Down
7 changes: 7 additions & 0 deletions app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions config/locales/controllers/notes_controller/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A very tiny change needed with the word visible here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @seafr and changes done

12 changes: 12 additions & 0 deletions test/fixtures/nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,15 @@ method:
type: "page"
cached_likes: 0
path: "/wiki/spectrometer"

draft:
nid: 21
uid: 2
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
14 changes: 14 additions & 0 deletions test/functional/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/unit/node_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down