实训审核问题

competitions
daiao 5 years ago
parent cb28d59308
commit 2d3d94eafb

@ -14,7 +14,7 @@ class ShixunsController < ApplicationController
before_action :shixun_access_allowed, except: [:index, :new, :create, :menus, :get_recommend_shixuns,
:propaedeutics, :departments, :apply_shixun_mirror,
:get_mirror_script, :download_file, :shixun_list]
:get_mirror_script, :download_file, :shixun_list, :review_shixuns]
before_action :find_repo_name, only: [:repository, :commits, :file_content, :update_file, :shixun_exec, :copy, :add_file]
before_action :allowed, only: [:update, :close, :update_propaedeutics, :settings, :publish,
@ -986,6 +986,20 @@ class ShixunsController < ApplicationController
@shixun.update_column(:status, 0)
end
# 创建实训审核
def review_shixuns
validate_review_shixun_params
# 没有记录就创建记录, 如果有记录就
@shixun.shixun_reviews.create!(user_id: current_user.id, status: params[:status],
review_type: params[:review_type], evaluate_content: params[:evaluate_content])
end
# 实训审核最新记录
def review_newest_record
@content_record = @shixun.shixun_reviews.where(review_type: "Content").first
@perfer_record = @shixun.shixun_reviews.where(review_type: "Performance").first
end
private
def shixun_params
raise("实训名称不能为空") if params[:shixun][:name].blank?
@ -994,6 +1008,11 @@ private
:hide_code, :forbid_copy, :vnc_evaluate, :code_edit_permission)
end
def validate_review_shixun_params
tip_exception("只有平台管理员或运营人员才能审核") if !admin_or_business?
tip_exception("审核类型参数不对") unless ["Content", "Performance"].include?(params[:review_type])
end
def shixun_info_params
raise("实训描述不能为空") if params[:shixun_info][:description].blank?
raise("评测脚本不能为空") if params[:shixun_info][:evaluate_script].blank?

@ -47,6 +47,9 @@ class Shixun < ApplicationRecord
has_many :shixun_service_configs, :dependent => :destroy
has_many :tidings, as: :container, dependent: :destroy
# 实训审核记录
has_many :shixun_reviews, -> {order("challenges.created_at desc")}, :dependent => :destroy
scope :search_by_name, ->(keyword) { where("name like ? or description like ? ",
"%#{keyword}%", "%#{keyword}%") }

@ -0,0 +1,4 @@
class ShixunReview < ApplicationRecord
belongs_to :user
belongs_to :shixun
end

@ -0,0 +1,16 @@
if @content_record
json.content_info @content_record do
json.status @content_record.status
json.time format_time(@content_record.created_at)
json.username @content_record.user&.real_name
end
end
if @perfer_record
json.perference_info @perfer_record do
json.status @perfer_record.status
json.time format_time(@perfer_record.created_at)
json.username @perfer_record.user&.real_name
end
end

@ -221,6 +221,7 @@ Rails.application.routes.draw do
get :cancel_publish
get :publish
get :shixun_exec
post :review_shixuns
end
resources :challenges do

@ -0,0 +1,12 @@
class CreateShixunReviews < ActiveRecord::Migration[5.2]
def change
create_table :shixun_reviews do |t|
t.references :user
t.references :shixun
t.string :evaluate_content
t.integer :status
t.string :review_type
t.timestamps
end
end
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe ShixunReview, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save