Skip to content

Commit

Permalink
fix: made session on the client side more predictable
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Jul 31, 2021
1 parent fbc3ffb commit cba9ddc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

*
* Made client side sessions more stable, by patching some global session related configurations

## [0.6.1] - 2021-07-31

Expand Down
13 changes: 13 additions & 0 deletions src/quorum/base.py
Expand Up @@ -421,6 +421,19 @@ def load(
config.confs("APPLICATION_ROOT", application_root)
config.confs("PREFERRED_URL_SCHEME", url_scheme)

# retrieves some internal configuration value related with
# the way that the session is going to be handled
session_cookie_path = config.conf("SESSION_COOKIE_PATH", "/")
session_cookie_secure = config.conf("SESSION_COOKIE_SECURE", False, cast = bool)
session_refresh_request = config.conf("SESSION_REFRESH_EACH_REQUEST", False, cast = bool)

# sets a series of session related values according to quorum
# predefined structure, this effectively enables sessions on
# the client side to be handled in a predictable manner
config.confs("SESSION_COOKIE_PATH", session_cookie_path)
config.confs("SESSION_COOKIE_SECURE", session_cookie_secure)
config.confs("SESSION_REFRESH_EACH_REQUEST", session_refresh_request)

# creates the proper values according to the currently provided
# ones so that they match the ones that are expected
name = name + "-" + instance if instance else name
Expand Down
8 changes: 4 additions & 4 deletions src/quorum/util.py
Expand Up @@ -239,13 +239,13 @@ def get_object(
# retrieves the reference to the form objects currently
# present in the request, note that in case a runtime
# error occurs (eg: out of context) fails gracefully
try: form_s = flask.request.form_s
try: form_s = flask.request.form_s #@UndefinedVariable
except RuntimeError: form_s = dict()

# retrieves the reference to the arguments objects currently
# present in the request, note that in case a runtime
# error occurs (eg: out of context) fails gracefully
try: args_s = flask.request.args_s
try: args_s = flask.request.args_s #@UndefinedVariable
except RuntimeError: args_s = dict()

# uses all the values referencing data in the request to try
Expand Down Expand Up @@ -726,7 +726,7 @@ def set_locale():
# normalizes the current locale string by converting the
# last part of the locale string to an uppercase representation
# and then re-joining the various components of it
values = flask.request.locale.split("_", 1)
values = flask.request.locale.split("_", 1) #@UndefinedVariable
if len(values) > 1: values[1] = values[1].upper()
locale_n = "_".join(values)
locale_n = str(locale_n)
Expand Down Expand Up @@ -965,7 +965,7 @@ def to_locale(value, locale = None, default = None, fallback = True):
) for value in value
])
has_context = common.base().has_context()
locale = locale or (flask.request.locale if has_context else None)
locale = locale or (flask.request.locale if has_context else None) #@UndefinedVariable
if locale:
bundle = common.base().get_bundle(locale) or {}
result = bundle.get(value, None)
Expand Down

0 comments on commit cba9ddc

Please sign in to comment.