课程成员迁移
This commit is contained in:
parent
cd10dd5433
commit
d87b52bedd
|
@ -81,7 +81,7 @@ class Course < ActiveRecord::Base
|
||||||
perm = Redmine::AccessControl.permission(permission)
|
perm = Redmine::AccessControl.permission(permission)
|
||||||
base_statement = (perm && perm.read? ? "#{Course.table_name}.status <> #{Course::STATUS_ARCHIVED}" : "#{Course.table_name}.status = #{Course::STATUS_ACTIVE}")
|
base_statement = (perm && perm.read? ? "#{Course.table_name}.status <> #{Course::STATUS_ARCHIVED}" : "#{Course.table_name}.status = #{Course::STATUS_ACTIVE}")
|
||||||
if perm && perm.course_module
|
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
|
end
|
||||||
if options[:course]
|
if options[:course]
|
||||||
course_statement = "#{Course.table_name}.id = #{options[:course].id}"
|
course_statement = "#{Course.table_name}.id = #{options[:course].id}"
|
||||||
|
|
|
@ -276,6 +276,7 @@ class User < Principal
|
||||||
def reload(*args)
|
def reload(*args)
|
||||||
@name = nil
|
@name = nil
|
||||||
@projects_by_role = nil
|
@projects_by_role = nil
|
||||||
|
@courses_by_role = nil
|
||||||
@membership_by_project_id = nil
|
@membership_by_project_id = nil
|
||||||
base_reload(*args)
|
base_reload(*args)
|
||||||
end
|
end
|
||||||
|
@ -634,6 +635,25 @@ class User < Principal
|
||||||
@projects_by_role
|
@projects_by_role
|
||||||
end
|
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
|
# Returns true if user is arg or belongs to arg
|
||||||
def is_or_belongs_to?(arg)
|
def is_or_belongs_to?(arg)
|
||||||
if arg.is_a?(User)
|
if arg.is_a?(User)
|
||||||
|
|
|
@ -6,6 +6,7 @@ class AddBoardsTypeToBoards < ActiveRecord::Migration
|
||||||
project = Project.find_by_id(board.project_id)
|
project = Project.find_by_id(board.project_id)
|
||||||
if project && project.project_type == 1
|
if project && project.project_type == 1
|
||||||
board.course_id = board.project_id
|
board.course_id = board.project_id
|
||||||
|
board.project_id = nil
|
||||||
board.save
|
board.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,8 @@ class AddCourseidToEnabledModules < ActiveRecord::Migration
|
||||||
EnabledModule.all.each do |enablemodule|
|
EnabledModule.all.each do |enablemodule|
|
||||||
project = Project.find_by_id(enablemodule.project_id)
|
project = Project.find_by_id(enablemodule.project_id)
|
||||||
if project && project.project_type == 1
|
if project && project.project_type == 1
|
||||||
enablemodule.course_id = board.project_id
|
enablemodule.course_id = enablemodule.project_id
|
||||||
|
enablemodule.project_id = nil
|
||||||
enablemodule.save
|
enablemodule.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
|
@ -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 => 20140603033360) do
|
ActiveRecord::Schema.define(:version => 20140603081801) 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
|
||||||
|
@ -315,6 +315,7 @@ ActiveRecord::Schema.define(:version => 20140603033360) do
|
||||||
create_table "enabled_modules", :force => true do |t|
|
create_table "enabled_modules", :force => true do |t|
|
||||||
t.integer "project_id"
|
t.integer "project_id"
|
||||||
t.string "name", :null => false
|
t.string "name", :null => false
|
||||||
|
t.integer "course_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "enabled_modules", ["project_id"], :name => "enabled_modules_project_id"
|
add_index "enabled_modules", ["project_id"], :name => "enabled_modules_project_id"
|
||||||
|
|
|
@ -98,6 +98,12 @@ Redmine::AccessControl.map do |map|
|
||||||
map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member
|
map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member
|
||||||
map.permission :view_journals_for_messages, {:gantts => [:show, :update]}, :read => true
|
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|
|
map.project_module :issue_tracking do |map|
|
||||||
# Issue categories
|
# Issue categories
|
||||||
map.permission :manage_categories, {:projects => :settings, :issue_categories => [:index, :show, :new, :create, :edit, :update, :destroy]}, :require => :member
|
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]}
|
map.permission :manage_related_issues, {:repositories => [:add_related_issue, :remove_related_issue]}
|
||||||
end
|
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.project_module :bids do |map|
|
||||||
map.permission :view_homework_attaches, {:bids => [:show, :show_project, :revision]}, :read => true
|
map.permission :view_homework_attaches, {:bids => [:show, :show_project, :revision]}, :read => true
|
||||||
|
|
|
@ -76,6 +76,7 @@ module Redmine
|
||||||
class Mapper
|
class Mapper
|
||||||
def initialize
|
def initialize
|
||||||
@project_module = nil
|
@project_module = nil
|
||||||
|
@course_module = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def permission(name, hash, options={})
|
def permission(name, hash, options={})
|
||||||
|
@ -90,13 +91,18 @@ module Redmine
|
||||||
@project_module = nil
|
@project_module = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def course_module(name, options={})
|
||||||
|
@course_module = name
|
||||||
|
yield self
|
||||||
|
@course_module = nil
|
||||||
|
end
|
||||||
def mapped_permissions
|
def mapped_permissions
|
||||||
@permissions
|
@permissions
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Permission
|
class Permission
|
||||||
attr_reader :name, :actions, :project_module
|
attr_reader :name, :actions, :project_module ,:course_module
|
||||||
|
|
||||||
def initialize(name, hash, options)
|
def initialize(name, hash, options)
|
||||||
@name = name
|
@name = name
|
||||||
|
|
Loading…
Reference in New Issue