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

Moving middleware user auth check to set_actor() #279

Closed
wants to merge 3 commits into from

Conversation

ndwhelan
Copy link

Move the check for whether the user is authenticated from before
registering set_actor() as the pre_save signal receiver
in to set_actor(). This enables two things:

  1. remote_addr in the LogEntry is set even if the user is
    not authenticated.
  2. This middleware no longer execute before the user is set
    on the request. Some frameworks may set this in a
    following middleware. Some frameworks, such as the widely
    adopeted Django Rest Framework do not set this as part
    of a middleware. So, the upshot of hit is that the
    actor will not be set when using Django Rest Framework.

Move the check for whether the user is authenticated from before
registering `set_actor()` as the `pre_save` signal receiver
in to `set_actor()`. This enables two things:

1. `remote_addr` in the `LogEntry` is set even if the user is
   not authenticated.
2. This middleware no longer execute before the user is set
   on the request. Some frameworks may set this in a
   following middleware. Some frameworks, such as the widely
   adopeted Django Rest Framework do not set this as part
   of a middleware. So, the upshot of hit is that the
   actor will not be set when using Django Rest Framework.
@ndwhelan
Copy link
Author

Addresses #277

@codecov
Copy link

codecov bot commented Oct 16, 2020

Codecov Report

Merging #279 into master will increase coverage by 1.84%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #279      +/-   ##
==========================================
+ Coverage   82.20%   84.04%   +1.84%     
==========================================
  Files          18       18              
  Lines         489      489              
==========================================
+ Hits          402      411       +9     
+ Misses         87       78       -9     
Impacted Files Coverage Δ
auditlog/middleware.py 92.10% <100.00%> (+23.68%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 31418d5...0492bf1. Read the comment docs.

@ndwhelan
Copy link
Author

This is probably solved by PR #262

@aleh-rymasheuski
Copy link
Contributor

This is actually not solved in #262. #262 sets both actor and remote_addr only for authenticated users, which is exactly the issue attempted to be resolved by this pull request.

@aqeelat aqeelat mentioned this pull request Dec 22, 2022
@aqeelat
Copy link
Member

aqeelat commented Jan 5, 2023

Superseded by #484
@hramezani

@hramezani
Copy link
Member

Thanks @ndwhelan for the initial patch and @aqeelat for continuing on this.

@hramezani hramezani closed this Jan 5, 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

Successfully merging this pull request may close these issues.

4 participants