修改新闻model、路由、index方法
This commit is contained in:
parent
3165d97417
commit
d6280befca
|
@ -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']
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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|
|
||||
|
|
Loading…
Reference in New Issue