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

Feature/46 admin sessions #73

Merged
merged 4 commits into from
Oct 25, 2024
Merged

Feature/46 admin sessions #73

merged 4 commits into from
Oct 25, 2024

Conversation

Coperh
Copy link
Contributor

@Coperh Coperh commented Sep 20, 2024

Fixes #46

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah

@Coperh Coperh force-pushed the feature/46-admin-sessions branch 2 times, most recently from 2d0b8d0 to 8a65aee Compare September 24, 2024 08:18
@Coperh Coperh force-pushed the feature/46-admin-sessions branch from 8a65aee to 14afa0a Compare October 11, 2024 12:25
@Coperh Coperh force-pushed the feature/46-admin-sessions branch from 14afa0a to bf1f086 Compare October 11, 2024 14:55
@Coperh Coperh force-pushed the feature/46-admin-sessions branch from bf1f086 to 5565720 Compare October 15, 2024 15:39
@Coperh Coperh marked this pull request as ready for review October 15, 2024 15:42
list_display = ["session_key", "user", "exists"]

@property
def SessionStore(self):
Copy link
Contributor Author

@Coperh Coperh Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally set this in the _init_ but that is not called every time I ran a test and the cached version always used the database backend.

Is there a way to fix this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this caused by assigning the setting here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably because the pytest fixtures change the SESSION_ENGINE after the __init__ is done, I'm not sure if there is way around this tbh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just use override_settings and it works as usual :/

tests/factories.py Outdated Show resolved Hide resolved
admin_user2 = admin_user


def test_only_session_profile_of_user_shown(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might still be possible to see the detail or delete view for another users session

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked this and it is not possible to go to the detail view for other user's sessions, not sure about deleting though. Can you add tests for this?

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that intended behavior? Either way would be nice to have tests that verify this (whether it is intended or not).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is intended on my end that you can only see you're own sessions. IDK if this is the correct message, do we want users to know other sessions exist?

I do not think it is in scope that a super admin user can see all sessions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current message is fine, because it does not give users extra information about other user's session. Just adding tests to verify that other users cant access/delete other session is enough in my opinion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs an assertion that deleting other users sessions is not possible, but might be nicer to move that to a separate test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now done

@Coperh
Copy link
Contributor Author

Coperh commented Oct 15, 2024

Still has the issue where it saves the SessionProfile when sending in the request to delete

tests/conftest.py Outdated Show resolved Hide resolved
testapp/settings.py Show resolved Hide resolved
admin_user2 = admin_user


def test_only_session_profile_of_user_shown(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked this and it is not possible to go to the detail view for other user's sessions, not sure about deleting though. Can you add tests for this?

image

open_api_framework/admin.py Outdated Show resolved Hide resolved
open_api_framework/admin.py Show resolved Hide resolved
list_display = ["session_key", "user", "exists"]

@property
def SessionStore(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably because the pytest fixtures change the SESSION_ENGINE after the __init__ is done, I'm not sure if there is way around this tbh

list_display = ["session_key", "user", "exists"]

@property
def SessionStore(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this caused by assigning the setting here?

tests/test_admin.py Outdated Show resolved Hide resolved
admin_user2 = admin_user


def test_only_session_profile_of_user_shown(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that intended behavior? Either way would be nice to have tests that verify this (whether it is intended or not).

tests/factories.py Outdated Show resolved Hide resolved

@pytest.fixture
def cache_session_store(settings):
settings.SESSION_ENGINE = "django.contrib.sessions.backends.cache"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these settings set directly because they are ran outside of a testcase provided by django (e.g django.test.TestCase)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The db session is not really necessary because its set in the settings.

I've removed both fixtures and replaced them with cache override in the cached version

tests/factories.py Outdated Show resolved Hide resolved
@Coperh Coperh force-pushed the feature/46-admin-sessions branch 2 times, most recently from 1ac629a to 25f3e5d Compare October 18, 2024 13:06
@Coperh Coperh requested review from stevenbal and SonnyBA October 18, 2024 13:23
Copy link
Contributor

@SonnyBA SonnyBA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there, would be nice if a test for deleting other users sessions is not possible

admin_user2 = admin_user


def test_only_session_profile_of_user_shown(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs an assertion that deleting other users sessions is not possible, but might be nicer to move that to a separate test

@Coperh Coperh force-pushed the feature/46-admin-sessions branch from 25f3e5d to b631bbf Compare October 18, 2024 14:31
@Coperh Coperh requested a review from SonnyBA October 18, 2024 14:34
tests/conftest.py Outdated Show resolved Hide resolved
@Coperh Coperh merged commit 70cc637 into main Oct 25, 2024
9 checks passed
@joeribekker joeribekker deleted the feature/46-admin-sessions branch November 19, 2024 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants