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 + diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 89b3ed5d8..1915281bf 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/gits_controller.rb b/app/controllers/gits_controller.rb index 778963f6e..4064f0f99 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -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 # 用户是否对对象拥有权限 diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index a9843a5cc..6217b08c3 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" diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 32a314c54..6dfa94252 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 :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 diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index aa0a0f171..9e3a1930c 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -429,10 +429,10 @@ 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, :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 @@ -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, :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 } diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 408e73fa5..888e212e3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index ece69dc02..0d5517c50 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 # 用户在平台名称的显示方式 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 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) diff --git a/app/views/shixuns/show_right.json.jbuilder b/app/views/shixuns/show_right.json.jbuilder index 8f4679a37..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.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 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 = { diff --git a/db/migrate/20190505092009_delete_ivalid_data.rb b/db/migrate/20190505092009_delete_ivalid_data.rb deleted file mode 100644 index 98f13d9e4..000000000 --- a/db/migrate/20190505092009_delete_ivalid_data.rb +++ /dev/null @@ -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 diff --git a/db/migrate/20190621105144_sync_ivalid_users.rb b/db/migrate/20190621105144_sync_ivalid_users.rb new file mode 100644 index 000000000..f2875977f --- /dev/null +++ b/db/migrate/20190621105144_sync_ivalid_users.rb @@ -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 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 78% 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..1a3aa147b 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,15 @@ -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 + 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..4557c610f --- /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.has_attribute?(:description) + remove_columns :shixuns, :description, :propaedeutics, :evaluate_script + end + end +end 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