Merge branch 'dev_aliyun' into dev_course

dev_course
daiao 6 years ago
commit 8c8d11706c

9
.gitignore vendored

@ -44,8 +44,7 @@
/config/secrets.yml
/config/redis.yml
/files/archiveZip/*
/files/cache_store/*
public/upload.html
/config/configuration.yml
/config/initializers/gitlab_config.rb
@ -55,3 +54,9 @@ vendor/bundle/
.ruby-version
.ruby-gemset
/files
/public/images/avatars
/public/files
/workspace
/log

@ -215,7 +215,7 @@ class ApplicationController < ActionController::Base
return if params[:controller] == "main"
# Find the current user
User.current = find_current_user
uid_logger("user_step: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous"))
uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous"))
if !User.current.logged? && Rails.env.development?
User.current = User.find 12

@ -3,7 +3,8 @@ class GitsController < ApplicationController
#供git-workhorse反向调用认证
def auth
# HTTP_AUTHORIZATION: "Basic 这里base64编码的的密码(user:passwd)"
logger.info("11111112222223333#{request.env["HTTP_AUTHORIZATION"]}")
logger.info("11111112222223333 HTTP_AUTHORIZATION: #{request.env["HTTP_AUTHORIZATION"]}")
logger.info("11111112222223333: request is #{request.env}")
#logger.info("#########-----request_env: #{request.env}")
# {"service"=>"git-receive-pack", "controller"=>"gits", "action"=>"auth",
# "url"=>"forge01/cermyt39.git/info/refs"}
@ -19,7 +20,7 @@ class GitsController < ApplicationController
uid_logger("git start auth: input_username is #{input_username}")
# Git 超级权限用户
if input_username == gituser && input_password == gitpassword
if input_username.strip == gituser.strip && input_password.strip == gitpassword.strip
result = true
else
# 用户是否对对象拥有权限

@ -173,8 +173,8 @@ class HomeworkCommonsController < ApplicationController
end
# 排序
rorder = params[:order] || "update_time"
b_order = params[:b_order] || "desc"
rorder = params[:order].blank? ? "update_time" : params[:order]
b_order = params[:b_order].blank? ? "desc" : params[:b_order]
if rorder == "update_time" || rorder == "work_score"
@student_works = @student_works.order("student_works.#{rorder} #{b_order}")
elsif rorder == "student_id"

@ -1,6 +1,6 @@
class ShixunsController < ApplicationController
before_action :require_login, except: [:download_file, :index, :menus]
# before_action :check_auth, except: [:download_file, :index]
# before_action :require_login, except: [:download_file, :index, :menus]
before_action :check_auth, except: [:download_file, :index]
before_action :find_shixun, except: [:index, :new, :create, :menus, :get_recommend_shixuns, :propaedeutics,
:departments, :apply_shixun_mirror, :get_mirror_script, :download_file]
@ -710,13 +710,12 @@ private
def find_shixun
@shixun = Shixun.find_by_identifier(params[:identifier])
shixun = Shixun.where(identifier: params[:identifier]).first
if @shixun.blank?
normal_status(404, "...")
return
end
if !current_user.shixun_permission(@shixun) || (@shixun.status == -1 && !current_user.admin?)
if !current_user.shixun_permission(@shixun)
tip_exception(403, "..")
end
end

@ -432,7 +432,7 @@ class StudentWorksController < ApplicationController
@games = @work.myshixun.games.includes(:challenge, :game_codes, :outputs) if @work.myshixun
# 用户最大评测次数
@user_evaluate_count = @games.inject(0){|sum, g| sum + g.outputs.pluck(:query_index).first.to_i } if @games
@user_evaluate_count = @games.sum(:evaluate_count) if @games
# 图形效率图的数据
@echart_data = student_efficiency(@homework, @work)
end
@ -443,7 +443,7 @@ class StudentWorksController < ApplicationController
@games = @work.myshixun.games.includes(:challenge, :game_codes, :outputs) if @work.myshixun
# 用户最大评测次数
@user_evaluate_count = @games.inject(0){|sum, g| sum + g.outputs.pluck(:query_index).first.to_i } if @games
@user_evaluate_count = @games.sum(:evaluate_count) if @games
# 图形效率图的数据
@echart_data = student_efficiency(@homework, @work)
@myself_eff = @echart_data[:efficiency_list].find { |item| item.last == @user.id }

@ -37,6 +37,7 @@ class UsersController < ApplicationController
end
@course_identity = current_user.course_identity(@course) if @course
rescue Exception => e
uid_logger_error(e.message)
missing_template
end

@ -386,13 +386,22 @@ class User < ApplicationRecord
end
# 用户是否有权限查看实训
# 1、实训删除只有管理员能看到
# 2、实训隐藏了只有管理员、实训合作者能看到
# 3、如果有限制学校范围则学校的用户、管理员、实训合作者能看到
def shixun_permission(shixun)
# 性能优化:先处理不需要权限的实训(已发布并且没有单位权限限制的实训)
return false if shixun.status != 2 || shixun.hidden # 隐藏或者未发布的实训false
return true if shixun.use_scope == 0 # 对所有学校公开
return true if shixun.use_scope == 1 && (manager_of_shixun?(shixun) || shixun.shixun_schools.exists?(school_id: school_id)) # 对部分高校公开
# return true if manager_of_shixun?(shixun) # 实训管理员
return false
case shixun.status
when -1 # 软删除只有管理员能访问
admin?
when 0, 1, 3 # 申请发布或者已关闭的实训,只有实训管理员可以访问
manager_of_shixun?(shixun)
when 2
if shixun.hidden
manager_of_shixun?(shixun)
else
shixun.use_scope == 0 || manager_of_shixun?(shixun) || shixun.shixun_schools.exists?(school_id: school_id)
end
end
end
# 用户在平台名称的显示方式

@ -13,7 +13,7 @@ json.array! shixuns do |shixun|
json.identifier shixun.identifier
json.name shixun.name
json.status shixun.status
json.power (User.current.shixun_permission(shixun)) # 现在首页只显示已发布的实训
json.power (current_user.shixun_permission(shixun)) # 现在首页只显示已发布的实训
# REDO: 局部缓存
json.tag_name shixun.tag_repertoires.first.try(:name)
json.myshixuns_count shixun.myshixuns_count

@ -1,4 +1,4 @@
json.status shixun.status
json.shixun_status shixun.status
# REDO:前端需要通过status来判断发布
json.task_operation task_operation_url(current_myshixun, shixun)

@ -1,6 +1,6 @@
json.partial! 'shixuns/right', locals: { shixun: @shixun }
#json.follow follow?(@shixun.owner, User.current)
#json.fans_count @fans_count
#json.followed_count @followed_count
json.follow follow?(@shixun.owner, User.current)
json.fans_count @fans_count
json.followed_count @followed_count
json.user_shixuns_count @user_own_shixuns

@ -96,7 +96,7 @@ Rails.application.configure do
config.active_record.belongs_to_required_by_default = false
# config.cache_store = :file_store, "#{Rails.root }/files/cache_store/"
config.cache_store = :redis_store, 'redis://10.9.72.102:6379/0/cache', { expires_in: 90.minutes }
config.cache_store = :redis_store, 'redis://r-bp122bd1b710f274.redis.rds.aliyuncs.com:6379/0/cache', { expires_in: 90.minutes }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {

@ -1,34 +0,0 @@
class DeleteIvalidData < ActiveRecord::Migration[5.2]
def change
users = User.find_by_sql("select count(*) as user_count, login from users group by login having user_count>1")
users.each do |user|
valid_users = User.where(login: user.login)
valid_users.each do |valid_user|
unless valid_user.lastname.present?
valid_user.delete
end
end
end
mail_users = User.find_by_sql("select count(*) as user_count, mail from users where mail is not null group by mail having user_count>1")
mail_users.each do |mail_user|
valid_mail_users = User.where(mail: mail_user.mail)
valid_mail_users.each do |valid_mail_user|
unless valid_mail_user.lastname.present?
valid_mail_user.delete
end
end
end
phone_users = User.find_by_sql("select count(*) as user_count, phone from users where phone is not null group by phone having user_count>1")
phone_users.each do |phone_user|
valid_phone_users = User.where(phone: phone_user.phone)
valid_phone_users.each do |valid_phone_user|
unless valid_phone_user.lastname.present?
valid_phone_user.delete
end
end
end
end
end

@ -0,0 +1,34 @@
class SyncIvalidUsers < ActiveRecord::Migration[5.2]
# def change
# users = User.where.not(id: 2).find_by_sql("select count(*) as user_count, login from users group by login having user_count>1")
# users.each do |user|
# valid_users = User.where(login: user.login)
# valid_users.each do |valid_user|
# unless valid_user.lastname.present?
# valid_user.delete
# end
# end
# end
#
# mail_users = User.where.not(id: 2).find_by_sql("select count(*) as user_count, mail from users where mail is not null group by mail having user_count>1")
# mail_users.each do |mail_user|
# valid_mail_users = User.where(mail: mail_user.mail)
# valid_mail_users.each do |valid_mail_user|
# unless valid_mail_user.lastname.present?
# valid_mail_user.delete
# end
# end
# end
#
#
# phone_users = User.where.not(id: 2).find_by_sql("select count(*) as user_count, phone from users where phone is not null group by phone having user_count>1")
# phone_users.each do |phone_user|
# valid_phone_users = User.where(phone: phone_user.phone)
# valid_phone_users.each do |valid_phone_user|
# unless valid_phone_user.lastname.present?
# valid_phone_user.delete
# end
# end
# end
# end
end

@ -1,4 +1,4 @@
class ModifyScriptAndDescriptionForShixuninfo < ActiveRecord::Migration[5.2]
class ModifyShixunInfoForShixuns < ActiveRecord::Migration[5.2]
def change
Shixun.find_each do |shixun|
if shixun.shixun_info
@ -11,6 +11,5 @@ class ModifyScriptAndDescriptionForShixuninfo < ActiveRecord::Migration[5.2]
evaluate_script: shixun[:evaluate_script], shixun_id: shixun.id)
end
end
remove_columns :shixuns, :description, :propaedeutics, :evaluate_script
end
end

@ -0,0 +1,7 @@
class RemoveShixunLongTextForShixuns < ActiveRecord::Migration[5.2]
def change
if Shixun.first.has_attribute?(:description)
remove_columns :shixuns, :description, :propaedeutics, :evaluate_script
end
end
end

@ -10,7 +10,7 @@ namespace :sync do
puts repo_name
myshixun.update_column(:repo_name, repo_name)
rescue Exception => e
Rails.logger.error("e.message")
Rails.logger.error("#{e.message}")
end
end
end
@ -26,7 +26,27 @@ namespace :sync do
puts repo_name
shixun.update_column(:repo_name, repo_name)
rescue Exception => e
Rails.logger.error("e.message")
Rails.logger.error("#{e.message}")
end
end
end
task :check => :environment do
g = Gitlab.client
shixuns = Shixun.where("repo_name is null and fork_from is not null")
shixuns.find_each do |shixun|
begin
puts shixun.identifier
original_shixun = Shixun.find(fork_from)
gshixun = g.fork(original_shixun.gpid, shixun.owner.try(:gid))
repo_name = g.project(gshixun.id).path_with_namespace
puts repo_name
shixun.update_attributes(:repo_name => repo_name, :gpid => gshixun.id)
rescue Exception => e
Rails.logger.error("#{e.message}")
end
end
end

Loading…
Cancel
Save