pre_develop
hjm 6 years ago
commit 9e25d8f10c

@ -109,11 +109,12 @@ module Mobile
return uw.user if uw return uw.user if uw
end end
third_party_user_id = session[:third_party_user_id] # third_party_user_id = session[:third_party_user_id]
if third_party_user_id # Rails.logger.info("#########third_party_user_id: #{third_party_user_id}")
c_user = UserSource.find_by_id(session[:third_party_user_id]) # if third_party_user_id
return c_user.user if c_user # c_user = UserSource.find_by_id(session[:third_party_user_id])
end # return c_user.user if c_user
# end
token = ApiKey.where(access_token: params[:token]).first token = ApiKey.where(access_token: params[:token]).first
if token && !token.expired? if token && !token.expired?

@ -43,12 +43,21 @@ module Mobile
requires :accessType, type: Integer, desc: "资源类型" requires :accessType, type: Integer, desc: "资源类型"
end end
get "source_url" do get "source_url" do
if session[:third_party_user_id].blank? user = User.find_by_id(params[:userId])
user = User.find(params[:userId]) return {error: -1, messages: "用户不存在,请先创建用户"} unless user
session[:third_party_user_id] = user.user_source.id token = Token.get_or_create_permanent_login_token(user)
cookie_options = {
:value => token.value,
:expires => 1.month.from_now,
:path => (Redmine::Configuration['autologin_cookie_path'] || '/'),
:secure => (Redmine::Configuration['autologin_cookie_secure'] ? true : false),
:httponly => true
}
if Redmine::Configuration['cookie_domain'].present?
cookie_options = cookie_options.merge(domain: Redmine::Configuration['cookie_domain'])
end end
cookies[Redmine::Configuration['autologin_cookie_name'].presence || 'autologin'] = cookie_options
CnmoocsService.new.source_url(params) CnmoocsService.new.source_url(params, token)
end end
desc "远程登录" desc "远程登录"

@ -193,6 +193,21 @@ class ApplicationController < ActionController::Base
find_current_user find_current_user
end end
def set_autologin_cookie(user)
token = Token.get_or_create_permanent_login_token(user)
cookie_options = {
:value => token.value,
:expires => 1.month.from_now,
:path => (Redmine::Configuration['autologin_cookie_path'] || '/'),
:secure => (Redmine::Configuration['autologin_cookie_secure'] ? true : false),
:httponly => true
}
if Redmine::Configuration['cookie_domain'].present?
cookie_options = cookie_options.merge(domain: Redmine::Configuration['cookie_domain'])
end
cookies[autologin_cookie_name] = cookie_options
end
def find_current_user def find_current_user
user = nil user = nil
unless api_request? unless api_request?
@ -207,9 +222,11 @@ class ApplicationController < ActionController::Base
elsif session[:wechat_openid] elsif session[:wechat_openid]
uw = UserWechat.find_by_openid(session[:wechat_openid]) uw = UserWechat.find_by_openid(session[:wechat_openid])
user = uw.user if uw user = uw.user if uw
elsif session[:third_party_user_id] elsif params[:authToken]
c_user = UserSource.find_by_id(session[:third_party_user_id]) user = Token.find_by_value(params[:authToken]).user
user = c_user.user if c_user #set_autologin_cookie(user)
#start_user_session(user)
session[:user_id] = user.id
end end
end end
if user.nil? && Setting.rest_api_enabled? && accept_api_auth? if user.nil? && Setting.rest_api_enabled? && accept_api_auth?
@ -335,6 +352,8 @@ class ApplicationController < ActionController::Base
end end
def require_login def require_login
logger.info("#########login?: #{User.current.logged?}")
logger.info("#########get?: #{request.get?}")
if !User.current.logged? if !User.current.logged?
# Extract only the basic url parameters on non-GET requests # Extract only the basic url parameters on non-GET requests
if request.get? if request.get?

@ -16,6 +16,7 @@ class ChallengesController < ApplicationController
#before_filter :find_shixun_language, :only => [:show, :new, :edit] #before_filter :find_shixun_language, :only => [:show, :new, :edit]
before_filter :base_index, :only => [:index, :index_down, :index_up, :destroy] before_filter :base_index, :only => [:index, :index_down, :index_up, :destroy]
before_filter :view_allow, :only => [:show] before_filter :view_allow, :only => [:show]
# before_filter :check_cnmooc, :only => [:index]
include ApplicationHelper include ApplicationHelper
@ -487,4 +488,12 @@ class ChallengesController < ApplicationController
response.headers['content--type'] = 'text/javascript' response.headers['content--type'] = 'text/javascript'
request.format = 'js' request.format = 'js'
end end
# def check_cnmooc
# if params[:authToken]
# user = User.find_by_id(session[:user_id])
# set_autologin_cookie(user)
# end
# end
end end

@ -50,7 +50,7 @@ class CollegesController < ApplicationController
# Redo这样做内存会卡死的 # Redo这样做内存会卡死的
# user_ids = User.find_by_sql("SELECT users.id FROM users LEFT JOIN user_extensions ON users.id=user_extensions.user_id WHERE user_extensions.`school_id` = #{@school.id}").map(&:id) # user_ids = User.find_by_sql("SELECT users.id FROM users LEFT JOIN user_extensions ON users.id=user_extensions.user_id WHERE user_extensions.`school_id` = #{@school.id}").map(&:id)
# Redo是否直接使用count会更好 # Redo是否直接使用count会更好
all_course_ids = Course.joins("join users u on courses.tea_id = u.id").joins("join user_extensions ue on u.id = ue.user_id").where("courses.id != 1309 and ue.school_id = #{@school.id}") all_course_ids = Course.where("id != 1309 and is_delete = 0 and school_id = #{@school.id}")
@courses_count = all_course_ids.size @courses_count = all_course_ids.size
# Redo对于量比较大的尽量不使用笛卡尔积 # Redo对于量比较大的尽量不使用笛卡尔积
@ -131,7 +131,7 @@ class CollegesController < ApplicationController
(select count(m.id) from messages m inner join boards b on b.id=m.board_id and b.parent_id=0 where b.course_id=c.id group by c.id) as messages_count, (select count(m.id) from messages m inner join boards b on b.id=m.board_id and b.parent_id=0 where b.course_id=c.id group by c.id) as messages_count,
c.tea_id, c.name, c.is_end, c.tea_id, c.name, c.is_end,
(SELECT MAX(created_at) FROM `course_activities` ca WHERE ca.course_id = c.id) AS update_time (SELECT MAX(created_at) FROM `course_activities` ca WHERE ca.course_id = c.id) AS update_time
FROM `courses` c WHERE (c.school_id = #{@school.id} and c.is_delete = 0)") FROM `courses` c WHERE c.school_id = #{@school.id} and c.is_delete = 0")
@courses.each do |course| @courses.each do |course|
course[:evaluating_count] = Output.find_by_sql("select sum(g.evaluate_count) as evaluating_count from games g inner join course[:evaluating_count] = Output.find_by_sql("select sum(g.evaluate_count) as evaluating_count from games g inner join

@ -577,7 +577,7 @@ class CoursesController < ApplicationController
cha_member.member_roles.where("role_id = 10").first.destroy cha_member.member_roles.where("role_id = 10").first.destroy
StudentsForCourse.where(:course_id => @course.id, :student_id => cha_member.user_id).destroy_all StudentsForCourse.where(:course_id => @course.id, :student_id => cha_member.user_id).destroy_all
end end
@course.update_attributes(:tea_id => cha_member.user_id) @course.update_attributes(:tea_id => cha_member.user_id, :school_id => cha_member.user.try(:user_extensions).try(:school_id))
man_member.member_roles.first.update_attributes(:role_id => 9) man_member.member_roles.first.update_attributes(:role_id => 9)
course_act = CourseActivity.where(:course_id => @course.id, :course_act_id => @course.id, :course_act_type => 'Course').first course_act = CourseActivity.where(:course_id => @course.id, :course_act_id => @course.id, :course_act_type => 'Course').first
course_act.update_column('user_id', cha_member.user_id) course_act.update_column('user_id', cha_member.user_id)

@ -853,7 +853,7 @@ class ManagementsController < ApplicationController
def evaluate_simple def evaluate_simple
page = params[:page] page = params[:page]
@recodes = EvaluateRecord.where("created_at > ?", Time.now - 10000.days).reorder("consume_time desc") @recodes = EvaluateRecord.where("created_at > ?", Time.now - 1.days).reorder("consume_time desc")
@recodes_count = @recodes.size @recodes_count = @recodes.size
@record_pages = Paginator.new @recodes_count, 20, page || 1 @record_pages = Paginator.new @recodes_count, 20, page || 1
@offset ||= @record_pages.offset @offset ||= @record_pages.offset

@ -1,10 +1,10 @@
# encoding: utf-8 # encoding: utf-8
class MyshixunsController < ApplicationController class MyshixunsController < ApplicationController
layout 'base_myshixun' layout 'base_myshixun'
skip_before_filter :verify_authenticity_token, :only => [:training_task_status, :close_webssh, :code_runinng_message] skip_before_filter :verify_authenticity_token, :only => [:training_task_status, :close_webssh, :code_runinng_message, :vnc]
before_filter :require_login, :except => [:training_task_status, :close_webssh, :code_runinng_message] before_filter :require_login, :except => [:training_task_status, :close_webssh, :code_runinng_message, :vnc]
before_filter :check_authentication, :except => [:training_task_status, :close_webssh, :mul_test_home, :mul_test_user, before_filter :check_authentication, :except => [:training_task_status, :close_webssh, :mul_test_home, :mul_test_user,
:mul_test_myshixun, :mul_test_shixun, :mul_test_start, :code_runinng_message] :mul_test_myshixun, :mul_test_shixun, :mul_test_start, :code_runinng_message, :vnc]
before_filter :find_myshixun, :only => [:show, :myshixun_reset, :open_webssh, :sync_reset_time, :destroy, :search_file_list, :vnc] before_filter :find_myshixun, :only => [:show, :myshixun_reset, :open_webssh, :sync_reset_time, :destroy, :search_file_list, :vnc]
DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z) DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
@ -357,7 +357,8 @@ class MyshixunsController < ApplicationController
host = Redmine::Configuration['tomcat_php'] host = Redmine::Configuration['tomcat_php']
begin begin
uri = "#{shixun_tomcat}/bridge/vnc/getvnc" uri = "#{shixun_tomcat}/bridge/vnc/getvnc"
params = {tpiID:@myshixun.id} shixun = @myshixun.shixun
params = {tpiID: @myshixun.id, :containers => "#{Base64.urlsafe_encode64(container_limit(shixun.mirror_repositories))}"}
res = uri_exec uri, params res = uri_exec uri, params
if res && res['code'].to_i != 0 if res && res['code'].to_i != 0
raise("实训云平台繁忙繁忙等级99") raise("实训云平台繁忙繁忙等级99")

@ -57,7 +57,7 @@ class Shixun < ActiveRecord::Base
scope :visible, lambda{where(status: [2,3])} scope :visible, lambda{where(status: [2,3])}
scope :min, lambda { select([:id, :name, :gpid, :modify_time, :reset_time, :language, :propaedeutics, :status, :identifier, scope :min, lambda { select([:id, :name, :gpid, :modify_time, :reset_time, :language, :propaedeutics, :status, :identifier,
:test_set_permission, :hide_code, :forbid_copy, :hidden, :webssh, :user_id, :code_hidden, :test_set_permission, :hide_code, :forbid_copy, :hidden, :webssh, :user_id, :code_hidden,
:task_pass, :exec_time, :multi_webssh]) } :task_pass, :exec_time, :multi_webssh, :vnc]) }
scope :published, lambda{where(status: 2)} scope :published, lambda{where(status: 2)}
scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) } scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) }

@ -114,13 +114,12 @@ class CnmoocsService
end end
def source_url(params) def source_url(params, token)
shixun = Shixun.find_by_identifier(params[:resouceId]) shixun = Shixun.find_by_id(params[:resouceId])
if shixun.blank? if shixun.blank?
return { error: -1, messages: '资源不存在' } return { error: -1, messages: '资源不存在' }
end end
{ error: 0, messages: '成功', accessUrl: "#{Redmine::Configuration['educoder_domain']}/shixuns/#{shixun.identifier}/challenges?authToken=#{token.value}" }
{ error: 0, messages: '成功', accessUrl: "#{Redmine::Configuration['educoder_domain']}/shixuns/#{shixun.identifier}" }
end end
def get_students_data params def get_students_data params

@ -19,6 +19,7 @@ class GamesService
shixun = Shixun.min.find(myshixun.shixun_id) shixun = Shixun.min.find(myshixun.shixun_id)
unless ((myshixun.user_id == current_user.id || current_user.business? || current_user.id == shixun.try(:user_id) || unless ((myshixun.user_id == current_user.id || current_user.business? || current_user.id == shixun.try(:user_id) ||
current_user.is_certification_teacher) && (shixun.operable?)) || current_user.admin? current_user.is_certification_teacher) && (shixun.operable?)) || current_user.admin?
Rails.logger.info("######403???")
return{:status => 403} return{:status => 403}
end end
game_challenge = Challenge.min.find(game.challenge_id) game_challenge = Challenge.min.find(game.challenge_id)
@ -74,7 +75,8 @@ class GamesService
:challenge => game_challenge.try(:attributes), :game => game.try(:attributes), :shixun => shixun.try(:attributes), :challenge => game_challenge.try(:attributes), :game => game.try(:attributes), :shixun => shixun.try(:attributes),
:record => record, :grade => grade, :prev_game => prev_game, :next_game => next_game, :username => username, :record => record, :grade => grade, :prev_game => prev_game, :next_game => next_game, :username => username,
:image_url => image_url, :user_url => user_url, :praise_count => praise_count, :user_praise => user_praise, :time_limit => time_limit, :image_url => image_url, :user_url => user_url, :praise_count => praise_count, :user_praise => user_praise, :time_limit => time_limit,
:tomcat_url => Redmine::Configuration['tomcat_php'], :is_teacher => is_teacher, :power => power, :myshixun_manager => myshixun_manager} :tomcat_url => Redmine::Configuration['tomcat_php'], :is_teacher => is_teacher, :power => power, :myshixun_manager => myshixun_manager,
:vnc => shixun.vnc}
# 区分选择题和编程题st0编程题 # 区分选择题和编程题st0编程题
if st == 0 if st == 0

@ -26,13 +26,10 @@
<div style="float: left;"> <div style="float: left;">
<%= hidden_field_tag :data_type, params[:data_type] || 'grow' %> <%= hidden_field_tag :data_type, params[:data_type] || 'grow' %>
<% if params[:data_type] == 'contrast' %> <a href="javascript:void(0)" class="fl task-btn ml5 mt10 contrast-btn <%= params[:data_type] == 'contrast' ? 'task-btn-orange' : '' %>"
<a href="javascript:void(0)" class="fl task-btn ml5 mt10 contrast-btn task-btn-orange">时间对比</a> data-tip-down="请在左侧分别选择需进行对比的两个时段,下表显示两时段选定指标两时段变化情况对比">时段对比</a>
<a href="javascript:void(0)" class="fl task-btn ml5 mt10 grow-btn">新增数据</a> <a href="javascript:void(0)" class="fl task-btn ml5 mt10 grow-btn <%= params[:data_type] == 'contrast' ? '' : 'task-btn-orange' %>"
<% else %> data-tip-down="请在左侧选择时间段,下表显示选定时间段内各项指标数据变化情况">数据变化</a>
<a href="javascript:void(0)" class="fl task-btn ml5 mt10 contrast-btn">时间对比</a>
<a href="javascript:void(0)" class="fl task-btn ml5 mt10 grow-btn task-btn-orange">新增数据</a>
<% end %>
</div> </div>
<%= text_field_tag :keyword, params[:keyword], placeholder: '请输入单位名称或者ID关键字进行搜索', <%= text_field_tag :keyword, params[:keyword], placeholder: '请输入单位名称或者ID关键字进行搜索',

@ -21,8 +21,8 @@
<th width="6%">序号</th> <th width="6%">序号</th>
<th width="10%">ID</th> <th width="10%">ID</th>
<th width="20%" class="edu-txt-left">单位名称</th> <th width="20%" class="edu-txt-left">单位名称</th>
<th width="22%">时段一<br><%= "#{params[:begin_date]}至#{params[:end_date]}" %></th> <th width="22%">时段一<br><%= "#{params[:begin_date]} 05:00至#{params[:end_date]} 05:00" %></th>
<th width="22%">时段二<br><%= "#{params[:other_begin_date]}至#{params[:other_end_date]}" %></th> <th width="22%">时段二<br><%= "#{params[:other_begin_date]} 05:00至#{params[:other_end_date]} 05:00" %></th>
<th width="20%" colspan="2"> <th width="20%" colspan="2">
<%= sort_tag('变化情况', name: 'percentage', path: school_data_contrast_managements_path) %> <%= sort_tag('变化情况', name: 'percentage', path: school_data_contrast_managements_path) %>
<br> 新 增 数 | 新增百分比) <br> 新 增 数 | 新增百分比)

@ -9,7 +9,7 @@
新增教师<span class="color-red"><%= @grow_summary.teacher_increase_count || 0 %></span>人, 新增教师<span class="color-red"><%= @grow_summary.teacher_increase_count || 0 %></span>人,
新增学生<span class="color-red"><%= @grow_summary.student_increase_count || 0 %></span>人, 新增学生<span class="color-red"><%= @grow_summary.student_increase_count || 0 %></span>人,
新增课堂<span class="color-red"><%= @grow_summary.course_increase_count || 0 %></span>个, 新增课堂<span class="color-red"><%= @grow_summary.course_increase_count || 0 %></span>个,
新增实训<span class="color-red"><%= @grow_summary.shixun_increase_count || 0 %></span>个, 新增实训作业<span class="color-red"><%= @grow_summary.shixun_increase_count || 0 %></span>个,
活跃用户<span class="color-red"><%= @grow_summary.active_user_count || 0 %></span>个 活跃用户<span class="color-red"><%= @grow_summary.active_user_count || 0 %></span>个
</div> </div>
<table class="edu-pop-table edu-txt-center" cellpadding="0" cellspacing="0" style="table-layout: fixed"> <table class="edu-pop-table edu-txt-center" cellpadding="0" cellspacing="0" style="table-layout: fixed">
@ -22,7 +22,7 @@
<th width="12%"><%= sort_tag('新增教师', name: 'teacher_increase_count', path: school_data_grow_managements_path) %></th> <th width="12%"><%= sort_tag('新增教师', name: 'teacher_increase_count', path: school_data_grow_managements_path) %></th>
<th width="12%"><%= sort_tag('新增学生', name: 'student_increase_count', path: school_data_grow_managements_path) %></th> <th width="12%"><%= sort_tag('新增学生', name: 'student_increase_count', path: school_data_grow_managements_path) %></th>
<th width="12%"><%= sort_tag('新增课堂', name: 'course_increase_count', path: school_data_grow_managements_path) %></th> <th width="12%"><%= sort_tag('新增课堂', name: 'course_increase_count', path: school_data_grow_managements_path) %></th>
<th width="12%"><%= sort_tag('新增实训', name: 'shixun_increase_count', path: school_data_grow_managements_path) %></th> <th width="12%"><%= sort_tag('新增实训作业', name: 'shixun_increase_count', path: school_data_grow_managements_path) %></th>
<th width="12%"><%= sort_tag('活跃用户', name: 'active_user_count', path: school_data_grow_managements_path) %></th> <th width="12%"><%= sort_tag('活跃用户', name: 'active_user_count', path: school_data_grow_managements_path) %></th>
</tr> </tr>
</thead> </thead>

@ -156,7 +156,7 @@
<label style="top:6px" class="color-grey-6" for="can_copy">勾选则允许认证教师复制该实训</label> <label style="top:6px" class="color-grey-6" for="can_copy">勾选则允许认证教师复制该实训</label>
</li> </li>
</div> </div>
<% if Redmine::Configuration['gitlab_address'].include?("test") %> <% if User.current.admin? %>
<div class="mb10 edu-back-white padding30-20"> <div class="mb10 edu-back-white padding30-20">
<p class="color-grey-6 font-16 mb10">VNC图形化</p> <p class="color-grey-6 font-16 mb10">VNC图形化</p>
<li class="mb20"> <li class="mb20">

@ -211,7 +211,7 @@
</span> </span>
</div> </div>
<% if Redmine::Configuration['gitlab_address'].include?("test") %> <% if User.current.admin? %>
<div class="clearfix mt20"> <div class="clearfix mt20">
<span class="color-grey-6 mt5 fl" style="min-width: 95px;">VNC图形化:</span> <span class="color-grey-6 mt5 fl" style="min-width: 95px;">VNC图形化:</span>
<span class="fl"> <span class="fl">

@ -3,5 +3,5 @@ zh:
teacher_increase_count: 新增教师 teacher_increase_count: 新增教师
student_increase_count: 新增学生 student_increase_count: 新增学生
course_increase_count: 新增课堂 course_increase_count: 新增课堂
shixun_increase_count: 新增实训 shixun_increase_count: 新增实训作业
active_user_count: 活跃用户 active_user_count: 活跃用户

@ -0,0 +1,11 @@
class MigrateCourseSchoolId < ActiveRecord::Migration
def up
courses = Course.includes(teacher: :user_extensions).where("courses.school_id != user_extensions.school_id or courses.school_id is null")
courses.each do |course|
course.update_column('school_id', course.teacher.try(:user_extensions).try(:school_id))
end
end
def down
end
end
Loading…
Cancel
Save