Merge branch 'api' of http://repository.trustie.net/xianbo/trustie2 into api
This commit is contained in:
commit
df18eac875
|
@ -75,7 +75,7 @@ module Mobile
|
||||||
end
|
end
|
||||||
get 'teachers' do
|
get 'teachers' do
|
||||||
cs = CoursesService.new
|
cs = CoursesService.new
|
||||||
teachers = cs.course_teacher_or_student_list({role: 1}, params[:course_id])
|
teachers = cs.course_teacher_or_student_list({role: 1}, params[:course_id],current_user)
|
||||||
{status: 0, data: teachers}
|
{status: 0, data: teachers}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ module Mobile
|
||||||
end
|
end
|
||||||
get 'teachers' do
|
get 'teachers' do
|
||||||
cs = CoursesService.new
|
cs = CoursesService.new
|
||||||
teachers = cs.course_teacher_or_student_list({role: 2}, params[:course_id])
|
teachers = cs.course_teacher_or_student_list({role: 2}, params[:course_id],current_user)
|
||||||
{status: 0, data: teachers}
|
{status: 0, data: teachers}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -124,6 +124,7 @@ class AccountController < ApplicationController
|
||||||
when '1'
|
when '1'
|
||||||
#register_by_email_activation(@user)
|
#register_by_email_activation(@user)
|
||||||
unless @user.new_record?
|
unless @user.new_record?
|
||||||
|
flash[:notice] = l(:notice_account_register_done)
|
||||||
render action: 'email_valid', locals: {:mail => user.mail}
|
render action: 'email_valid', locals: {:mail => user.mail}
|
||||||
end
|
end
|
||||||
when '3'
|
when '3'
|
||||||
|
|
|
@ -245,9 +245,14 @@ class CoursesController < ApplicationController
|
||||||
#@members = @course.member_principals.includes(:roles, :principal).all.sort
|
#@members = @course.member_principals.includes(:roles, :principal).all.sort
|
||||||
end
|
end
|
||||||
cs = CoursesService.new
|
cs = CoursesService.new
|
||||||
@members = cs.course_teacher_or_student_list(params,@course)
|
@members = cs.course_teacher_or_student_list(params,@course,User.current)
|
||||||
@members = paginateHelper @members
|
@members = paginateHelper @members
|
||||||
render :layout => 'base_courses'
|
render :layout => 'base_courses'
|
||||||
|
|
||||||
|
rescue Exception => e
|
||||||
|
if e.message == '403'
|
||||||
|
render_403
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#判断指定用户是否为课程教师
|
#判断指定用户是否为课程教师
|
||||||
|
|
|
@ -24,7 +24,7 @@ module AccountHelper
|
||||||
if user.save and token.save
|
if user.save and token.save
|
||||||
UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0)
|
UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0)
|
||||||
Mailer.register(token).deliver
|
Mailer.register(token).deliver
|
||||||
flash[:notice] = l(:notice_account_register_done)
|
#flash[:notice] = l(:notice_account_register_done)
|
||||||
#render action: 'email_valid', locals: {:mail => user.mail}
|
#render action: 'email_valid', locals: {:mail => user.mail}
|
||||||
else
|
else
|
||||||
yield if block_given?
|
yield if block_given?
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
class CoursesService
|
class CoursesService
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
include CoursesHelper
|
include CoursesHelper
|
||||||
|
#TODO:尚未整合权限系统
|
||||||
#参数school_id为0或不传时返回所有课程,否则返回对应学校的课程
|
#参数school_id为0或不传时返回所有课程,否则返回对应学校的课程
|
||||||
#参数per_page_count分页功能,每页显示的课程数
|
#参数per_page_count分页功能,每页显示的课程数
|
||||||
#参数page分页功能,当前页码
|
#参数page分页功能,当前页码
|
||||||
|
@ -48,20 +49,28 @@ class CoursesService
|
||||||
url_to_avatar(obj)
|
url_to_avatar(obj)
|
||||||
end
|
end
|
||||||
|
|
||||||
#课程老师或课程学生列表
|
#课程老师或课程学生列表 TODO:更新业务逻辑,当前版本未包含分班功能
|
||||||
def course_teacher_or_student_list params,course
|
def course_teacher_or_student_list params,course,current_user
|
||||||
@teachers= searchTeacherAndAssistant(course)
|
if course.is_a?(Course)
|
||||||
|
c = course
|
||||||
|
else
|
||||||
|
c = Course.find(course)
|
||||||
|
end
|
||||||
|
if !(current_user.admin? || c.is_public == 1 || (c.is_public == 0 && current_user.member_of_course?(c)))
|
||||||
|
raise '403'
|
||||||
|
end
|
||||||
|
@teachers= searchTeacherAndAssistant(c)
|
||||||
#@canShowCode = isCourseTeacher(User.current.id,course) && params[:role] != '1'
|
#@canShowCode = isCourseTeacher(User.current.id,course) && params[:role] != '1'
|
||||||
case params[:role]
|
case params[:role]
|
||||||
when '1'
|
when '1'
|
||||||
#@subPage_title = l :label_teacher_list
|
#@subPage_title = l :label_teacher_list
|
||||||
@members = searchTeacherAndAssistant(course)
|
@members = searchTeacherAndAssistant(c)
|
||||||
when '2'
|
when '2'
|
||||||
#@subPage_title = l :label_student_list
|
#@subPage_title = l :label_student_list
|
||||||
@members = searchStudent(course)
|
@members = searchStudent(c)
|
||||||
else
|
else
|
||||||
#@subPage_title = ''
|
#@subPage_title = ''
|
||||||
@members = @course.member_principals.includes(:roles, :principal).all.sort
|
@members = c.member_principals.includes(:roles, :principal).all.sort
|
||||||
end
|
end
|
||||||
@members
|
@members
|
||||||
end
|
end
|
||||||
|
@ -74,6 +83,11 @@ class CoursesService
|
||||||
scope = @course ? @course.news.course_visible : News.course_visible
|
scope = @course ? @course.news.course_visible : News.course_visible
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#显示课程通知
|
||||||
|
def show_course_news
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
def show_course params
|
def show_course params
|
||||||
course = Course.find(params[:id])
|
course = Course.find(params[:id])
|
||||||
course
|
course
|
||||||
|
@ -178,4 +192,17 @@ class CoursesService
|
||||||
[@state,course]
|
[@state,course]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#作业列表
|
||||||
|
#已提交的作业数量获取 bid.homeworks.count
|
||||||
|
#学生提问数量获取 bid.commit.nil? ? 0 : bid.commit
|
||||||
|
def homework_list params,current_user
|
||||||
|
if @course.is_public != 0 || current_user.member_of_course?(@course)
|
||||||
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
||||||
|
@bids = @course.homeworks.order('deadline DESC')
|
||||||
|
@bids = @bids.like(params[:name]) if params[:name].present?
|
||||||
|
else
|
||||||
|
raise '403'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
Loading…
Reference in New Issue