summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2019-05-06 10:33:52 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2019-05-06 10:33:52 +0000
commitd7eb886b9fd32ad2d0ab7bca9128dbb40e80c0da (patch)
treecb08813cb677cbd292d036bf18e2acfbbcd1be16 /lib
parent3f30ab5733843d1279d283ae98ab89b646f8f25d (diff)
parent5faa98f481e0f5e0ccb1758c34a104f523ab21d2 (diff)
downloadgitlab-ce-d7eb886b9fd32ad2d0ab7bca9128dbb40e80c0da.tar.gz
Merge branch 'jej/session-stored-globaly' into 'master'
Session stored globally per request See merge request gitlab-org/gitlab-ce!27658
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/namespaced_session_store.rb22
-rw-r--r--lib/gitlab/session.rb27
2 files changed, 49 insertions, 0 deletions
diff --git a/lib/gitlab/namespaced_session_store.rb b/lib/gitlab/namespaced_session_store.rb
new file mode 100644
index 00000000000..34520078bfb
--- /dev/null
+++ b/lib/gitlab/namespaced_session_store.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+module Gitlab
+ class NamespacedSessionStore
+ delegate :[], :[]=, to: :store
+
+ def initialize(key)
+ @key = key
+ end
+
+ def initiated?
+ !Session.current.nil?
+ end
+
+ def store
+ return unless Session.current
+
+ Session.current[@key] ||= {}
+ Session.current[@key]
+ end
+ end
+end
diff --git a/lib/gitlab/session.rb b/lib/gitlab/session.rb
new file mode 100644
index 00000000000..7487ba04a6d
--- /dev/null
+++ b/lib/gitlab/session.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+module Gitlab
+ class Session
+ STORE_KEY = :session_storage
+
+ class << self
+ def with_session(session)
+ old = self.current
+ self.current = session
+ yield
+ ensure
+ self.current = old
+ end
+
+ def current
+ Thread.current[STORE_KEY]
+ end
+
+ protected
+
+ def current=(value)
+ Thread.current[STORE_KEY] = value
+ end
+ end
+ end
+end