Skip to content

Support for SU from Python - #84

Open
JulianGodd wants to merge 7 commits into
adamcharnock:developfrom
JulianGodd:develop
Open

Support for SU from Python#84
JulianGodd wants to merge 7 commits into
adamcharnock:developfrom
JulianGodd:develop

Conversation

@JulianGodd

Copy link
Copy Markdown

A Django app I'm working on surfaced the need to SU directly from python. Unfortunately, as Django doesn't support redirecting with POST and django-su's login_as_user view only allows POST requests, this isn't possible.

To enable this I moved a majority of the login_as_user function to a new function: su_in in utils.

This enables apps using django-su to optionally SU users without requiring logging in through Django's Admin app.

I chose this over allowing GET requests to login_as_user since that seemed to have security implications and made redirecting back to the original page more janky.

@coveralls

coveralls commented Oct 3, 2023

Copy link
Copy Markdown

Coverage Status

coverage: 93.312% (-1.1%) from 94.426% when pulling 46882fa on JulianGodd:develop into aadabf6 on adamcharnock:develop.

@JulianGodd

Copy link
Copy Markdown
Author

The error common to all 3 failing tests occurs when github actions uses typing_extensions version 4.8 which drops support for python 3.7.

  File "/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/typing_extensions-4.8.0-py3.7.egg/typing_extensions.py", line 874
    def TypedDict(typename, fields=_marker, /, *, total=True, **kwargs):
                                            ^
SyntaxError: invalid syntax

The error on the / character is for positional only arguments, a feature added in python 3.8

These errors are independent of django-su and not introduced by my pull request (no django-su code appears in the stack trace).

Thanks

@codecov-commenter

codecov-commenter commented Oct 18, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (aadabf6) 94.46% compared to head (46882fa) 93.31%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #84      +/-   ##
===========================================
- Coverage    94.46%   93.31%   -1.16%     
===========================================
  Files            9        9              
  Lines          307      314       +7     
===========================================
+ Hits           290      293       +3     
- Misses          17       21       +4     
Files Coverage Δ
django_su/views.py 90.24% <100.00%> (-0.50%) ⬇️
django_su/utils.py 87.80% <85.00%> (-2.68%) ⬇️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

- Made test_login_user_id_invalid actually check an invalid id
- added test_login_success_without_custom_login_action
- added test for auth.change_user permission check when calling su_in from user code
@JulianGodd

Copy link
Copy Markdown
Author

Can you rerun the github action? All of my changes since originally making the pull request have been to the github actions and automated testing. I've verified that they succeed on my fork.

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

Successfully merging this pull request may close these issues.

3 participants