dev_local
daiao 6 years ago
parent aee5cf576d
commit fd831f32bf

@ -142,6 +142,13 @@ class ApplicationController < ActionController::Base
end
end
# 本地考试使用
def local_exam
if LocalSetting.first.try(:exam) && !User.current.admin?
render_403
end
end
def user_agent
logger.info "HTTP_USER_AGENT #{request.env["HTTP_USER_AGENT"]}"
end

@ -18,6 +18,7 @@
class BoardsController < ApplicationController
layout 'base_projects'#by young
default_search_scope :messages
before_filter :local_exam
# before_filter :check_authentication, :except => []
before_filter :find_project_by_project_id, :find_board_if_available, :except => [:join_to_org_subfields]
before_filter :authorize, :except => [:new, :show, :create, :index, :join_to_org_subfields, :update_position, :update_name, :update_boards_position, :update_boards_name]

@ -13,6 +13,7 @@ class CoursesController < ApplicationController
include ApplicationHelper
helper SyllabusesHelper
before_filter :local_exam, :except => [:show]
# before_filter :auth_login1, :only => [:show, :course_activity, :feedback]
if Redmine::Configuration['gitlab_address'].include?("test")
skip_before_filter :verify_authenticity_token, :only => [:update_course_module, :join_course_multi_role]
@ -1617,76 +1618,78 @@ class CoursesController < ApplicationController
end
def show
# 被删除的课程只有超级管理员才能看到is_delete为1的时候标记课程被删除
# if @course.is_delete == 1 && !User.current.admin?
# render_403
# return
# end
#更新创建课程消息状态
# course_request_messages = CourseMessage.where(:user_id => User.current.id, :course_id => @course.id, :course_message_type => ["CourseRequestDealResult", "Course"], :viewed => false)
# course_request_messages.update_all(:viewed => true)
# create_course_messages = @course.course_messages.where("user_id =? and course_message_type =? and course_id =? and viewed =?", User.current.id, 'Course', @course.id, 0)
# create_course_messages.update_all(:viewed => true)
#更新申请结果反馈消息的状态
# course_request_messages = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?", User.current.id, @course.id, 'CourseRequestDealResult', false)
# course_request_messages.update_all(:viewed => true)
@course_modules = @course.course_modules.where(:hidden => 0)
course_module_type = @course_modules.map(&:module_type)
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
if User.current.member_of_course?(@course) && !@is_teacher
member = @course.members.where(:user_id => User.current.id).first
if member.try(:course_group_id).to_i == 0
common_homework_ids = @course.homework_commons.where("homework_type = 1 and unified_setting = 1")
shixun_homework_ids = @course.homework_commons.where("homework_type = 4 and unified_setting = 1")
group_homework_ids = @course.homework_commons.where("homework_type = 3 and unified_setting = 1")
exercise_ids = @course.exercises.where("unified_setting = 1")
poll_ids = @course.polls.where("unified_setting = 1")
atta_ids = @course.attachments.where("unified_setting = 1")
if LocalSetting.first.try(:exam) && !User.current.admin?
else
# 被删除的课程只有超级管理员才能看到is_delete为1的时候标记课程被删除
# if @course.is_delete == 1 && !User.current.admin?
# render_403
# return
# end
#更新创建课程消息状态
# course_request_messages = CourseMessage.where(:user_id => User.current.id, :course_id => @course.id, :course_message_type => ["CourseRequestDealResult", "Course"], :viewed => false)
# course_request_messages.update_all(:viewed => true)
# create_course_messages = @course.course_messages.where("user_id =? and course_message_type =? and course_id =? and viewed =?", User.current.id, 'Course', @course.id, 0)
# create_course_messages.update_all(:viewed => true)
#更新申请结果反馈消息的状态
# course_request_messages = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?", User.current.id, @course.id, 'CourseRequestDealResult', false)
# course_request_messages.update_all(:viewed => true)
@course_modules = @course.course_modules.where(:hidden => 0)
course_module_type = @course_modules.map(&:module_type)
@is_teacher = User.current.allowed_to?(:as_teacher, @course) || User.current.admin?
if User.current.member_of_course?(@course) && !@is_teacher
member = @course.members.where(:user_id => User.current.id).first
if member.try(:course_group_id).to_i == 0
common_homework_ids = @course.homework_commons.where("homework_type = 1 and unified_setting = 1")
shixun_homework_ids = @course.homework_commons.where("homework_type = 4 and unified_setting = 1")
group_homework_ids = @course.homework_commons.where("homework_type = 3 and unified_setting = 1")
exercise_ids = @course.exercises.where("unified_setting = 1")
poll_ids = @course.polls.where("unified_setting = 1")
atta_ids = @course.attachments.where("unified_setting = 1")
else
not_homework_ids = @course.homework_group_settings.where("course_group_id = #{member.try(:course_group_id)} and (publish_time > '#{Time.now}' or publish_time is null)")
not_homework_ids = not_homework_ids.blank? ? "(-1)" : "(" + not_homework_ids.map(&:homework_common_id).join(",") + ")"
common_homework_ids = @course.homework_commons.where("homework_type = 1 and id not in #{not_homework_ids}")
shixun_homework_ids = @course.homework_commons.where("homework_type = 4 and id not in #{not_homework_ids}")
group_homework_ids = @course.homework_commons.where("homework_type = 3 and id not in #{not_homework_ids}")
not_exercise_ids = @course.exercise_group_settings.where("course_group_id = #{member.try(:course_group_id)} and (publish_time > '#{Time.now}' or publish_time is null)")
not_exercise_ids = not_exercise_ids.blank? ? "(-1)" : "(" + not_exercise_ids.map(&:exercise_id).join(",") + ")"
exercise_ids = @course.exercises.where("id not in #{not_exercise_ids}")
not_poll_ids = @course.poll_group_settings.where("course_group_id = #{member.try(:course_group_id)} and (publish_time > '#{Time.now}' or publish_time is null)")
not_poll_ids = not_poll_ids.blank? ? "(-1)" : "(" + not_poll_ids.map(&:poll_id).join(",") + ")"
poll_ids = @course.polls.where("id not in #{not_poll_ids}")
not_atta_ids = @course.attachment_group_settings.where("course_group_id = #{member.try(:course_group_id)} and publish_time > '#{Time.now}'")
not_atta_ids = not_atta_ids.blank? ? "(-1)" : "(" + not_atta_ids.map(&:attachment_id).join(",") + ")"
atta_ids = @course.attachments.where("id not in #{not_atta_ids}")
end
else
not_homework_ids = @course.homework_group_settings.where("course_group_id = #{member.try(:course_group_id)} and (publish_time > '#{Time.now}' or publish_time is null)")
not_homework_ids = not_homework_ids.blank? ? "(-1)" : "(" + not_homework_ids.map(&:homework_common_id).join(",") + ")"
common_homework_ids = @course.homework_commons.where("homework_type = 1 and id not in #{not_homework_ids}")
shixun_homework_ids = @course.homework_commons.where("homework_type = 4 and id not in #{not_homework_ids}")
group_homework_ids = @course.homework_commons.where("homework_type = 3 and id not in #{not_homework_ids}")
not_exercise_ids = @course.exercise_group_settings.where("course_group_id = #{member.try(:course_group_id)} and (publish_time > '#{Time.now}' or publish_time is null)")
not_exercise_ids = not_exercise_ids.blank? ? "(-1)" : "(" + not_exercise_ids.map(&:exercise_id).join(",") + ")"
exercise_ids = @course.exercises.where("id not in #{not_exercise_ids}")
not_poll_ids = @course.poll_group_settings.where("course_group_id = #{member.try(:course_group_id)} and (publish_time > '#{Time.now}' or publish_time is null)")
not_poll_ids = not_poll_ids.blank? ? "(-1)" : "(" + not_poll_ids.map(&:poll_id).join(",") + ")"
poll_ids = @course.polls.where("id not in #{not_poll_ids}")
not_atta_ids = @course.attachment_group_settings.where("course_group_id = #{member.try(:course_group_id)} and publish_time > '#{Time.now}'")
not_atta_ids = not_atta_ids.blank? ? "(-1)" : "(" + not_atta_ids.map(&:attachment_id).join(",") + ")"
atta_ids = @course.attachments.where("id not in #{not_atta_ids}")
common_homework_ids = @course.homework_commons.where("homework_type = 1")
shixun_homework_ids = @course.homework_commons.where("homework_type = 4")
group_homework_ids = @course.homework_commons.where("homework_type = 3")
exercise_ids = @course.exercises
poll_ids = @course.polls
atta_ids = @course.attachments
end
common_homework_ids = common_homework_ids.blank? ? "(-1)" : "(" + common_homework_ids.map(&:id).join(",") + ")"
shixun_homework_ids = shixun_homework_ids.blank? ? "(-1)" : "(" + shixun_homework_ids.map(&:id).join(",") + ")"
group_homework_ids = group_homework_ids.blank? ? "(-1)" : "(" + group_homework_ids.map(&:id).join(",") + ")"
exercise_ids = exercise_ids.blank? ? "(-1)" : "(" + exercise_ids.map(&:id).join(",") + ")"
poll_ids = poll_ids.blank? ? "(-1)" : "(" + poll_ids.map(&:id).join(",") + ")"
atta_ids = atta_ids.blank? ? "(-1)" : "(" + atta_ids.map(&:id).join(",") + ")"
if @is_teacher && course_module_type.include?('board')
course_act_type = "('Message', 'JoinCourse')"
elsif @is_teacher
course_act_type = "('JoinCourse')"
elsif course_module_type.include?('board')
course_act_type = "('Message')"
else
course_act_type = "('0')"
end
else
common_homework_ids = @course.homework_commons.where("homework_type = 1")
shixun_homework_ids = @course.homework_commons.where("homework_type = 4")
group_homework_ids = @course.homework_commons.where("homework_type = 3")
exercise_ids = @course.exercises
poll_ids = @course.polls
atta_ids = @course.attachments
end
common_homework_ids = common_homework_ids.blank? ? "(-1)" : "(" + common_homework_ids.map(&:id).join(",") + ")"
shixun_homework_ids = shixun_homework_ids.blank? ? "(-1)" : "(" + shixun_homework_ids.map(&:id).join(",") + ")"
group_homework_ids = group_homework_ids.blank? ? "(-1)" : "(" + group_homework_ids.map(&:id).join(",") + ")"
exercise_ids = exercise_ids.blank? ? "(-1)" : "(" + exercise_ids.map(&:id).join(",") + ")"
poll_ids = poll_ids.blank? ? "(-1)" : "(" + poll_ids.map(&:id).join(",") + ")"
atta_ids = atta_ids.blank? ? "(-1)" : "(" + atta_ids.map(&:id).join(",") + ")"
if @is_teacher && course_module_type.include?('board')
course_act_type = "('Message', 'JoinCourse')"
elsif @is_teacher
course_act_type = "('JoinCourse')"
elsif course_module_type.include?('board')
course_act_type = "('Message')"
else
course_act_type = "('0')"
end
sql_str = "course_act_type in #{course_act_type}"
@course_modules.each do |course_module|
case course_module.module_type
sql_str = "course_act_type in #{course_act_type}"
@course_modules.each do |course_module|
case course_module.module_type
when "shixun_homework"
sql_str += " or (course_act_type = 'HomeworkCommon' && course_act_id in #{shixun_homework_ids})"
when "common_homework"
@ -1701,11 +1704,11 @@ class CoursesController < ApplicationController
sql_str += " or (course_act_type = 'Poll' && course_act_id in #{poll_ids})"
when "attachment"
sql_str += " or (course_act_type = 'Attachment' && course_act_id in #{atta_ids})"
end
end
end
@page = params[:page] ? params[:page].to_i + 1 : 0
if params[:type].present?
case params[:type]
@page = params[:page] ? params[:page].to_i + 1 : 0
if params[:type].present?
case params[:type]
when "common_homework"
# homework_ids = @course.homework_commons.where("homework_type = 1 and id in #{homework_ids}")
@course_activities = @course.course_activities.where("course_act_type = 'HomeworkCommon' and course_act_id in #{common_homework_ids}").order('updated_at desc')
@ -1735,16 +1738,17 @@ class CoursesController < ApplicationController
@course_activities = @course.course_activities.where("course_act_type = 'JournalsForMessage'").order('updated_at desc')
else
@course_activities = @course.course_activities.where("#{sql_str}").order('updated_at desc')
end
else
@course_activities = @course.course_activities.where("#{sql_str}").order('updated_at desc')
end
else
@course_activities = @course.course_activities.where("#{sql_str}").order('updated_at desc')
end
@course_activities_count = @course_activities.size
@course_activities = @course_activities.limit(10).offset(@page * 10)
@type = params[:type]
@course_activities_count = @course_activities.size
@course_activities = @course_activities.limit(10).offset(@page * 10)
@type = params[:type]
@left_nav_type = 1
@show_page = true
@left_nav_type = 1
@show_page = true
end
respond_to do |format|
format.js
format.html{render :layout => 'base_courses'}

@ -27,6 +27,10 @@ class ExerciseController < ApplicationController
return
end
if LocalSetting.first.try(:exam) && !User.current.admin?
params[:type] = 2
end
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
if @is_teacher
exercises = @course.exercises.order("IF(ISNULL(publish_time),0,1),publish_time DESC, created_at DESC")

@ -20,6 +20,7 @@ class FilesController < ApplicationController
layout 'base_projects' #by young
menu_item :files
before_filter :local_exam
# before_filter :check_authentication, :except => []
# before_filter :auth_login1, :only => [:index]
# before_filter :logged_user_by_apptoken,:only => [:index]

@ -1,5 +1,6 @@
#encoding: utf-8
class GraduationTasksController < ApplicationController
before_filter :local_exam
before_filter :find_course, :only => [:index, :new, :create]
before_filter :find_task, :only => [:show, :edit, :update, :destroy, :task_discuss, :task_setting, :publish_task, :end_task]
before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy]

@ -1,5 +1,6 @@
#encoding: utf-8
class GraduationTopicsController < ApplicationController
before_filter :local_exam
before_filter :find_course, :only => [:index, :new, :create, :search_teacher, :export]
before_filter :find_topic, :only => [:show, :edit, :update, :destroy, :set_public, :student_select_topic, :cancel_topic_select, :refuse_select,
:accept_select]

@ -8,6 +8,7 @@ class HomeworkCommonController < ApplicationController
include StudentWorkHelper
include ApplicationHelper
# before_filter :check_authentication, :except => []
before_filter :local_exam
before_filter :find_course, :only => [:index,:new,:create, :shixuns, :create_shixun_homework, :publish_shixun_homework]
before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment,:stop_anonymous_comment,:destroy,:start_evaluation_set,
:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,:open_student_works,

@ -1,5 +1,6 @@
#encoding utf-8
class PollController < ApplicationController
before_filter :local_exam
before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question,:commit_poll,:commit_answer,:publish_poll,:publish_notice,:end_notice,:cancel_publish,:poll_result,
:close_poll,:export_poll,:save_poll,:update_question_num, :student_poll_list, :poll_setting, :set_public, :add_to_exercise_bank]
before_filter :find_container, :only => [:new,:create, :index]

@ -10,7 +10,11 @@
<div class="with78 fl">
<div class="ml20 clearfix">
<div id="course_activities_content">
<%= render :partial => 'courses/course_activity_content', :locals => {:course_activities => @course_activities} %>
<% if LocalSetting.first.try(:exam) && !User.current.admin? %>
<%= render :partial => 'welcome/no_data' %>
<% else %>
<%= render :partial => 'courses/course_activity_content', :locals => {:course_activities => @course_activities} %>
<% end %>
</div>
</div>
</div>
Loading…
Cancel
Save