课程权限判断变更,从项目权限分离
This commit is contained in:
parent
8460344043
commit
cd10dd5433
|
@ -52,11 +52,40 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def handle_course courses,activities
|
||||
course_activity_count_array=activities.values()
|
||||
|
||||
course_array=[]
|
||||
i=0;
|
||||
courses.each do |course|
|
||||
course_array[i]=course
|
||||
i=i+1
|
||||
end
|
||||
|
||||
courses=desc_sort_course_by_avtivity(course_activity_count_array,course_array)
|
||||
|
||||
return courses
|
||||
end
|
||||
|
||||
def desc_sort_course_by_avtivity(activity_count,courses)
|
||||
return courses if activity_count.size<2
|
||||
(activity_count.size-2).downto(0) do |i|
|
||||
(0..i).each do |j|
|
||||
if activity_count[j]<activity_count[j+1]
|
||||
courses[j],courses[j+1]=courses[j+1],courses[j]
|
||||
activity_count[j],activity_count[j+1]=activity_count[j+1],activity_count[j]
|
||||
end
|
||||
end
|
||||
end
|
||||
return courses
|
||||
end
|
||||
|
||||
def index
|
||||
@course_type = params[:course_type]
|
||||
@school_id = params[:school_id]
|
||||
per_page_option = 10
|
||||
|
||||
|
||||
if @school_id == "0" or @school_id.nil?
|
||||
@courses_all = Course.active.visible.
|
||||
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id")
|
||||
|
@ -84,7 +113,7 @@ class CoursesController < ApplicationController
|
|||
|
||||
case params[:course_sort_type]
|
||||
when '0'
|
||||
@courses = @courses_all.order("created_on desc")
|
||||
@courses = @courses_all.order("created_at desc")
|
||||
@s_type = 0
|
||||
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||
|
||||
|
@ -122,7 +151,7 @@ class CoursesController < ApplicationController
|
|||
@courses = @courses[@course_pages.offset, @course_pages.per_page]
|
||||
else
|
||||
@s_type = 0
|
||||
@courses = @courses_all.order("created_on desc")
|
||||
@courses = @courses_all.order("created_at desc")
|
||||
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||
|
||||
#gcm
|
||||
|
@ -142,6 +171,7 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
def get_course_activity courses,activities
|
||||
@course_ids=activities.keys()
|
||||
|
||||
|
@ -160,11 +190,6 @@ class CoursesController < ApplicationController
|
|||
activities[board.course_id]+=board.messages.where("updated_on>?",date_from).count
|
||||
end
|
||||
|
||||
#time_entry_count
|
||||
TimeEntry.where(course_id: @course_ids).where("updated_on>?",date_from).each do |timeentry|
|
||||
activities[timeentry.course_id]+=1
|
||||
end
|
||||
|
||||
#feedbackc_count
|
||||
JournalsForMessage.where(jour_id: @course_ids, jour_type: Project).each do |jourformess|
|
||||
activities[jourformess.jour_id]+=1
|
||||
|
|
|
@ -126,29 +126,25 @@ module CoursesHelper
|
|||
content = ''.html_safe
|
||||
case state
|
||||
when 0
|
||||
content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:course_sort_type => '0'), :school_id => school_id, :class=>"selected"), :class=>"selected")
|
||||
content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:course_sort_type => '1', :school_id => school_id)))
|
||||
# content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:course_sort_type => '2')))
|
||||
content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:course_sort_type => '3', :school_id => school_id)))
|
||||
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0'), :school_id => school_id, :class=>"selected"), :class=>"selected")
|
||||
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id)))
|
||||
content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id)))
|
||||
|
||||
when 1
|
||||
content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:course_sort_type => '0', :school_id => school_id)))
|
||||
content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:course_sort_type => '1', :school_id => school_id), :class=>"selected"), :class=>"selected")
|
||||
# content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:course_sort_type => '2')))
|
||||
content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:course_sort_type => '3', :school_id => school_id)))
|
||||
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0', :school_id => school_id)))
|
||||
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id), :class=>"selected"), :class=>"selected")
|
||||
content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id)))
|
||||
|
||||
when 2
|
||||
content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:course_sort_type => '0', :school_id => school_id)))
|
||||
content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:course_sort_type => '1', :school_id => school_id)))
|
||||
# content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:course_sort_type => '2'), :class=>"selected"), :class=>"selected")
|
||||
content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:course_sort_type => '3', :school_id => school_id)))
|
||||
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0', :school_id => school_id)))
|
||||
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id)))
|
||||
content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id)))
|
||||
|
||||
#gcm
|
||||
when 3
|
||||
content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:course_sort_type => '0', :school_id => school_id)))
|
||||
content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:course_sort_type => '1', :school_id => school_id)))
|
||||
# content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:course_sort_type => '2')))
|
||||
content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:course_sort_type => '3', :school_id => school_id), :class=>"selected"), :class=>"selected")
|
||||
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0', :school_id => school_id)))
|
||||
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id)))
|
||||
content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id), :class=>"selected"), :class=>"selected")
|
||||
end
|
||||
#gcmend
|
||||
|
||||
|
|
|
@ -80,14 +80,13 @@ class Course < ActiveRecord::Base
|
|||
def self.allowed_to_condition(user, permission, options={})
|
||||
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.project_module
|
||||
# If the permission belongs to a project module, make sure the module is enabled
|
||||
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}')"
|
||||
end
|
||||
if options[:project]
|
||||
project_statement = "#{Course.table_name}.id = #{options[:project].id}"
|
||||
project_statement << " OR (#{Course.table_name}.lft > #{options[:project].lft} AND #{Course.table_name}.rgt < #{options[:project].rgt})" if options[:with_subprojects]
|
||||
base_statement = "(#{project_statement}) AND (#{base_statement})"
|
||||
if options[:course]
|
||||
course_statement = "#{Course.table_name}.id = #{options[:course].id}"
|
||||
course_statement << " OR (#{Course.table_name}.lft > #{options[:course].lft} AND #{Course.table_name}.rgt < #{options[:course].rgt})" if options[:with_subcourses]
|
||||
base_statement = "(#{course_statement}) AND (#{base_statement})"
|
||||
end
|
||||
|
||||
if user.admin?
|
||||
|
@ -101,9 +100,9 @@ class Course < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
if user.logged?
|
||||
user.projects_by_role.each do |role, projects|
|
||||
if role.allowed_to?(permission) && projects.any?
|
||||
statement_by_role[role] = "#{Course.table_name}.id IN (#{projects.collect(&:id).join(',')})"
|
||||
user.courses_by_role.each do |role, courses|
|
||||
if role.allowed_to?(permission) && courses.any?
|
||||
statement_by_role[role] = "#{Course.table_name}.id IN (#{courses.collect(&:id).join(',')})"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
class AddCourseidToEnabledModules < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :enabled_modules, :course_id, :int
|
||||
|
||||
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.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -180,7 +180,8 @@ Redmine::AccessControl.map do |map|
|
|||
|
||||
#课程权限模块
|
||||
map.project_module :course do
|
||||
map.permission :view_courses,{:projects => [:course]},:read => true
|
||||
map.permission :view_course, {:courses => [:show], :activities => [:index]}, :public => true, :read => true
|
||||
map.permission :view_courses,{:courses => [:course]},:read => true
|
||||
end
|
||||
|
||||
#作业模块权限
|
||||
|
|
Loading…
Reference in New Issue