diff --git a/app/models/course.rb b/app/models/course.rb index 46599dbfc..a583990c1 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -50,6 +50,8 @@ class Course < ActiveRecord::Base validates_format_of :name,:with =>/^[^ ]+[a-zA-Z0-9_\u4e00-\u9fa5\s\S]+$/ validates_length_of :description, :maximum => 10000 before_save :self_validate + # 公开课程变成私有课程,所有资源都变成私有 + after_update :update_files_public after_create :create_board_sync, :act_as_course_activity, :act_as_course_message before_destroy :delete_all_members @@ -213,6 +215,14 @@ class Course < ActiveRecord::Base end + def update_files_public + unless self.is_public? + self.attachments.each do |a| + a.update_attributes(:is_public => false) + end + end + end + # 创建课程讨论区 def create_board_sync @board = self.boards.build