diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index d340e3bb..e7c39387 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -64,7 +64,7 @@ class NewsController < ApplicationController format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") } end elsif @course - scope = @course ? @course.news.visible : News.visible + scope = @course ? @course.news.course_visible : News.course_visible @news_count = scope.count @news_pages = Paginator.new @news_count, @limit, params['page'] diff --git a/app/models/news.rb b/app/models/news.rb index 51bd7d81..53c1c309 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -18,6 +18,8 @@ class News < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :project + #added by nwb + belongs_to :course belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' has_many :comments, :as => :commented, :dependent => :delete_all, :order => "created_on" # fq @@ -33,9 +35,13 @@ class News < ActiveRecord::Base acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}} acts_as_activity_provider :find_options => {:include => [:project, :author]}, :author_key => :author_id + #added by nwb + #课程新闻独立于项目 + acts_as_activity_provider :type => 'course_news', + :find_options => {:include => [:project, :author]}, + :author_key => :author_id acts_as_watchable - after_create :add_author_as_watcher # fq after_create :act_as_activity @@ -45,6 +51,9 @@ class News < ActiveRecord::Base includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args)) } + scope :course_visible, lambda {|*args| + includes(:course).where(Course.allowed_to_condition(args.shift || User.current, :view_news, *args)) + } safe_attributes 'title', 'summary', 'description' def visible?(user=User.current) diff --git a/app/views/news/_course_news_html.erb b/app/views/news/_course_news.html.erb similarity index 100% rename from app/views/news/_course_news_html.erb rename to app/views/news/_course_news.html.erb diff --git a/app/views/news/_project_news_html.erb b/app/views/news/_project_news.html.erb similarity index 100% rename from app/views/news/_project_news_html.erb rename to app/views/news/_project_news.html.erb diff --git a/config/routes.rb b/config/routes.rb index 327822f8..3000af94 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -566,7 +566,7 @@ RedmineApp::Application.routes.draw do get 'appliedproject' end end - + resources :news, :except => [:show, :edit, :update, :destroy] end # end of resources :courses match 'courses/:id/feedback', :to => 'courses#feedback', :via => :get, :as => 'course_feedback' match '/courses/search', :controller => 'courses', :action => 'search', :via => [:get, :post] diff --git a/db/schema.rb b/db/schema.rb index 8430c487..6faf0a82 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140606028512) do +ActiveRecord::Schema.define(:version => 20140611161801) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -578,6 +578,7 @@ ActiveRecord::Schema.define(:version => 20140606028512) do t.integer "author_id", :default => 0, :null => false t.datetime "created_on" t.integer "comments_count", :default => 0, :null => false + t.integer "course_id" end add_index "news", ["author_id"], :name => "index_news_on_author_id" diff --git a/lib/redmine.rb b/lib/redmine.rb index 78088f08..24b9bce9 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -419,6 +419,7 @@ Redmine::Activity.map do |activity| # end #added by nwb #activity.register :course_journals_for_messages + activity.register :course_news, :class_name => 'News' end Redmine::Search.map do |search|