From b89218a1b374dd3049d28ad0ffbfec961d176b5a Mon Sep 17 00:00:00 2001
From: huang <huang.jingquan@163.com>
Date: Sun, 6 Sep 2015 16:50:03 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=88=97=E8=A1=A8=E6=B7=BB?=
 =?UTF-8?q?=E5=8A=A0=E6=9C=AA=E8=AF=BB=E6=B6=88=E6=81=AF=E7=BB=9F=E8=AE=A1?=
 =?UTF-8?q?=E5=92=8C=E2=80=9C=E5=85=A8=E9=83=A8=E8=AE=BE=E4=B8=BA=E5=B7=B2?=
 =?UTF-8?q?=E8=AF=BB=E2=80=9D=E5=8A=9F=E8=83=BD=20=E4=B8=AA=E4=BA=BA?=
 =?UTF-8?q?=E7=95=99=E8=A8=80=E6=B7=BB=E5=8A=A0=E7=99=BB=E5=BD=95=E9=AA=8C?=
 =?UTF-8?q?=E8=AF=81=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/controllers/users_controller.rb    | 30 +++++++++++++++-----------
 app/views/users/user_messages.html.erb |  6 +++++-
 2 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index e3480b238..d1eeda707 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -102,22 +102,22 @@ class UsersController < ApplicationController
   # issue:问题;journal:缺陷状态更新; forum:公共贴吧: user_feedback: 用户留言; new_reply:新闻回复(comment)
   def user_messages
     unless User.current.logged?
-      render_403
+      redirect_to signin_url
       return
     end
     # 当前用户查看消息,则设置消息为已读
-    #if params[:viewed] == "all"
-    #  course_querys = @user.course_messages
-    #  forge_querys = @user.forge_messages
-    #  user_querys = @user.user_feedback_messages
-    #  forum_querys = @user.memo_messages
-    #  if User.current.id == @user.id
-    #    course_querys.update_all(:viewed => true)
-    #    forge_querys.update_all(:viewed => true)
-    #    user_querys.update_all(:viewed => true)
-    #    forum_querys.update_all(:viewed => true)
-    #  end
-    #end
+    if params[:viewed] == "all"
+      course_querys = @user.course_messages
+      forge_querys = @user.forge_messages
+      user_querys = @user.user_feedback_messages
+      forum_querys = @user.memo_messages
+      if User.current.id == @user.id
+        course_querys.update_all(:viewed => true)
+        forge_querys.update_all(:viewed => true)
+        user_querys.update_all(:viewed => true)
+        forum_querys.update_all(:viewed => true)
+      end
+    end
     # @new_message_count = forge_querys.count + forum_querys.count + course_querys.count + user_querys.count
     case params[:type]
       when nil
@@ -540,6 +540,10 @@ class UsersController < ApplicationController
 
 # modified by fq
   def user_newfeedback
+    unless User.current.logged?
+      redirect_to signin_url
+      return
+    end
     # 更新用户留言消息状态
     @user.journals_for_messages.each do |jour_message|
       jour_message.user_feedback_messages.each do |userfeedback_message|
diff --git a/app/views/users/user_messages.html.erb b/app/views/users/user_messages.html.erb
index 1d288b4b8..c3c1a447b 100644
--- a/app/views/users/user_messages.html.erb
+++ b/app/views/users/user_messages.html.erb
@@ -29,7 +29,11 @@
   </div>
 <div class="resources mt10" id="users_setting">
 <div>
-
+<% if params[:type].nil? %>
+    <div class="newsReadSetting">
+      有&nbsp;<span class="c_red"><%= User.current.count_new_message %></span>&nbsp;条未读<a href="javascript:void(0);" class="ml15"><%= link_to "全部设为已读", user_message_path(User.current, :viewed => 'all') %></a>
+    </div>
+<% end %>
 <% if @message_alls.count >0 %>
     <%# 课程消息 %>
     <% unless @message_alls.nil? %>