diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 9f823ab9..bff99f35 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -6,7 +6,7 @@ class CoursesController < ApplicationController menu_item l(:label_sort_by_influence), :only => :index before_filter :authorize, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen, :view_homework_attaches, :course] - before_filter :authorize_global, :only => [:view_homework_attaches] #:new,:create] + #before_filter :authorize_global, :only => [:view_homework_attaches, :new,:create] before_filter :require_admin, :only => [:copy, :archive, :unarchive, :destroy, :calendar] before_filter :require_login, :only => [:join, :unjoin] @@ -66,6 +66,13 @@ class CoursesController < ApplicationController return courses end + def settings + @issue_custom_fields = IssueCustomField.sorted.all + @issue_category ||= IssueCategory.new + @member ||= @courses.members.new + @trackers = Tracker.sorted.all + end + def create if User.current.user_extensions.identity @course = Course.new @@ -80,6 +87,7 @@ class CoursesController < ApplicationController @course.setup_time = params[:setup_time] @course.endup_time = params[:endup_time] @course.class_period = params[:class_period] + @course.description = params[:description] end @issue_custom_fields = IssueCustomField.sorted.all @@ -91,7 +99,7 @@ class CoursesController < ApplicationController r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first m = Member.new(:user => User.current, :roles => [r]) #course = ProjectInfo.new(:user_id => User.current.id, :course_id => @course.id) - user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id) + #user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id) if params[:course][:is_public] == '1' course_status = CourseStatus.create(:course_id => @course.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :course_type => @course_tag) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6452bcc8..c508234a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -200,19 +200,19 @@ class UsersController < ApplicationController end end - membership = @user.memberships.all(:conditions => Project.visible_condition(User.current)) + membership = @user.coursememberships.all(:conditions => Course.visible_condition(User.current)) membership.sort! {|older, newer| newer.created_on <=> older.created_on } @memberships = [] membership.collect { |e| - @memberships.push(e) if(e.project.project_type == 1) + @memberships.push(e) } ## 判断课程是否过期 [需封装] @memberships_doing = [] @memberships_done = [] now_time = Time.now.year @memberships.map { |e| - end_time = e.project.course_extra.get_time.year - isDone = course_endTime_timeout?(e.project) + end_time = e.course.get_time.year + isDone = course_endTime_timeout?(e.course) if isDone @memberships_done.push e else diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 70029a55..8f3e4eb7 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -182,7 +182,7 @@ module CoursesHelper end # 截至到2014-03-17 这个是最终的判断课程是否过期的方法 def course_endTime_timeout? project - end_time_str = Course.find_by_extra(project.try(:identifier)).try(:endup_time) + end_time_str = Course.find_by_extra(project.try(:extra)).try(:endup_time) begin cTime = Time.parse(end_time_str.to_s) rescue TypeError,ArgumentError diff --git a/app/models/course.rb b/app/models/course.rb index d0273fa7..9b2e0d84 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -10,6 +10,14 @@ class Course < ActiveRecord::Base belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表 belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school,该方法通过school_id来调用School表 has_many :bid + + has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}" + has_many :memberships, :class_name => 'Member' + has_many :member_principals, :class_name => 'Member', + :include => :principal, + :conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})" + has_many :users, :through => :members + validates_presence_of :password, :term validates_format_of :class_period, :message => "class period can only digital!", :with =>/^[1-9]\d*$/ safe_attributes 'extra', @@ -21,7 +29,8 @@ class Course < ActiveRecord::Base 'tea_id', 'password', 'term', - 'password' + 'password', + 'description' acts_as_customizable @@ -49,8 +58,11 @@ class Course < ActiveRecord::Base errors[:extra].blank? && !(new_record? || extra.blank?) end + def archived? + self.status == STATUS_ARCHIVED + end - def self.visible_condition(user, options={}) + def self.visible_condition(user, options={}) allowed_to_condition(user, :view_course, options) end diff --git a/app/models/member_role.rb b/app/models/member_role.rb index 29ad6563..67122a63 100644 --- a/app/models/member_role.rb +++ b/app/models/member_role.rb @@ -54,14 +54,16 @@ class MemberRole < ActiveRecord::Base end def add_role_to_subprojects - member.project.children.each do |subproject| - if subproject.inherit_members? - child_member = Member.find_or_new(subproject.id, member.user_id) - child_member.member_roles << MemberRole.new(:role => role, :inherited_from => id) - child_member.save! + if member.project + member.project.children.each do |subproject| + if subproject.inherit_members? + child_member = Member.find_or_new(subproject.id, member.user_id) + child_member.member_roles << MemberRole.new(:role => role, :inherited_from => id) + child_member.save! + end end end - end + end def remove_inherited_roles MemberRole.where(:inherited_from => id).all.group_by(&:member).each do |member, member_roles| diff --git a/app/models/principal.rb b/app/models/principal.rb index 15cebdf5..6681855b 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -26,6 +26,7 @@ class Principal < ActiveRecord::Base has_many :members, :foreign_key => 'user_id', :dependent => :destroy has_many :memberships, :class_name => 'Member', :foreign_key => 'user_id', :include => [ :project, :roles ], :conditions => "#{Project.table_name}.status<>#{Project::STATUS_ARCHIVED}", :order => "#{Project.table_name}.name" + has_many :coursememberships, :class_name => 'Member', :foreign_key => 'user_id', :include => [ :course, :roles ], :conditions => "#{Course.table_name}.status<>#{Course::STATUS_ARCHIVED}", :order => "#{Course.table_name}.name" has_many :projects, :through => :memberships has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify diff --git a/app/views/courses/_course_form.html.erb b/app/views/courses/_course_form.html.erb index 66054a93..4f2f5a79 100644 --- a/app/views/courses/_course_form.html.erb +++ b/app/views/courses/_course_form.html.erb @@ -292,14 +292,12 @@ -
<%= l(:text_command) %> <% end %> -diff --git a/app/views/users/_course_form.html.erb b/app/views/users/_course_form.html.erb index 13ab819d..6de99f7d 100644 --- a/app/views/users/_course_form.html.erb +++ b/app/views/users/_course_form.html.erb @@ -1,44 +1,44 @@
<%= image_tag(url_to_avatar(membership.project), :class => 'avatar') %> | +<%= image_tag(url_to_avatar(membership.course), :class => 'avatar') %> |
|