From cd41197a46d22795a5f4201bbb544b5a21d6f9e2 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 21 Jun 2019 15:57:18 +0800 Subject: [PATCH 01/30] redis init --- config/environments/production.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 38938b7e3..c3950f345 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -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 = { From 2880e8ac25a3bd5383f40df22044acbe00857605 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 21 Jun 2019 17:04:40 +0800 Subject: [PATCH 02/30] =?UTF-8?q?gitlab=E8=BF=81=E7=A7=BB=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/gitlab.rake | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/tasks/gitlab.rake b/lib/tasks/gitlab.rake index 396f197d3..0d872991b 100644 --- a/lib/tasks/gitlab.rake +++ b/lib/tasks/gitlab.rake @@ -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 From 1543ed0379e170d130b310d47c1511c6e13ec8e2 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 21 Jun 2019 17:13:52 +0800 Subject: [PATCH 03/30] git ignore --- .gitignore | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index b2e36f7ee..309e960d7 100644 --- a/.gitignore +++ b/.gitignore @@ -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 + From 6c6d64ad42f9e5d02b2bbf4b117f63e46c30fcf4 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 21 Jun 2019 17:22:31 +0800 Subject: [PATCH 04/30] test --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 32a314c54..499bd0aa4 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -1,5 +1,5 @@ class ShixunsController < ApplicationController - before_action :require_login, except: [:download_file, :index, :menus] + # 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, From 04bb267f6ff6dc6feaba163a028e15982428c5bc Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 21 Jun 2019 18:53:04 +0800 Subject: [PATCH 05/30] =?UTF-8?q?=E5=A4=84=E7=90=86=E6=97=A0=E6=95=88?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rb => 20190621105144_sync_ivalid_users.rb} | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) rename db/migrate/{20190505092009_delete_ivalid_data.rb => 20190621105144_sync_ivalid_users.rb} (60%) diff --git a/db/migrate/20190505092009_delete_ivalid_data.rb b/db/migrate/20190621105144_sync_ivalid_users.rb similarity index 60% rename from db/migrate/20190505092009_delete_ivalid_data.rb rename to db/migrate/20190621105144_sync_ivalid_users.rb index 98f13d9e4..3520ca84d 100644 --- a/db/migrate/20190505092009_delete_ivalid_data.rb +++ b/db/migrate/20190621105144_sync_ivalid_users.rb @@ -1,34 +1,34 @@ -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 +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 From 287f7ff17b15d7c3bb0972d495e33435490c333f Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 09:07:50 +0800 Subject: [PATCH 06/30] test 403 --- app/controllers/shixuns_controller.rb | 1 + app/controllers/users_controller.rb | 2 ++ app/views/shixuns/show_right.json.jbuilder | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 499bd0aa4..e47064e24 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -118,6 +118,7 @@ class ShixunsController < ApplicationController #@fans_count = owner.followers.count #@followed_count = owner.followed_users.count @user_own_shixuns = owner.shixuns.published.count + uid_logger_error("777777777777777777") end # 排行榜 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d01973175..d65675aac 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -15,6 +15,7 @@ class UsersController < ApplicationController def get_user_info begin @user = current_user + uid_logger_error("############{@user.id}") # TODO 等消息上线再打开注释 #@tidding_count = unviewed_tiddings(current_user) if current_user.present? @course = @@ -37,6 +38,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 diff --git a/app/views/shixuns/show_right.json.jbuilder b/app/views/shixuns/show_right.json.jbuilder index 8f4679a37..e3414df55 100644 --- a/app/views/shixuns/show_right.json.jbuilder +++ b/app/views/shixuns/show_right.json.jbuilder @@ -1,4 +1,4 @@ -json.partial! 'shixuns/right', locals: { shixun: @shixun } +# json.partial! 'shixuns/right', locals: { shixun: @shixun } #json.follow follow?(@shixun.owner, User.current) #json.fans_count @fans_count From ba91ae106fd018ff23fe8f5d9749ab3fa175fee0 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 09:17:17 +0800 Subject: [PATCH 07/30] 403 problem --- app/controllers/application_controller.rb | 2 +- app/controllers/shixuns_controller.rb | 1 - app/controllers/users_controller.rb | 7 ++++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 98dd577a1..d9b6f5b6b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index e47064e24..499bd0aa4 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -118,7 +118,6 @@ class ShixunsController < ApplicationController #@fans_count = owner.followers.count #@followed_count = owner.followed_users.count @user_own_shixuns = owner.shixuns.published.count - uid_logger_error("777777777777777777") end # 排行榜 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d65675aac..90e2d3a62 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -14,8 +14,8 @@ class UsersController < ApplicationController # 贴吧获取用户信接口 def get_user_info begin - @user = current_user - uid_logger_error("############{@user.id}") + @user = User.find(12) + # @user = current_user # TODO 等消息上线再打开注释 #@tidding_count = unviewed_tiddings(current_user) if current_user.present? @course = @@ -55,7 +55,8 @@ class UsersController < ApplicationController # Redo: 消息总数缓存 def get_navigation_info @old_domain = edu_setting('old_edu_host') - @user = current_user + # @user = current_user + @user = User.find(12) # 新消息数 @new_message = @user.tidings.where("created_at > '#{@user.click_time}'").count > 0 || @user.private_messages.where("created_at > '#{@user.click_time}'").count > 0 From 15e27382094e4be0addf684baadbd03084fca8b2 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 09:25:01 +0800 Subject: [PATCH 08/30] start --- app/controllers/users_controller.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 90e2d3a62..9c9d7411c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -14,8 +14,7 @@ class UsersController < ApplicationController # 贴吧获取用户信接口 def get_user_info begin - @user = User.find(12) - # @user = current_user + @user = current_user # TODO 等消息上线再打开注释 #@tidding_count = unviewed_tiddings(current_user) if current_user.present? @course = @@ -55,8 +54,7 @@ class UsersController < ApplicationController # Redo: 消息总数缓存 def get_navigation_info @old_domain = edu_setting('old_edu_host') - # @user = current_user - @user = User.find(12) + @user = current_user # 新消息数 @new_message = @user.tidings.where("created_at > '#{@user.click_time}'").count > 0 || @user.private_messages.where("created_at > '#{@user.click_time}'").count > 0 From c216cfd44b785c1506a040eb045e44762766a8ba Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 10:35:43 +0800 Subject: [PATCH 09/30] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E5=88=9B=E5=BB=BA=E5=88=99=E5=92=8C=E6=8E=A8?= =?UTF-8?q?=E8=8D=90=E5=AE=9E=E8=AE=AD=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/show_right.json.jbuilder | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/shixuns/show_right.json.jbuilder b/app/views/shixuns/show_right.json.jbuilder index e3414df55..fe3c5d0f5 100644 --- a/app/views/shixuns/show_right.json.jbuilder +++ b/app/views/shixuns/show_right.json.jbuilder @@ -1,6 +1,6 @@ -# json.partial! 'shixuns/right', locals: { shixun: @shixun } +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 From db081f1f3b6bf09b9ad5110b28acd8c3c444aeac Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 10:47:40 +0800 Subject: [PATCH 10/30] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=9D=83=E9=99=90?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 3 +-- app/models/user.rb | 17 +++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 499bd0aa4..165b570fc 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -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 :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,7 +710,6 @@ 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 diff --git a/app/models/user.rb b/app/models/user.rb index ece69dc02..a877b2b90 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -386,13 +386,18 @@ 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 status + when -1 # 软删除只有管理员能访问 + admin? + when 0, 1, 3 # 申请发布或者已关闭的实训,只有实训管理员可以访问 + manager_of_shixun?(shixun) + when 2 + shixun.use_scope == 0 || (manager_of_shixun?(shixun) || shixun.shixun_schools.exists?(school_id: school_id)) + end end # 用户在平台名称的显示方式 From 5bf0be607a6d373008bf1cce416b5a91e807b077 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 10:52:08 +0800 Subject: [PATCH 11/30] git request --- app/controllers/gits_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index 778963f6e..4351bf602 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -4,6 +4,7 @@ class GitsController < ApplicationController def auth # HTTP_AUTHORIZATION: "Basic 这里base64编码的的密码(user:passwd)" logger.info("11111112222223333#{request.env["HTTP_AUTHORIZATION"]}") + logger.info("11111112222223333: request is #{request}") #logger.info("#########-----request_env: #{request.env}") # {"service"=>"git-receive-pack", "controller"=>"gits", "action"=>"auth", # "url"=>"forge01/cermyt39.git/info/refs"} From d9001276227bc6ec184b5bb11eca9896b1ce6b93 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 10:59:18 +0800 Subject: [PATCH 12/30] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E7=9A=84=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 165b570fc..6dfa94252 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -715,7 +715,7 @@ private 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 From 709fbcda0437a6c6086a579034f5bf5d63634d97 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 11:03:35 +0800 Subject: [PATCH 13/30] http auth --- app/controllers/gits_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index 4351bf602..92451d655 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -4,7 +4,7 @@ class GitsController < ApplicationController def auth # HTTP_AUTHORIZATION: "Basic 这里base64编码的的密码(user:passwd)" logger.info("11111112222223333#{request.env["HTTP_AUTHORIZATION"]}") - logger.info("11111112222223333: request is #{request}") + 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"} From eee76b604ee2a7a1a85351ce6527ef7f7910e943 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 11:10:28 +0800 Subject: [PATCH 14/30] git passsword --- app/controllers/gits_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index 92451d655..e5d33acab 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -3,7 +3,7 @@ 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", @@ -20,7 +20,9 @@ class GitsController < ApplicationController uid_logger("git start auth: input_username is #{input_username}") # Git 超级权限用户 + logger.info("666666666: a: #{input_username}, b: #{gituser}, c #{input_password} , d #{gitpassword}}") if input_username == gituser && input_password == gitpassword + result = true else # 用户是否对对象拥有权限 From 283ee9e5398c8bbb9bd3ad94027af6893bfa8a45 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 11:13:38 +0800 Subject: [PATCH 15/30] git usrname strip --- app/controllers/gits_controller.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index e5d33acab..4064f0f99 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -20,9 +20,7 @@ class GitsController < ApplicationController uid_logger("git start auth: input_username is #{input_username}") # Git 超级权限用户 - logger.info("666666666: a: #{input_username}, b: #{gituser}, c #{input_password} , d #{gitpassword}}") - if input_username == gituser && input_password == gitpassword - + if input_username.strip == gituser.strip && input_password.strip == gitpassword.strip result = true else # 用户是否对对象拥有权限 From b004cb2e9960b2407dcd1d4ab99ff40ad56de1a7 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 11:14:57 +0800 Subject: [PATCH 16/30] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index a877b2b90..0177d71a2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -396,7 +396,7 @@ class User < ApplicationRecord when 0, 1, 3 # 申请发布或者已关闭的实训,只有实训管理员可以访问 manager_of_shixun?(shixun) when 2 - shixun.use_scope == 0 || (manager_of_shixun?(shixun) || shixun.shixun_schools.exists?(school_id: school_id)) + shixun.use_scope == 0 || manager_of_shixun?(shixun) || shixun.shixun_schools.exists?(school_id: school_id) end end From faac0e76aa708de34d60f0b03b8f4ca913aa896c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 13:56:06 +0800 Subject: [PATCH 17/30] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2055449_modify_shixun_info_for_shixuns.rb} | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) rename db/migrate/{20190605060799_modify_script_and_description_for_shixuninfo.rb => 20190622055449_modify_shixun_info_for_shixuns.rb} (77%) diff --git a/db/migrate/20190605060799_modify_script_and_description_for_shixuninfo.rb b/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb similarity index 77% rename from db/migrate/20190605060799_modify_script_and_description_for_shixuninfo.rb rename to db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb index 151d3c03e..30ea96d65 100644 --- a/db/migrate/20190605060799_modify_script_and_description_for_shixuninfo.rb +++ b/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb @@ -1,16 +1,18 @@ -class ModifyScriptAndDescriptionForShixuninfo < ActiveRecord::Migration[5.2] - def change - Shixun.find_each do |shixun| - if shixun.shixun_info - shixun.shixun_info.update_attributes(propaedeutics: shixun[:propaedeutics], - description: shixun[:description], - evaluate_script: shixun[:evaluate_script], - shixun_id: shixun[:id]) - else - ShixunInfo.create!(propaedeutics: shixun[:propaedeutics], description: shixun[:description], - evaluate_script: shixun[:evaluate_script], shixun_id: shixun.id) - end - end - remove_columns :shixuns, :description, :propaedeutics, :evaluate_script - end -end +class ModifyShixunInfoForShixuns < ActiveRecord::Migration[5.2] + def change + Shixun.find_each do |shixun| + if shixun.shixun_info + shixun.shixun_info.update_attributes(propaedeutics: shixun[:propaedeutics], + description: shixun[:description], + evaluate_script: shixun[:evaluate_script], + shixun_id: shixun[:id]) + else + ShixunInfo.create!(propaedeutics: shixun[:propaedeutics], description: shixun[:description], + evaluate_script: shixun[:evaluate_script], shixun_id: shixun.id) + end + end + if shixun.description.present? + remove_columns :shixuns, :description, :propaedeutics, :evaluate_script + end + end +end From 05cafcff8c49f8e236b2763a8ff63fbdf3018ece Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 13:57:58 +0800 Subject: [PATCH 18/30] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb b/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb index 30ea96d65..5b3ceada6 100644 --- a/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb +++ b/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb @@ -11,7 +11,7 @@ class ModifyShixunInfoForShixuns < ActiveRecord::Migration[5.2] evaluate_script: shixun[:evaluate_script], shixun_id: shixun.id) end end - if shixun.description.present? + if Shixun.first.description.present? remove_columns :shixuns, :description, :propaedeutics, :evaluate_script end end From db62c1d6c371c41a7206ce90a939be5a212b597a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 14:00:57 +0800 Subject: [PATCH 19/30] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E7=9A=84=E9=95=BF=E7=B1=BB=E5=9E=8B=E7=9A=84=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190622055449_modify_shixun_info_for_shixuns.rb | 3 --- .../20190622060005_remove_shixun_long_text_for_shixuns.rb | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20190622060005_remove_shixun_long_text_for_shixuns.rb diff --git a/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb b/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb index 5b3ceada6..1a3aa147b 100644 --- a/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb +++ b/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb @@ -11,8 +11,5 @@ class ModifyShixunInfoForShixuns < ActiveRecord::Migration[5.2] evaluate_script: shixun[:evaluate_script], shixun_id: shixun.id) end end - if Shixun.first.description.present? - remove_columns :shixuns, :description, :propaedeutics, :evaluate_script - end end end diff --git a/db/migrate/20190622060005_remove_shixun_long_text_for_shixuns.rb b/db/migrate/20190622060005_remove_shixun_long_text_for_shixuns.rb new file mode 100644 index 000000000..bcc8a2bce --- /dev/null +++ b/db/migrate/20190622060005_remove_shixun_long_text_for_shixuns.rb @@ -0,0 +1,7 @@ +class RemoveShixunLongTextForShixuns < ActiveRecord::Migration[5.2] + def change + if Shixun.first.description.present? + remove_columns :shixuns, :description, :propaedeutics, :evaluate_script + end + end +end From 899c7fb673408e839febe7b9720af7bee9c2a8d9 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 14:08:45 +0800 Subject: [PATCH 20/30] =?UTF-8?q?=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190622060005_remove_shixun_long_text_for_shixuns.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190622060005_remove_shixun_long_text_for_shixuns.rb b/db/migrate/20190622060005_remove_shixun_long_text_for_shixuns.rb index bcc8a2bce..4557c610f 100644 --- a/db/migrate/20190622060005_remove_shixun_long_text_for_shixuns.rb +++ b/db/migrate/20190622060005_remove_shixun_long_text_for_shixuns.rb @@ -1,6 +1,6 @@ class RemoveShixunLongTextForShixuns < ActiveRecord::Migration[5.2] def change - if Shixun.first.description.present? + if Shixun.first.has_attribute?(:description) remove_columns :shixuns, :description, :propaedeutics, :evaluate_script end end From 9642805db14358b21777ead1bf681fd0e84c9565 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 14:45:25 +0800 Subject: [PATCH 21/30] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E8=B6=85=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index aa0a0f171..9c71b82e2 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -429,7 +429,7 @@ class StudentWorksController < ApplicationController def shixun_work_report @user = @work.user @shixun = @homework.shixuns.take - @games = @work.myshixun.games.includes(:challenge, :game_codes,:outputs) if @work.myshixun + @games = @work.myshixun.games.includes(:challenge) if @work.myshixun # 用户最大评测次数 @user_evaluate_count = @games.inject(0){|sum, g| sum + g.outputs.pluck(:query_index).first.to_i } if @games From f630266141e4d7e51b6ba93e400fadd8518257d9 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 14:48:47 +0800 Subject: [PATCH 22/30] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 9c71b82e2..213ea40c0 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -432,7 +432,7 @@ class StudentWorksController < ApplicationController @games = @work.myshixun.games.includes(:challenge) 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 @@ -440,10 +440,10 @@ class StudentWorksController < ApplicationController def export_shixun_work_report @user = @work.user @shixun = @homework.shixuns.take - @games = @work.myshixun.games.includes(:challenge, :game_codes,:outputs) if @work.myshixun + @games = @work.myshixun.games.includes(:challenge, :game_codes) 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 } From c0df2b017f72371bbefc2027168682b2da16b609 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 22 Jun 2019 14:52:10 +0800 Subject: [PATCH 23/30] =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190621105144_sync_ivalid_users.rb | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/db/migrate/20190621105144_sync_ivalid_users.rb b/db/migrate/20190621105144_sync_ivalid_users.rb index 3520ca84d..f2875977f 100644 --- a/db/migrate/20190621105144_sync_ivalid_users.rb +++ b/db/migrate/20190621105144_sync_ivalid_users.rb @@ -1,34 +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 + # 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 From 980cb9e730545abc7827f442a19f4f1e4441e850 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 14:54:05 +0800 Subject: [PATCH 24/30] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=8A=A5=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 213ea40c0..9e3a1930c 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -429,7 +429,7 @@ class StudentWorksController < ApplicationController def shixun_work_report @user = @work.user @shixun = @homework.shixuns.take - @games = @work.myshixun.games.includes(:challenge) if @work.myshixun + @games = @work.myshixun.games.includes(:challenge, :game_codes, :outputs) if @work.myshixun # 用户最大评测次数 @user_evaluate_count = @games.sum(:evaluate_count) if @games @@ -440,7 +440,7 @@ class StudentWorksController < ApplicationController def export_shixun_work_report @user = @work.user @shixun = @homework.shixuns.take - @games = @work.myshixun.games.includes(:challenge, :game_codes) if @work.myshixun + @games = @work.myshixun.games.includes(:challenge, :game_codes, :outputs) if @work.myshixun # 用户最大评测次数 @user_evaluate_count = @games.sum(:evaluate_count) if @games From 2bbd5dcc2456a81a64aa7ca8aa547ed019f0d89f Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 14:59:45 +0800 Subject: [PATCH 25/30] .. --- db/migrate/20190622065825_add_profile_completed_to_uses.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 db/migrate/20190622065825_add_profile_completed_to_uses.rb diff --git a/db/migrate/20190622065825_add_profile_completed_to_uses.rb b/db/migrate/20190622065825_add_profile_completed_to_uses.rb new file mode 100644 index 000000000..ef2cc2bf2 --- /dev/null +++ b/db/migrate/20190622065825_add_profile_completed_to_uses.rb @@ -0,0 +1,5 @@ +class AddProfileCompletedToUses < ActiveRecord::Migration[5.2] + def change + add_column :users, :profile_completed, :boolean, default: false + end +end From 1f3ab3645d46e3c8d200caae088b1db1d3979aa2 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 15:00:17 +0800 Subject: [PATCH 26/30] reset --- db/migrate/20190622065825_add_profile_completed_to_uses.rb | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 db/migrate/20190622065825_add_profile_completed_to_uses.rb diff --git a/db/migrate/20190622065825_add_profile_completed_to_uses.rb b/db/migrate/20190622065825_add_profile_completed_to_uses.rb deleted file mode 100644 index ef2cc2bf2..000000000 --- a/db/migrate/20190622065825_add_profile_completed_to_uses.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddProfileCompletedToUses < ActiveRecord::Migration[5.2] - def change - add_column :users, :profile_completed, :boolean, default: false - end -end From 620539b9247b47847171910730e4c88c7f60d8f7 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 22 Jun 2019 15:18:24 +0800 Subject: [PATCH 27/30] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index ec3f0ab9a..e4ed35b4b 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -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" From c4c93fb0e1445960e972cb78615c5897f561e15e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 15:20:33 +0800 Subject: [PATCH 28/30] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/_shixun.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shixuns/_shixun.json.jbuilder b/app/views/shixuns/_shixun.json.jbuilder index 6913c4745..ebc0c520d 100644 --- a/app/views/shixuns/_shixun.json.jbuilder +++ b/app/views/shixuns/_shixun.json.jbuilder @@ -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 From 112281a3a10a9143fa16bf25a56e195244f931db Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 15:33:40 +0800 Subject: [PATCH 29/30] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=9D=83=E9=99=90?= =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 0177d71a2..0d5517c50 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -390,13 +390,17 @@ class User < ApplicationRecord # 2、实训隐藏了只有管理员、实训合作者能看到 # 3、如果有限制学校范围,则学校的用户、管理员、实训合作者能看到 def shixun_permission(shixun) - case status + case shixun.status when -1 # 软删除只有管理员能访问 admin? when 0, 1, 3 # 申请发布或者已关闭的实训,只有实训管理员可以访问 manager_of_shixun?(shixun) when 2 - shixun.use_scope == 0 || manager_of_shixun?(shixun) || shixun.shixun_schools.exists?(school_id: school_id) + 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 From 8f3584733e062c98da1074ac910a4bbc9b7bb976 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 15:49:11 +0800 Subject: [PATCH 30/30] =?UTF-8?q?=E9=98=BF=E9=87=8C=E4=BA=91=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/_top.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shixuns/_top.json.jbuilder b/app/views/shixuns/_top.json.jbuilder index ef15e2515..ebb77ec74 100644 --- a/app/views/shixuns/_top.json.jbuilder +++ b/app/views/shixuns/_top.json.jbuilder @@ -1,4 +1,4 @@ -json.status shixun.status +json.shixun_status shixun.status # REDO:前端需要通过status来判断发布 json.task_operation task_operation_url(current_myshixun, shixun)