From fe77865779b79b87b42843aa3484209325b71a3f Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 6 Jul 2019 09:01:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=AF=84=E6=B5=8B=E5=8A=A0=E5=85=A5sec=5Fk?= =?UTF-8?q?ey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 3 ++- app/controllers/gits_controller.rb | 9 +++++++-- app/controllers/myshixuns_controller.rb | 8 +++----- db/migrate/20190705085829_add_sec_key_to_outputs.rb | 5 +++++ 4 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20190705085829_add_sec_key_to_outputs.rb diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 7e7b6e082..41af7ae68 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -501,6 +501,7 @@ class GamesController < ApplicationController # 编程题评测 def game_build + sec_key = params[:sec_key] game_challenge = Challenge.select([:id, :position, :picture_path]).find(@game.challenge_id) # 更新评测次数 @@ -548,7 +549,7 @@ class GamesController < ApplicationController :instanceChallenge => "#{step}", :testCases => "#{testCases}", :resubmit => "#{resubmit}", :times => params[:first].to_i, :podType => @shixun.webssh, :content_modified => content_modified, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}", - :persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}", + :persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}", :sec_key => sec_key, :timeLimit => "#{@shixun.exec_time}", :isPublished => (@shixun.status < 2 ? 0 : 1) } # 评测有文件输出的需要特殊传字段 path:表示文件存储的位置 diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index f00245190..1965f61ba 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -1,10 +1,15 @@ class GitsController < ApplicationController - #供git-workhorse反向调用认证 + # 说明: + # 以下Git认证只针对新版git,Gitlab的Git认证不走该控制器 + # 思路: + # 1、用户通过Git客户端推送代码的时候,这个时候Git客户端肯定会强制用户输入邮箱的 + # 2、通过web端版本库界面更新代码(如果用户邮箱不存在,则用系统备用邮箱) + # 供 git-workhorse反向调用认证 def auth # HTTP_AUTHORIZATION: "Basic 这里base64编码的的密码(user:passwd)" logger.info("11111112222223333 HTTP_AUTHORIZATION: #{request.env["HTTP_AUTHORIZATION"]}") - #logger.info("#########-----request_env: #{request.env}") + # logger.info("#########-----request_env: #{request.env}") # {"service"=>"git-receive-pack", "controller"=>"gits", "action"=>"auth", # "url"=>"forge01/cermyt39.git/info/refs"} # diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 3abc71fd0..499612167 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -85,9 +85,6 @@ class MyshixunsController < ApplicationController # "createPod":"1.610","evaluateAllTime":2820,"evaluateStart":"2017-11-24 11:04:35","execute":"0.294"}' # params[:pics] = "a.png,b.png,c.png" def training_task_status - logger.info("123################{params[:jsonTestDetails]}") - logger.info("456################{params[:timeCost]}") - logger.info("666###############{params}") ActiveRecord::Base.transaction do begin @@ -98,13 +95,14 @@ class MyshixunsController < ApplicationController return_back_time = format("%.3f", ( t1.to_f - brige_end_time.to_f)).to_f status = jsonTestDetails['status'] game_id = jsonTestDetails['buildID'] + sec_key = jsonTestDetails['sec_key'] logger.info("training_task_status start#1**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") resubmit = jsonTestDetails['resubmit'] outPut = tran_base64_decode64(jsonTestDetails['outPut']) jenkins_testsets = jsonTestDetails['msg'] compile_success = jsonTestDetails['compileSuccess'] # message = Base64.decode64(params[:msg]) unless params[:msg].blank? - logger.info(outPut) + game = Game.find(game_id) myshixun = game.myshixun challenge = game.challenge @@ -125,7 +123,7 @@ class MyshixunsController < ApplicationController logger.info "actual_output:################################################# #{actual_output}" Output.create!(:code => status, :game_id => game_id, :out_put => outPut, :test_set_position => j_test_set['caseId'], :actual_output => actual_output, :result => j_test_set['passed'].to_i, :query_index => max_query_index, - :compile_success => compile_success.to_i) + :compile_success => compile_success.to_i, :sec_key => sec_key) # 如果设置了按测试集给分,则需要统计测试集的分值 if challenge.test_set_score && j_test_set['passed'].to_i == 1 test_set_score += challenge.test_sets.where(:position => j_test_set['caseId']).pluck(:score).first diff --git a/db/migrate/20190705085829_add_sec_key_to_outputs.rb b/db/migrate/20190705085829_add_sec_key_to_outputs.rb new file mode 100644 index 000000000..428fbaced --- /dev/null +++ b/db/migrate/20190705085829_add_sec_key_to_outputs.rb @@ -0,0 +1,5 @@ +class AddSecKeyToOutputs < ActiveRecord::Migration[5.2] + def change + add_column :outputs, :sec_key, :string + end +end From e6999da273e6b1850297ec1504d6bc16b6aed3e2 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 6 Jul 2019 09:19:47 +0800 Subject: [PATCH 2/2] user interest api --- app/controllers/users/interests_controller.rb | 25 +++++++++++++++++++ app/models/repertoire.rb | 1 + app/models/user.rb | 4 +++ app/models/user_interest.rb | 4 +++ config/routes.rb | 1 + .../20190706010307_create_user_interests.rb | 8 ++++++ 6 files changed, 43 insertions(+) create mode 100644 app/controllers/users/interests_controller.rb create mode 100644 app/models/user_interest.rb create mode 100644 db/migrate/20190706010307_create_user_interests.rb diff --git a/app/controllers/users/interests_controller.rb b/app/controllers/users/interests_controller.rb new file mode 100644 index 000000000..ca5f63af9 --- /dev/null +++ b/app/controllers/users/interests_controller.rb @@ -0,0 +1,25 @@ +class Users::InterestsController < Users::BaseController + before_action :require_login + before_action :private_user_resources! + + def create + identity = params[:identity].to_s.strip + + extension = observed_user.user_extension || observed_user.build_user_extension + return render_error('请选择职业') unless %w(teacher student professional).include?(identity) + + ActiveRecord::Base.transaction do + extension.update_column(:identity, identity) + + # 兴趣 + observed_user.user_interests.delete_all + UserInterest.bulk_insert(:user_id, :repertoire_id) do |worker| + (Repertoire.pluck(:id) & Array.wrap(params[:interest_ids]).map(&:to_i)).each do |repertoire_id| + worker.add(user_id: observed_user.id, repertoire_id: repertoire_id) + end + end + end + + render_ok + end +end \ No newline at end of file diff --git a/app/models/repertoire.rb b/app/models/repertoire.rb index d76a022c5..72e1ebfff 100644 --- a/app/models/repertoire.rb +++ b/app/models/repertoire.rb @@ -2,4 +2,5 @@ class Repertoire < ApplicationRecord has_many :sub_repertoires, ->{order(updated_at: :desc)}, :dependent => :destroy has_many :tag_repertoires, through: :sub_repertoires + has_many :user_interests, dependent: :delete_all end diff --git a/app/models/user.rb b/app/models/user.rb index e775af5f8..7e04ff423 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -115,6 +115,10 @@ class User < ApplicationRecord has_many :attendances + # 兴趣 + has_many :user_interests, dependent: :delete_all + has_many :interests, through: :user_interests, source: :repertoire + # Groups and active users scope :active, lambda { where(status: STATUS_ACTIVE) } diff --git a/app/models/user_interest.rb b/app/models/user_interest.rb new file mode 100644 index 000000000..bdb6e77d4 --- /dev/null +++ b/app/models/user_interest.rb @@ -0,0 +1,4 @@ +class UserInterest < ApplicationRecord + belongs_to :user + belongs_to :repertoire +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index cf5bad608..f0123d95b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -47,6 +47,7 @@ Rails.application.routes.draw do resource :experience_records, only: [:show] resource :grade_records, only: [:show] resource :watch, only: [:create, :destroy] + resource :interest, only: [:create] end diff --git a/db/migrate/20190706010307_create_user_interests.rb b/db/migrate/20190706010307_create_user_interests.rb new file mode 100644 index 000000000..d64a1c228 --- /dev/null +++ b/db/migrate/20190706010307_create_user_interests.rb @@ -0,0 +1,8 @@ +class CreateUserInterests < ActiveRecord::Migration[5.2] + def change + create_table :user_interests do |t| + t.references :user + t.references :repertoire + end + end +end