class SettingsController < ApplicationController def show @old_projects_url = nil get_navbar site_page_deploy_domain get_add_menu get_common_menu get_sub_competitions get_personal_menu get_third_party get_third_party_new get_top_system_notification end def check_url url = params[:url] task_id = params[:task] term = params[:term] return normal_status(-1, "缺少url参数") unless url.present? return normal_status(-1, "缺少term参数") unless term.present? return normal_status(-1, "缺少task参数") unless task_id.present? glcc_mate = GlccMediumTermExamineMaterial.new(code_or_pr_url: url, task_id: task_id, term: term, created_on:Time.now) state = glcc_mate.check_pr_url errors = glcc_mate.gennerate_content(state) render_ok({ state:state, state_html: errors}) end private def get_navbar @navbar = default_laboratory.navbar.sort_by{|e| e["index"].to_i } # if User.current.logged? # pernal_index = {"name"=>"个人主页", "link"=>get_site_url("url", "#{Rails.application.config_for(:configuration)['platform_url']}/current_user"), "hidden"=>false} # @navbar << pernal_index # end end def site_page_deploy_domain @deploy_domain = EduSetting.find_by_name("site_page_deploy_domain").try(:value) end def get_add_menu @add = [] Site.add.select(:id, :name, :url, :key).to_a.map(&:serializable_hash).each do |site| hash = {} site.each {|k, v| hash.merge!("#{k}": get_site_url(k, v)) } @add << hash end end def get_sub_competitions @sub_competitions = [] Site.competition.pluck(:key).uniq.each do |key| hash = {"identifier": "#{key.to_s}"} hash.merge!("list": Site.competition.where(key: key).select(:id, :name, :url, :key).to_a.map(&:serializable_hash)) @sub_competitions << hash end end def get_common_menu @common = {} Site.common.select(:url, :key).each do |site| next if site["url"].to_s.include?("current_user") && !User.current.logged? @common.merge!("#{site["key"]}": append_http(reset_site_url(site["url"]))) end end def get_personal_menu @personal = [] if User.current.logged? Site.personal.select(:id, :name, :url, :key).to_a.map(&:serializable_hash).each do |site| hash = {} site.each {|k, v| hash.merge!("#{k}": get_site_url(k, v)) } @personal << hash end end end def get_third_party @third_party = [] @third_party << { name: 'educoder', url: EducoderOauth.oauth_url } end def get_third_party_new @third_party_new = [] @third_party_new << { name: 'educoder', url: EducoderOauth.oauth_url, method: 'get' } platform_url = Rails.application.config_for(:configuration)['platform_url'] config = Rails.application.config_for(:configuration) (config.dig("oauth").keys - ["educoder", "wechat"]).each do |provider| @third_party_new << { name: provider, url: "#{platform_url}/auth/#{provider}", method: 'get' } end end def get_top_system_notification @top_system_notification = SystemNotification.is_top.first end def get_site_url(key, value) key.to_s === "url" ? append_http(reset_site_url(value)) : reset_site_url(value) end def reset_site_url(url) return url unless url.to_s.include?("current_user") split_arr = url.split('current_user') split_arr.length > 1 ? split_arr.join(current_user&.login) : (split_arr << current_user&.login).join('') end def append_http(url) url.to_s.start_with?("http") ? url : [request.protocol, request.host_with_port, url].join('') end end