Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flag status on waffle_status endpoint is not properly shown #496

Open
SoundWaveX81 opened this issue Dec 22, 2023 · 0 comments
Open

flag status on waffle_status endpoint is not properly shown #496

SoundWaveX81 opened this issue Dec 22, 2023 · 0 comments

Comments

@SoundWaveX81
Copy link

SoundWaveX81 commented Dec 22, 2023

I have created this flag:

waffle admin config

I'm trying to get the flag status using the waffle_status endpoint, but no matter if the user is logged or not I get the same response:

{
    "flags": {
        "test_flag": {
            "is_active": false,
            "last_modified": "2023-12-21T16:03:38.922Z"
        }
    },
    "switches": {},
    "samples": {}
}

It is supposed that I have to get this flag as True for the user farid, the one with id 1, isn't?

I made this exercise using django 4, django-waffle 4.1.0, and I have made this configs on settings.py

.
.
.
INSTALLED_APPS = [
    'django.contrib.admin',
    'rest_framework',
    'rest_framework.authtoken',
    'django.contrib.auth',
    'waffle',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'exammple'
]
.
.
.

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'waffle.middleware.WaffleMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
.
.
.
REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticated',
    ]
}
.
.
.

and in project's url.py file

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/v1/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
    path('api/v1/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
    path(
        'api/v1/', include(
            [
                path('', include(example_urls))
            ]
        )
    ),
    path('waffle/', include('waffle.urls')),
]

Is this a bug/missing feature on waffle? or I'm missing some config in somewhere?

P.S. The purpose of this is that I have to give this flag status to a FrontEnd app to show or hide some visual components depending on the flag's status.

I've tried mixing configs on django admin, and settings.py, and the expected result is that the waffle_status endpoint returns True if the user who made the request is in the added ones on the flag config, otherwise has to return False

UPDATE1: I did clone the repo of the django-waffle project and I wrote this test:

 def test_waffle_json_user_flag(self):
        user = get_user_model().objects.create(username='someone_else')
        flag = waffle.get_waffle_flag_model().objects.create(name='myflag')
        flag.users.add(user)
        self.client.force_login(user=user)
        response = self.client.get(reverse('waffle_status'))
        content = response.json()
        self.assertTrue(content['flags']['myflag']['is_active'])

        another_user = get_user_model().objects.create(username='another_one')
        self.client.force_login(user=another_user)
        another_response = self.client.get(reverse('waffle_status'))
        another_content = another_response.json()
        self.assertFalse(another_content['flags']['myflag']['is_active'])

It passed successfully!

Then I ran the django server on the project, I did create a flag and bind a user to it. I did tests using postman and I get the same issue as described above.

Doing some debug on the waffle_status view on waffle-django package, I saw that the request returned has no user, I meant if I dig into request.user i saw AnonymousUser so, what I'm missing here?

@SoundWaveX81 SoundWaveX81 changed the title lag status on waffle_status endpoint is not properly shown flag status on waffle_status endpoint is not properly shown Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant