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 display on Dashboard #2666

Merged
merged 5 commits into from
May 17, 2018
Merged
Changes from all 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
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -136,6 +136,8 @@ def alert_and_redirect_moderated
flash[:warning] = "First-time poster <a href='/profile/#{@node.author.name}'>#{@node.author.name}</a> submitted this #{time_ago_in_words(@node.created_at)} ago and it has not yet been approved by a moderator. <a class='btn btn-default btn-sm' href='/moderate/publish/#{@node.id}'>Approve</a> <a class='btn btn-default btn-sm' href='/moderate/spam/#{@node.id}'>Spam</a>"
elsif @node.status == 4 && (current_user && current_user.id == @node.author.id) && !flash[:first_time_post]
flash[:warning] = "Thank you for contributing open research, and thanks for your patience while your post is approved by <a href='/wiki/moderation'>community moderators</a> and we'll email you when it is published. In the meantime, if you have more to contribute, feel free to do so."
elsif @node.status == 3 && (current_user && current_user.id == @node.author.id) && !flash[:first_time_post]
flash[:warning] = "This is a Draft note. Kindly complete it and publish it using 'Publish Draft' button."
elsif @node.status != 1 && !(current_user && (current_user.role == 'admin' || current_user.role == 'moderator'))
# if it's spam or a draft
# no notification; don't let people easily fish for existing draft titles; we should try to 404 it
4 changes: 2 additions & 2 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -101,9 +101,9 @@ def activity
notes = notes.where('nid != (?)', blog.nid) if blog

if current_user && (current_user.role == 'moderator' || current_user.role == 'admin')
notes = notes.where('(node.status = 1 OR node.status = 4)')
notes = notes.where('(node.status = 1 OR node.status = 4 OR node.status = 3)')
elsif current_user
notes = notes.where('(node.status = 1 OR (node.status = 4 AND node.uid = ?))', current_user.uid)
notes = notes.where('(node.status = 1 OR ((node.status = 3 OR node.status = 4) AND node.uid = ?))', current_user.uid)
else
notes = notes.where('node.status = 1')
end
10 changes: 7 additions & 3 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
@@ -51,7 +51,11 @@ def show
@node = Node.find params[:id]
end

if @node.status == 3 && (current_user.nil? || @node.author != current_user)
if @node.status == 3 && current_user.nil?
flash[:warning] = "You need to login to view the page"
redirect_to '/login'
return
elsif @node.status == 3 && @node.author.user != current_user && !current_user.can_moderate?
flash[:notice] = "Only author can access the draft note"
redirect_to '/'
return
@@ -243,7 +247,7 @@ def update
def delete
@node = Node.find(params[:id])
if current_user && (current_user.uid == @node.uid || current_user.can_moderate?)
if @node.authors.uniq.length == 1
if @node.authors.uniq.length == 1
@node.destroy
respond_with do |format|
format.html do
@@ -374,4 +378,4 @@ def update_title
node.update(title: params[:title])
redirect_to node.path + "#comments"
end
end
end
4 changes: 2 additions & 2 deletions test/functional/notes_controller_test.rb
Original file line number Diff line number Diff line change
@@ -663,8 +663,8 @@ def test_get_rss_feed
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]
assert_redirected_to '/login'
assert_equal "You need to login to view the page", flash[:warning]
end

test 'draft should not be shown when user is not author' do