添加课程管理员表,并从项目管理员表中迁移原有数据

This commit is contained in:
nwb 2014-06-05 11:01:46 +08:00
parent 529cf4f4f8
commit de201ae8f6
7 changed files with 135 additions and 1 deletions

View File

@ -331,7 +331,80 @@ class CoursesController < ApplicationController
end end
end end
def show
# try to redirect to the requested menu item
if params[:jump] && redirect_to_course_menu_item(@course, params[:jump])
return
end
@users_by_role = @course.users_by_role
if(User.find_by_id(CourseInfo.find_by_course_id(@course.id).try(:user_id)))
@user = User.find_by_id(CourseInfo.find_by_course_id(@course.id).user_id)
end
cond = @course.course_condition(Setting.display_subcourses_issues?)
@open_issues_by_tracker = Issue.visible.open.where(cond).count(:group => :tracker)
@total_issues_by_tracker = Issue.visible.where(cond).count(:group => :tracker)
if User.current.allowed_to?(:view_time_entries, @course)
@total_hours = TimeEntry.visible.sum(:hours, :include => :course, :conditions => cond).to_f
end
@key = User.current.rss_key
#新增内容
@days = Setting.activity_days_default.to_i
if params[:from]
begin; @date_to = params[:from].to_date + 1; rescue; end
end
has = {
"show_files" => true,
"show_messages" => true,
"show_bids" => true,
"show_contests" => true,
"show_journals_for_messages" => true
}
@date_to ||= Date.today + 1
@date_from = @date_to - @days-1.years
@with_subcourses = params[:with_subcourses].nil? ? Setting.display_subcourses_issues? : (params[:with_subcourses] == '1')
@author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
# 决定显示所用用户或单个用户活动
@activity = Redmine::Activity::Fetcher.new(User.current, :course => @course,
:with_subcourses => @with_subcourses,
: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})
@events_count = events.count
@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'
documents = @course.documents.includes(:attachments, :category).all
case @sort_by
when 'date'
@grouped = documents.group_by {|d| d.updated_on.to_date }
when 'title'
@grouped = documents.group_by {|d| d.title.first.upcase}
when 'author'
@grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
else
@grouped = documents.group_by(&:category)
end
@document = @course.documents.build
#
respond_to do |format|
format.html{render :layout => 'base_courses'}
format.api
end
end
private private

View File

@ -71,6 +71,16 @@ class Course < ActiveRecord::Base
allowed_to_condition(user, :view_course, options) allowed_to_condition(user, :view_course, options)
end end
# 返回用户组可以访问的课程
def users_by_role
members.includes(:user, :roles).all.inject({}) do |h, m|
m.roles.each do |r|
h[r] ||= []
h[r] << m.user
end
h
end
end
#自定义验证 #自定义验证
def validate def validate

View File

@ -0,0 +1,3 @@
class CourseInfos < ActiveRecord::Base
attr_accessible :typeId, :typeName
end

View File

@ -0,0 +1,25 @@
class CreateCourseInfos < ActiveRecord::Migration
def change
create_table :course_infos do |t|
t.integer :course_id
t.integer :user_id
t.timestamps
end
#迁移课程管理员数据
Project.all.each do |project|
if project.project_type == 1
course = Course.find_by_extra(project.identifier)
if course
projectinfos = ProjectInfo.find_all_by_project_id(project.id)
projectinfos.each do |projinfo|
courseinfo = CourseInfos.new
courseinfo.course_id = course.id
courseinfo.user_id = projinfo.user_id
courseinfo.save
end
end
end
end
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140604071624) do ActiveRecord::Schema.define(:version => 20140605025300) do
create_table "activities", :force => true do |t| create_table "activities", :force => true do |t|
t.integer "act_id", :null => false t.integer "act_id", :null => false
@ -218,6 +218,13 @@ ActiveRecord::Schema.define(:version => 20140604071624) do
t.datetime "updated_on", :null => false t.datetime "updated_on", :null => false
end end
create_table "course_infos", :force => true do |t|
t.integer "course_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "course_statuses", :force => true do |t| create_table "course_statuses", :force => true do |t|
t.integer "changesets_count" t.integer "changesets_count"
t.integer "watchers_count" t.integer "watchers_count"

9
test/fixtures/course_infos.yml vendored Normal file
View File

@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
typeId: 1
typeName: MyString
two:
typeId: 1
typeName: MyString

View File

@ -0,0 +1,7 @@
require 'test_helper'
class CourseInfosTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end