From 114d78255802c69b324f8da62c81b881a392fa2a Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 13 Dec 2019 11:53:43 +0800 Subject: [PATCH 1/3] RequestStore for current user and current laboratory --- Gemfile | 3 +++ app/controllers/application_controller.rb | 2 +- app/models/laboratory.rb | 14 +++++++++++--- app/models/user.rb | 12 ++++++++++-- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 55030971d..55478816f 100644 --- a/Gemfile +++ b/Gemfile @@ -103,3 +103,6 @@ gem 'diffy' # oauth2 gem 'omniauth', '~> 1.9.0' gem 'omniauth-oauth2', '~> 1.6.0' + +# global var +gem 'request_store' diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3ec8ad0f7..b3a0e123a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -303,7 +303,7 @@ class ApplicationController < ActionController::Base current_domain_session = session[:"#{default_yun_session}"] if current_domain_session # existing session - (User.active.find(current_domain_session) rescue nil) + User.current = (User.active.find(current_domain_session) rescue nil) elsif autologin_user = try_to_autologin autologin_user elsif params[:format] == 'atom' && params[:key] && request.get? && accept_rss_auth? diff --git a/app/models/laboratory.rb b/app/models/laboratory.rb index 2ba86ed90..dab2f6f39 100644 --- a/app/models/laboratory.rb +++ b/app/models/laboratory.rb @@ -38,12 +38,20 @@ class Laboratory < ApplicationRecord find_by_identifier(subdomain) end - def self.current=(laboratory) - Thread.current[:current_laboratory] = laboratory + # def self.current=(laboratory) + # Thread.current[:current_laboratory] = laboratory + # end + # + # def self.current + # Thread.current[:current_laboratory] ||= Laboratory.find(1) + # end + + def self.current=(user) + RequestStore.store[:current_laboratory] = user end def self.current - Thread.current[:current_laboratory] ||= Laboratory.find(1) + RequestStore.store[:current_laboratory] ||= User.anonymous end def shixuns diff --git a/app/models/user.rb b/app/models/user.rb index eb3ece0a4..a9b2f0b3a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -540,12 +540,20 @@ class User < ApplicationRecord mail.present? end + # def self.current=(user) + # Thread.current[:current_user] = user + # end + # + # def self.current + # Thread.current[:current_user] ||= User.anonymous + # end + def self.current=(user) - Thread.current[:current_user] = user + RequestStore.store[:current_user] = user end def self.current - Thread.current[:current_user] ||= User.anonymous + RequestStore.store[:current_user] ||= User.anonymous end def self.anonymous From 331f3bdea1ba1a3b5f910ec656396d353f797a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Fri, 13 Dec 2019 15:42:22 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/courses/busyWork/CommonWorkItem.js | 15 ++++++++------- .../courses/shixunHomework/ShixunhomeWorkItem.js | 8 -------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/public/react/src/modules/courses/busyWork/CommonWorkItem.js b/public/react/src/modules/courses/busyWork/CommonWorkItem.js index 75676557a..82e2d2d96 100644 --- a/public/react/src/modules/courses/busyWork/CommonWorkItem.js +++ b/public/react/src/modules/courses/busyWork/CommonWorkItem.js @@ -205,15 +205,16 @@ class CommonWorkItem extends Component{ {item.uncommit_count===undefined?"":{item.uncommit_count} 未交} { item.status_time!="" && - + {item.status_time} - - } + } + {/**/} + {/**/} {isAdmin &&
{ this.props.toEditPage(this.props.match.params, item.homework_id) }}>编辑 { this.props.toWorkSettingPage(this.props.match.params, item.homework_id) }}>设置 diff --git a/public/react/src/modules/courses/shixunHomework/ShixunhomeWorkItem.js b/public/react/src/modules/courses/shixunHomework/ShixunhomeWorkItem.js index dc59d93ed..f5f06c037 100644 --- a/public/react/src/modules/courses/shixunHomework/ShixunhomeWorkItem.js +++ b/public/react/src/modules/courses/shixunHomework/ShixunhomeWorkItem.js @@ -393,21 +393,13 @@ class ShixunhomeWorkItem extends Component{ { discussMessage.time_status===1? - {discussMessage.status_time} - :discussMessage.time_status===2? - {discussMessage.status_time} - :discussMessage.time_status===3? - {discussMessage.status_time} - :discussMessage.time_status===4? - {discussMessage.status_time} - : {discussMessage.status_time} } From 75634252cea448b34efb1efa376b3a95dfdcd3ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Fri, 13 Dec 2019 15:48:17 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=BC=80=E6=94=BE=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E6=8A=A5=E5=91=8A=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/modules/courses/shixunHomework/ShixunWorkReport.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/react/src/modules/courses/shixunHomework/ShixunWorkReport.js b/public/react/src/modules/courses/shixunHomework/ShixunWorkReport.js index 23f590dcd..1bf7ac181 100644 --- a/public/react/src/modules/courses/shixunHomework/ShixunWorkReport.js +++ b/public/react/src/modules/courses/shixunHomework/ShixunWorkReport.js @@ -366,10 +366,10 @@ class ShixunWorkReport extends Component {

{data&&data.shixun_name}

{/*{this.props.isAdmin()?导出实训报告数据:""}*/} 返回 - {this.props.isAdmin() ? this.confirmysl(`/student_works/${homeworkid}/export_shixun_work_report.pdf`)} - > 导出实训报告数据 : ""} + > 导出实训报告数据 {/*{this.props.isAdmin() ?work_comment_hidden===true? "":this.showAppraiseModal(1)}*/}