Skip to content

Commit

Permalink
Draft display on Dashboard (#2666)
Browse files Browse the repository at this point in the history
* draft display on dashboard

* moderator file view permitted

* checking

* fix

* test fix
  • Loading branch information
grvsachdeva authored and jywarren committed May 17, 2018
1 parent a7e94fd commit 8617ad2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/home_controller.rb
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions app/controllers/notes_controller.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -374,4 +378,4 @@ def update_title
node.update(title: params[:title])
redirect_to URI.parse(node.path).path + "#comments"
end
end
end
4 changes: 2 additions & 2 deletions test/functional/notes_controller_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 8617ad2

Please sign in to comment.