Skip to content

Commit

Permalink
created drafts page (publiclab#9893)
Browse files Browse the repository at this point in the history
  • Loading branch information
TildaDares authored and billymoroney1 committed Dec 28, 2021
1 parent 9c7100c commit 0ae72e0
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 3 deletions.
11 changes: 11 additions & 0 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,17 @@ def publish_draft
end
end

def drafts
@user = User.find_by(name: params[:id])
if current_user&.can_moderate? || current_user == @user
@pagy, @drafts = pagy(@user.drafts, items: 24)
render template: 'notes/drafts'
else
flash[:warning] = "This page is only visible to the author and moderators."
redirect_to '/'
end
end

private

def set_node
Expand Down
12 changes: 10 additions & 2 deletions app/views/notes/_nav_tabs.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="node-types" style="margin-bottom:8px;">
<div class="node-types mr-3" style="margin-bottom:8px;">
<ul class="nav nav-tabs" aria-labelledby="dropdownMenuButton">

<li class="nav-item">
Expand Down Expand Up @@ -27,5 +27,13 @@
<span class="d-lg-inline"><%= translation('notes.index.comments') %></span>
</a>
</li>

<% if current_user&.can_moderate? || current_user == @user %>
<li class="nav-item" style="width: 155px;">
<a class="nav-link" href="/drafts/author/<%= @user.name %>">
<i class="fa fa-pencil"></i> <span class="d-lg-inline"><%= translation('notes.index.drafts') %></span>
</a>
</li>
<% end %>
</ul>
</div>
</div>
18 changes: 18 additions & 0 deletions app/views/notes/drafts.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div class="col-lg-9">
<h3 class="mb-4">Your Drafts (<%= @drafts.count %>)</h3>
<div id="notes">
<div class="row">
<% @drafts.each_with_index do |node,i| %>
<div class="<% if @widget %>col-4 <% end %><%= node.tagnames_as_classes %> col-lg-4 col-md-6 clearfix node note node-nid-<%= node.id %> note-nid-<%= node.id %>">
<%= render partial: 'notes/card', locals: { node: node, i: i, tagname: false } %>
</div>
<% unless @widget %><hr class="d-md-none" /><% end %>
<% end %>
</div>
</div>
<% if @pagy %>
<%== pagy_bootstrap_nav @pagy %>
<% else %>
<%= will_paginate notes, renderer: WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated || (unpaginated ||= false) %>
<% end %>
</div>
2 changes: 1 addition & 1 deletion app/views/users/profile.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
<li><h5><a href = "/tag/question:*/author/<%= params[:id] %>"><%= pluralize(Node.questions.where(status: 1, uid: @profile_user.id).length, 'question', plural:'questions') %></a></h5></li>
<li><h5><a href = "/profile/comments/<%= params[:id] %>"><%= pluralize(Comment.where(uid: @profile_user.id).count, 'comment', plural: 'comments') %></a></h5></li>
<% if current_user&.can_moderate? || @profile_user == current_user %>
<li><h5><a href='#'><%= pluralize(@profile_user.drafts.size, 'draft', plural: 'drafts' )%></a></h5></li>
<li><h5><a href='/drafts/author/<%= @profile_user.name %>'><%= pluralize(@profile_user.drafts.size, 'draft', plural: 'drafts' )%></a></h5></li>
<% end %>
<li><h5><a href = "/tag/activity:*/author/<%= params[:id] %>"><%= pluralize(@count_activities_posted, 'activity posted', plural:'activities posted') %> </a></h5></li>
<li><h5><a href = "/tag/replication:*/author/<%= params[:id] %>"><%= pluralize(@count_activities_attempted, 'activity attempted', plural:'activities attempted')%></a> </h5></li>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ en:
research_notes: "Research Notes"
questions: "Questions"
comments: "Comments"
drafts: "Drafts"
all_notes: "All Notes"
_notes:
moderate_first_time_post: "Moderate first-time post:"
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
get 'notes/show/:id' => 'notes#show'
get 'notes/:author/:date/:id' => 'notes#show'
get 'notes/feeds' => 'subscription#notes'
get 'drafts/author/:id' => 'notes#drafts'

# :id will be the node's id (like has no id)
get 'likes' => 'like#index'
Expand Down
22 changes: 22 additions & 0 deletions test/functional/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1069,4 +1069,26 @@ def test_get_rss_feed
}
end
end

test 'moderators can view drafts page' do
user = users(:moderator)
UserSession.create(user)
get :drafts, params: { id: users(:newcomer).username }
assert_response :success
end

test 'draft author can view drafts page' do
user = users(:jeff)
UserSession.create(user)
get :drafts, params: { id: user.username }
assert_response :success
end

test 'drafts page is not shown when user is not a draft author or moderator' do
user = users(:newcomer)
UserSession.create(user)
get :drafts, params: { id: users(:jeff).username }
assert_equal "This page is only visible to the author and moderators.", flash[:warning]
assert_response :redirect
end
end

0 comments on commit 0ae72e0

Please sign in to comment.