Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
09b3ad63
Commit
09b3ad63
authored
May 06, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
37b58383
d7eb886b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
103 additions
and
0 deletions
+103
-0
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+5
-0
lib/gitlab/namespaced_session_store.rb
lib/gitlab/namespaced_session_store.rb
+22
-0
lib/gitlab/session.rb
lib/gitlab/session.rb
+27
-0
spec/lib/gitlab/namespaced_session_store_spec.rb
spec/lib/gitlab/namespaced_session_store_spec.rb
+22
-0
spec/lib/gitlab/session_spec.rb
spec/lib/gitlab/session_spec.rb
+27
-0
No files found.
app/controllers/application_controller.rb
View file @
09b3ad63
...
...
@@ -27,6 +27,7 @@ class ApplicationController < ActionController::Base
before_action
:check_impersonation_availability
around_action
:set_locale
around_action
:set_session_storage
after_action
:set_page_title_header
,
if: :json_request?
after_action
:limit_unauthenticated_session_times
...
...
@@ -434,6 +435,10 @@ class ApplicationController < ActionController::Base
Gitlab
::
I18n
.
with_user_locale
(
current_user
,
&
block
)
end
def
set_session_storage
(
&
block
)
Gitlab
::
Session
.
with_session
(
session
,
&
block
)
end
def
set_page_title_header
# Per https://tools.ietf.org/html/rfc5987, headers need to be ISO-8859-1, not UTF-8
response
.
headers
[
'Page-Title'
]
=
URI
.
escape
(
page_title
(
'GitLab'
))
...
...
lib/gitlab/namespaced_session_store.rb
0 → 100644
View file @
09b3ad63
# 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
lib/gitlab/session.rb
0 → 100644
View file @
09b3ad63
# 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
spec/lib/gitlab/namespaced_session_store_spec.rb
0 → 100644
View file @
09b3ad63
# frozen_string_literal: true
require
'spec_helper'
describe
Gitlab
::
NamespacedSessionStore
do
let
(
:key
)
{
:some_key
}
subject
{
described_class
.
new
(
key
)
}
it
'stores data under the specified key'
do
Gitlab
::
Session
.
with_session
({})
do
subject
[
:new_data
]
=
123
expect
(
Thread
.
current
[
:session_storage
][
key
]).
to
eq
(
new_data:
123
)
end
end
it
'retrieves data from the given key'
do
Thread
.
current
[
:session_storage
]
=
{
key
=>
{
existing_data:
123
}
}
expect
(
subject
[
:existing_data
]).
to
eq
123
end
end
spec/lib/gitlab/session_spec.rb
0 → 100644
View file @
09b3ad63
# frozen_string_literal: true
require
'spec_helper'
describe
Gitlab
::
Session
do
it
'uses the current thread as a data store'
do
Thread
.
current
[
:session_storage
]
=
{
a: :b
}
expect
(
described_class
.
current
).
to
eq
(
a: :b
)
ensure
Thread
.
current
[
:session_storage
]
=
nil
end
describe
'#with_session'
do
it
'sets session hash'
do
described_class
.
with_session
(
one:
1
)
do
expect
(
described_class
.
current
).
to
eq
(
one:
1
)
end
end
it
'restores current store after'
do
described_class
.
with_session
(
two:
2
)
{
}
expect
(
described_class
.
current
).
to
eq
nil
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment