Skip to content

Commit

Permalink
fix: do flask stuff only when flask
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Jul 12, 2024
1 parent 7290523 commit 366e108
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions api/waffle/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from framework.auth.core import _get_current_user
from osf import features
from flask import request
import flask


class MockUser(object):
Expand All @@ -13,18 +13,21 @@ def flag_is_active(request, flag_name):
"""
This function changes the typical flask request object so it can be used by django-waffle. Other modifications for
django-waffle can be found in the __call__ method of OsfWebRenderer.
:param flask request object:
:return flask request object:
:param request (flask or django):
:param flag name (string):
:return bool:
"""
# Waffle does not enjoy NoneTypes as user values.
request.user = _get_current_user() or MockUser()
request.COOKIES = getattr(request, 'cookies', None)
if isinstance(request, flask.Request):
# Waffle does not enjoy NoneTypes as user values.
request.user = _get_current_user() or MockUser()
request.COOKIES = getattr(request, 'cookies', None)
return waffle.flag_is_active(request, flag_name)


def storage_i18n_flag_active():
return flag_is_active(request, features.STORAGE_I18N)
return flag_is_active(flask.request, features.STORAGE_I18N)


def storage_usage_flag_active():
return flag_is_active(request, features.STORAGE_USAGE)
return flag_is_active(flask.request, features.STORAGE_USAGE)

0 comments on commit 366e108

Please sign in to comment.