Merge branch 'dev_hjq' of http://repository.trustie.net/xianbo/trustie2 into dev_hjq
This commit is contained in:
commit
dd401aca1a
|
@ -97,8 +97,8 @@ class UsersController < ApplicationController
|
|||
end
|
||||
|
||||
# 用户消息
|
||||
# 说明: homework 发布作业;message:讨论区; news:新闻; poll:问卷;works_reviewers:作品评阅
|
||||
# issue:问题;
|
||||
# 说明: homework 发布作业;message:讨论区; news:新闻; poll:问卷;works_reviewers:作品评阅;works_reply:作品回复
|
||||
# issue:问题;journal:缺陷状态更新; forum:公共贴吧
|
||||
def user_messages
|
||||
unless User.current.logged?
|
||||
render_403
|
||||
|
@ -114,6 +114,7 @@ class UsersController < ApplicationController
|
|||
when nil
|
||||
@user_course_messages = @user.course_messages.reverse
|
||||
@user_forge_messages = @user.forge_messages.reverse
|
||||
@user_forum_messages = @user.forum_messages.reverse
|
||||
when 'homework'
|
||||
@user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "HomeworkCommon", @user).order("created_at desc")
|
||||
@user_forge_messages = nil
|
||||
|
@ -134,9 +135,11 @@ class UsersController < ApplicationController
|
|||
when 'issue'
|
||||
@user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "Issue", @user).order("created_at desc")
|
||||
@user_course_messages = nil
|
||||
when 'journal'
|
||||
@user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "Journal", @user).order("created_at desc")
|
||||
when 'journal' # 缺陷状态更新、留言
|
||||
@user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "Forum", @user).order("created_at desc")
|
||||
@user_course_messages = nil
|
||||
when 'forum'
|
||||
@user_forum_messages = ForumMessage.where("memo_message_type =? and user_id =?", "Forum", @user).order("created_at desc")
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html{render :layout=>'base_users_new'}
|
||||
|
|
|
@ -39,6 +39,7 @@ class Forum < ActiveRecord::Base
|
|||
logger.debug "send mail for forum add."
|
||||
Mailer.run.forum_add(self) if Setting.notified_events.include?('forum_add')
|
||||
end
|
||||
|
||||
# Updates topic_count, memo_count and last_memo_id attributes for +board_id+
|
||||
def self.reset_counters!(forum_id)
|
||||
forum_id = forum_id.to_i
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
class ForumMessage < ActiveRecord::Base
|
||||
attr_accessible :forum_id, :memo_message_id, :memo_message_type, :user_id, :viewed
|
||||
|
||||
belongs_to :memo
|
||||
belongs_to :user
|
||||
|
||||
validates :user_id,presence: true
|
||||
validates :forum_id,presence: true
|
||||
validates :memo_message_id,presence: true
|
||||
validates :memo_message_type, presence: true
|
||||
end
|
|
@ -16,6 +16,8 @@ class Memo < ActiveRecord::Base
|
|||
acts_as_attachable
|
||||
has_many :user_score_details, :class_name => 'UserScoreDetails',:as => :score_changeable_obj
|
||||
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
|
||||
# 消息
|
||||
has_many :forum_messages, dependent: :destroy
|
||||
belongs_to :last_reply, :class_name => 'Memo', :foreign_key => 'last_reply_id'
|
||||
# acts_as_searchable :column => ['subject', 'content'],
|
||||
# #:include => { :forum => :p}
|
||||
|
@ -44,7 +46,7 @@ class Memo < ActiveRecord::Base
|
|||
"parent_id",
|
||||
"replies_count"
|
||||
|
||||
after_create :add_author_as_watcher, :reset_counters!, :send_mail
|
||||
after_create :add_author_as_watcher, :reset_counters!, :send_mail, :send_message
|
||||
# after_update :update_memos_forum
|
||||
after_destroy :reset_counters!,:delete_kindeditor_assets#,:down_user_score -- 公共区发帖暂不计入得分
|
||||
# after_create :send_notification
|
||||
|
@ -59,6 +61,32 @@ class Memo < ActiveRecord::Base
|
|||
Mailer.run.forum_message_added(self) if Setting.notified_events.include?('forum_message_added')
|
||||
end
|
||||
|
||||
# 公共贴吧消息记录
|
||||
# 原则:贴吧创始人;发帖人,wanglingchun(特殊用户)
|
||||
def send_message
|
||||
receivers = []
|
||||
u = User.find(6)
|
||||
receivers << u
|
||||
# 主贴
|
||||
if self.parent_id.nil?
|
||||
if self.author_id != self.forum.creator_id # 发帖人不是吧主
|
||||
receivers << self.forum.creator
|
||||
end
|
||||
else # 回帖
|
||||
# 添加吧主
|
||||
if self.author_id != self.forum.creator_id
|
||||
receivers << self.forum.creator
|
||||
end
|
||||
# 添加发帖人
|
||||
if self.author_id != self.parent.author_id
|
||||
receivers << self.parent.author
|
||||
end
|
||||
end
|
||||
receivers.each do |r|
|
||||
self.forum_messages << ForumMessage.new(:user_id => r.id, :forum_id => self.forum_id, :memo_message_id => self.id, :memo_message_type => "Forum", :viewed => false)
|
||||
end
|
||||
end
|
||||
|
||||
def cannot_reply_to_locked_topic
|
||||
errors.add :base, l(:label_memo_locked) if root.locked? && self != root
|
||||
end
|
||||
|
|
|
@ -127,10 +127,10 @@ class User < Principal
|
|||
has_many :messages, :foreign_key => 'author_id'
|
||||
has_one :user_score, :dependent => :destroy
|
||||
has_many :documents # 项目中关联的文档再次与人关联
|
||||
# 关联虚拟表
|
||||
# 关联消息表
|
||||
has_many :forge_messages
|
||||
has_many :course_messages
|
||||
# end
|
||||
has_many :forum_messages
|
||||
|
||||
# 虚拟转换
|
||||
has_many :new_jours, :as => :jour, :class_name => 'JournalsForMessage', :conditions => "status=1"
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
class CreateForumMessages < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :forum_messages do |t|
|
||||
t.integer :user_id
|
||||
t.integer :forum_id
|
||||
t.integer :memo_message_id
|
||||
t.string :memo_message_type
|
||||
t.integer :viewed
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
50
db/schema.rb
50
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20150810064247) do
|
||||
ActiveRecord::Schema.define(:version => 20150818091800) do
|
||||
|
||||
create_table "activities", :force => true do |t|
|
||||
t.integer "act_id", :null => false
|
||||
|
@ -325,6 +325,15 @@ ActiveRecord::Schema.define(:version => 20150810064247) do
|
|||
t.datetime "updated_on", :null => false
|
||||
end
|
||||
|
||||
create_table "course_activities", :force => true do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "course_id"
|
||||
t.integer "course_act_id"
|
||||
t.string "course_act_type"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "course_attachments", :force => true do |t|
|
||||
t.string "filename"
|
||||
t.string "disk_filename"
|
||||
|
@ -357,6 +366,16 @@ ActiveRecord::Schema.define(:version => 20150810064247) do
|
|||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "course_messages", :force => true do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "course_id"
|
||||
t.integer "course_message_id"
|
||||
t.string "course_message_type"
|
||||
t.integer "viewed"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "course_statuses", :force => true do |t|
|
||||
t.integer "changesets_count"
|
||||
t.integer "watchers_count"
|
||||
|
@ -455,6 +474,13 @@ ActiveRecord::Schema.define(:version => 20150810064247) do
|
|||
|
||||
add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
|
||||
|
||||
create_table "discuss_demos", :force => true do |t|
|
||||
t.string "title"
|
||||
t.text "body"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "documents", :force => true do |t|
|
||||
t.integer "project_id", :default => 0, :null => false
|
||||
t.integer "category_id", :default => 0, :null => false
|
||||
|
@ -536,6 +562,26 @@ ActiveRecord::Schema.define(:version => 20150810064247) do
|
|||
|
||||
add_index "forge_activities", ["forge_act_id"], :name => "index_forge_activities_on_forge_act_id"
|
||||
|
||||
create_table "forge_messages", :force => true do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "project_id"
|
||||
t.integer "forge_message_id"
|
||||
t.string "forge_message_type"
|
||||
t.integer "viewed"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "forum_messages", :force => true do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "forum_id"
|
||||
t.integer "memo_message_id"
|
||||
t.string "memo_message_type"
|
||||
t.integer "viewed"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "forums", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
t.text "description"
|
||||
|
@ -857,7 +903,6 @@ ActiveRecord::Schema.define(:version => 20150810064247) do
|
|||
t.datetime "created_on"
|
||||
t.integer "comments_count", :default => 0, :null => false
|
||||
t.integer "course_id"
|
||||
t.datetime "updated_on"
|
||||
end
|
||||
|
||||
add_index "news", ["author_id"], :name => "index_news_on_author_id"
|
||||
|
@ -1461,6 +1506,7 @@ ActiveRecord::Schema.define(:version => 20150810064247) do
|
|||
t.string "identity_url"
|
||||
t.string "mail_notification", :default => "", :null => false
|
||||
t.string "salt", :limit => 64
|
||||
t.integer "gid"
|
||||
end
|
||||
|
||||
add_index "users", ["auth_source_id"], :name => "index_users_on_auth_source_id"
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
FactoryGirl.define do
|
||||
factory :forum_message do
|
||||
user_id 1
|
||||
forum_id 1
|
||||
memo_message_id 1
|
||||
memo_message_type "MyString"
|
||||
viewed 1
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ForumMessage, :type => :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue