parent
59742b9ddb
commit
54505340eb
|
@ -96,10 +96,11 @@ class CoursesController < ApplicationController
|
|||
@trackers = Tracker.sorted.all
|
||||
|
||||
if User.current.user_extensions.identity == 0
|
||||
if @course.save
|
||||
if @course.save
|
||||
unless User.current.admin?
|
||||
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])
|
||||
m.project_id = -1
|
||||
course = CourseInfos.new(: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'
|
||||
|
@ -128,7 +129,7 @@ class CoursesController < ApplicationController
|
|||
format.api { render_validation_errors(@course) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -367,9 +368,6 @@ class CoursesController < ApplicationController
|
|||
:with_subprojects => false,
|
||||
:author => @author)
|
||||
@activity.scope_select {|t| !has["show_#{t}"].nil?}
|
||||
# logger.debug "=========================================#{@activity.scope}"
|
||||
# @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty?
|
||||
#Added by young
|
||||
events = @activity.events(@date_from, @date_to)
|
||||
|
||||
@offset, @limit = api_offset_and_limit({:limit => 10})
|
||||
|
@ -377,7 +375,7 @@ class CoursesController < ApplicationController
|
|||
@events_pages = Paginator.new @events_count, @limit, params['page']
|
||||
@offset ||= @events_pages.offset
|
||||
events = events.slice(@offset,@limit)
|
||||
#Ended by young
|
||||
|
||||
@events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)}
|
||||
# documents
|
||||
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
|
||||
|
|
|
@ -16,6 +16,7 @@ class Course < ActiveRecord::Base
|
|||
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 :principals, :through => :member_principals, :source => :principal
|
||||
has_many :users, :through => :members
|
||||
has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy
|
||||
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
|
||||
|
@ -23,6 +24,7 @@ class Course < ActiveRecord::Base
|
|||
has_many :student, :through => :students_for_courses, :source => :user
|
||||
has_many :course_infos, :class_name => 'CourseInfos',:dependent => :destroy
|
||||
has_many :enabled_modules, :dependent => :delete_all
|
||||
has_many :boards, :dependent => :destroy, :order => "position ASC"
|
||||
|
||||
acts_as_taggable
|
||||
#acts_as_nested_set :order => 'name', :dependent => :destroy
|
||||
|
@ -31,6 +33,10 @@ class Course < ActiveRecord::Base
|
|||
|
||||
validates_presence_of :password, :term
|
||||
validates_format_of :class_period, :message => "class period can only digital!", :with =>/^[1-9]\d*$/
|
||||
|
||||
after_save :create_board_sync
|
||||
before_destroy :delete_all_members
|
||||
|
||||
safe_attributes 'extra',
|
||||
'time',
|
||||
'name',
|
||||
|
@ -128,6 +134,25 @@ class Course < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def create_board_sync
|
||||
@board = self.boards.build
|
||||
self.name=" #{l(:label_borad_course) }"
|
||||
@board.name = self.name
|
||||
@board.description = self.name.to_s
|
||||
@board.project_id = -1
|
||||
if @board.save
|
||||
logger.debug "[Course Model] ===> #{@board.to_json}"
|
||||
else
|
||||
logger.error "[Course Model] ===> Auto create board when course saved, because #{@board.full_messages}"
|
||||
end
|
||||
end
|
||||
|
||||
def delete_all_members
|
||||
me, mr = Member.table_name, MemberRole.table_name
|
||||
connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.course_id = #{id})")
|
||||
Member.delete_all(['course_id = ?', id])
|
||||
end
|
||||
|
||||
def get_endup_time
|
||||
begin
|
||||
end_time = Time.parse(self.endup_time)
|
||||
|
|
|
@ -39,6 +39,10 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
:timestamp => "#{self.table_name}.updated_on",
|
||||
:find_options => {:include => :project }
|
||||
|
||||
acts_as_activity_provider :author_key => :user_id,
|
||||
:timestamp => "#{self.table_name}.updated_on",
|
||||
:find_options => {:include => :course }
|
||||
|
||||
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
|
||||
|
||||
validates :notes, presence: true
|
||||
|
|
|
@ -1129,17 +1129,13 @@ class Project < ActiveRecord::Base
|
|||
# 创建项目后在项目下同步创建一个讨论区
|
||||
def create_board_sync
|
||||
@board = self.boards.build
|
||||
if project_type == 1
|
||||
self.name=" #{l(:label_borad_course) }"
|
||||
else
|
||||
self.name =" #{l(:label_borad_project) }"
|
||||
end
|
||||
self.name=" #{l(:label_borad_course) }"
|
||||
@board.name = self.name
|
||||
@board.description = self.name.to_s
|
||||
if @board.save
|
||||
logger.debug "[Project Model] ===> #{@board.to_json}"
|
||||
logger.debug "[Course Model] ===> #{@board.to_json}"
|
||||
else
|
||||
logger.error "[Project Model] ===> Auto create board when project saved, because #{@board.full_messages}"
|
||||
logger.error "[Course Model] ===> Auto create board when Course saved, because #{@board.full_messages}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -634,6 +634,15 @@ class User < Principal
|
|||
@membership_by_project_id[project_id]
|
||||
end
|
||||
|
||||
def coursemembership(course)
|
||||
course_id = course.is_a?(Course) ? course.id : course
|
||||
|
||||
@membership_by_course_id ||= Hash.new {|h, course_id|
|
||||
h[course_id] = coursememberships.where(:course_id => course_id).first
|
||||
}
|
||||
@membership_by_course_id[course_id]
|
||||
end
|
||||
|
||||
# Return user's roles for project
|
||||
def roles_for_project(project)
|
||||
roles = []
|
||||
|
@ -662,7 +671,7 @@ class User < Principal
|
|||
return roles if course.nil? || course.archived?
|
||||
if logged?
|
||||
# Find course membership
|
||||
membership = membership(course)
|
||||
membership = coursemembership(course)
|
||||
if membership
|
||||
roles = membership.roles
|
||||
else
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
<table width="580px" border="0">
|
||||
<tr>
|
||||
<td colspan="2" valign="top">
|
||||
<%= test=e.course%>
|
||||
<strong> <%= h(e.course) if @course.nil? || (e.course != nil && @course.id != e.course.id) %></strong>
|
||||
<span class="font_lighter">
|
||||
<% if @canShowRealName %>
|
||||
|
|
|
@ -74,6 +74,9 @@ module Redmine
|
|||
scope = scope.scoped(:conditions => Project.allowed_to_condition(user, provider_options[:permission] || :view_project, options))
|
||||
elsif respond_to?(:visible)
|
||||
scope = scope.visible(user, options)
|
||||
elsif options[:course]
|
||||
ActiveSupport::Deprecation.warn "acts_as_activity_provider with implicit :permission option is deprecated. Add a visible scope to the #{self.name} model or use explicit :permission option."
|
||||
scope = scope.scoped(:conditions => Course.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym, options))
|
||||
else
|
||||
ActiveSupport::Deprecation.warn "acts_as_activity_provider with implicit :permission option is deprecated. Add a visible scope to the #{self.name} model or use explicit :permission option."
|
||||
scope = scope.scoped(:conditions => Project.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym, options))
|
||||
|
|
Loading…
Reference in New Issue