课程成员迁移

This commit is contained in:
nwb 2014-06-04 09:19:01 +08:00
parent cd10dd5433
commit d87b52bedd
8 changed files with 54 additions and 10 deletions

View File

@ -81,7 +81,7 @@ class Course < ActiveRecord::Base
perm = Redmine::AccessControl.permission(permission)
base_statement = (perm && perm.read? ? "#{Course.table_name}.status <> #{Course::STATUS_ARCHIVED}" : "#{Course.table_name}.status = #{Course::STATUS_ACTIVE}")
if perm && perm.course_module
base_statement << " AND #{Course.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.project_module}')"
base_statement << " AND #{Course.table_name}.id IN (SELECT em.course_id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.course_module}')"
end
if options[:course]
course_statement = "#{Course.table_name}.id = #{options[:course].id}"

View File

@ -276,6 +276,7 @@ class User < Principal
def reload(*args)
@name = nil
@projects_by_role = nil
@courses_by_role = nil
@membership_by_project_id = nil
base_reload(*args)
end
@ -634,6 +635,25 @@ class User < Principal
@projects_by_role
end
# 课程的角色权限
def courses_by_role
return @courses_by_role if @courses_by_role
@courses_by_role = Hash.new([])
memberships.each do |membership|
if membership.course
membership.roles.each do |role|
@courses_by_role[role] = [] unless @courses_by_role.key?(role)
@courses_by_role[role] << membership.course
end
end
end
@courses_by_role.each do |role, courses|
courses.uniq!
end
@courses_by_role
end
# Returns true if user is arg or belongs to arg
def is_or_belongs_to?(arg)
if arg.is_a?(User)

View File

@ -6,6 +6,7 @@ class AddBoardsTypeToBoards < ActiveRecord::Migration
project = Project.find_by_id(board.project_id)
if project && project.project_type == 1
board.course_id = board.project_id
board.project_id = nil
board.save
end
end

View File

@ -5,7 +5,8 @@ class AddCourseidToEnabledModules < ActiveRecord::Migration
EnabledModule.all.each do |enablemodule|
project = Project.find_by_id(enablemodule.project_id)
if project && project.project_type == 1
enablemodule.course_id = board.project_id
enablemodule.course_id = enablemodule.project_id
enablemodule.project_id = nil
enablemodule.save
end
end

View File

@ -0,0 +1,15 @@
class AddCourseidToToMembers < ActiveRecord::Migration
def change
add_column :members, :course_id, :int
# 课程成员数据迁移
Member.all.each do |member|
project = Project.find_by_id(member.project_id)
if project && project.project_type == 1
member.course_id = member.project_id
member.project_id = nil
member.save
end
end
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140603033360) do
ActiveRecord::Schema.define(:version => 20140603081801) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -315,6 +315,7 @@ ActiveRecord::Schema.define(:version => 20140603033360) do
create_table "enabled_modules", :force => true do |t|
t.integer "project_id"
t.string "name", :null => false
t.integer "course_id"
end
add_index "enabled_modules", ["project_id"], :name => "enabled_modules_project_id"

View File

@ -98,6 +98,12 @@ Redmine::AccessControl.map do |map|
map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member
map.permission :view_journals_for_messages, {:gantts => [:show, :update]}, :read => true
#课程权限模块
map.course_module :course do
map.permission :view_course, {:courses => [:show], :activities => [:index]}, :public => true, :read => true
map.permission :view_courses,{:courses => [:course]},:read => true
end
map.project_module :issue_tracking do |map|
# Issue categories
map.permission :manage_categories, {:projects => :settings, :issue_categories => [:index, :show, :new, :create, :edit, :update, :destroy]}, :require => :member
@ -178,12 +184,6 @@ Redmine::AccessControl.map do |map|
map.permission :manage_related_issues, {:repositories => [:add_related_issue, :remove_related_issue]}
end
#课程权限模块
map.project_module :course do
map.permission :view_course, {:courses => [:show], :activities => [:index]}, :public => true, :read => true
map.permission :view_courses,{:courses => [:course]},:read => true
end
#作业模块权限
map.project_module :bids do |map|
map.permission :view_homework_attaches, {:bids => [:show, :show_project, :revision]}, :read => true

View File

@ -76,6 +76,7 @@ module Redmine
class Mapper
def initialize
@project_module = nil
@course_module = nil
end
def permission(name, hash, options={})
@ -90,13 +91,18 @@ module Redmine
@project_module = nil
end
def course_module(name, options={})
@course_module = name
yield self
@course_module = nil
end
def mapped_permissions
@permissions
end
end
class Permission
attr_reader :name, :actions, :project_module
attr_reader :name, :actions, :project_module ,:course_module
def initialize(name, hash, options)
@name = name