From ba8ac74208ae9c42f849273348ea60c16e02fef1 Mon Sep 17 00:00:00 2001 From: TildaDares Date: Tue, 22 Jun 2021 12:14:28 +0100 Subject: [PATCH] added drafts link to profile page --- app/models/user.rb | 6 ++++++ app/views/users/profile.html.erb | 3 +++ test/unit/user_test.rb | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index 50bc8252e6..8a8d804454 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -517,6 +517,12 @@ def self.recently_active_users(limit = 5, order = 'last_updated DESC') end end + def drafts + Node.where(uid: uid) + .where(status: 3, type: 'note') + .order('created DESC') + end + private def decrease_likes_banned diff --git a/app/views/users/profile.html.erb b/app/views/users/profile.html.erb index a05b9509cd..8a221110aa 100644 --- a/app/views/users/profile.html.erb +++ b/app/views/users/profile.html.erb @@ -265,6 +265,9 @@
  • <%= pluralize(@profile_user.revisions.count, 'wiki edit', plural: 'wiki edits') %>
  • <%= pluralize(Node.questions.where(status: 1, uid: @profile_user.id).length, 'question', plural:'questions') %>
  • <%= pluralize(Comment.where(uid: @profile_user.id).count, 'comment', plural: 'comments') %>
  • + <% if current_user&.can_moderate? || @profile_user == current_user %> +
  • <%= pluralize(@profile_user.drafts.size, 'draft', plural: 'drafts' )%>
  • + <% end %>
  • <%= pluralize(@count_activities_posted, 'activity posted', plural:'activities posted') %>
  • <%= pluralize(@count_activities_attempted, 'activity attempted', plural:'activities attempted')%>
  • <%= pluralize(Tag.find_nodes_by_type("with:#{@profile_user.username}").count, 'note co-authored', plural: 'notes co-authored')%>
  • diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 3ecfe9f525..ecb22b04ef 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -309,4 +309,9 @@ class UserTest < ActiveSupport::TestCase user = users(:bob) assert_equal user.subscriptions(:tag).size, 4 end + + test 'user drafts' do + user = users(:jeff) + assert_not user.drafts.empty? + end end