diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a25b346c..8cf3a2c3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -291,6 +291,12 @@ class ApplicationController < ActionController::Base render_404 end + def find_course + @course= Course.find(params[:id]) + rescue ActiveRecord::RecordNotFound + render_404 + end + def self.model_object(model) self.model_object = model end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 53717aef..932550e4 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -5,14 +5,15 @@ class CoursesController < ApplicationController menu_item l(:label_sort_by_active), :only => :index menu_item l(:label_sort_by_influence), :only => :index + before_filter :find_course, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches] before_filter :authorize, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen, :view_homework_attaches, :course] #before_filter :authorize_global, :only => [:view_homework_attaches, :new,:create] before_filter :require_admin, :only => [:copy, :archive, :unarchive, :destroy, :calendar] + before_filter :toggleCourse, only: [:finishcourse, :restartcourse] before_filter :require_login, :only => [:join, :unjoin] before_filter :allow_join, :only => [:join] - def join if User.current.logged? course = Project.find(params[:object_id]) @@ -299,6 +300,24 @@ class CoursesController < ApplicationController return activities end + def toggleCourse + @course_prefs = Course.find_by_extra(@course.extra) + unless (@course_prefs.teacher == User.current || User.current.admin?) + render_403 + end + end + + def finishcourse + yesterday = Date.today.prev_day.to_time + + @course_prefs.endup_time = yesterday + @save_flag = @course_prefs.save + + respond_to do |format| + format.js + end + end + private def allow_join diff --git a/app/views/courses/finishcourse.js.erb b/app/views/courses/finishcourse.js.erb new file mode 100644 index 00000000..bfbaee70 --- /dev/null +++ b/app/views/courses/finishcourse.js.erb @@ -0,0 +1,8 @@ +<% if @save_flag %> + <% if Rails.env.development? %> + console.debug('课程修改成功:结束时间改为<%=Course.find_by_extra(@project.extra).try(:endup_time)%>'); + <% end %> + $('#finish_course_<%=@course.id%>').replaceWith("<%= j(render partial: 'courses/set_course_time', :locals => {:course => @course} )%>") +<% else %> + alert('权限不足,设置失败,请在论坛提交问题,等待管理员处理。'); +<% end %> diff --git a/app/views/users/_course_list_have_entity.html.erb b/app/views/users/_course_list_have_entity.html.erb index 19fb88a6..e29c8710 100644 --- a/app/views/users/_course_list_have_entity.html.erb +++ b/app/views/users/_course_list_have_entity.html.erb @@ -1,6 +1,6 @@