authentik icon indicating copy to clipboard operation
authentik copied to clipboard

events: provide the deleted model state in the event context #10169

Open local-it-dev opened this issue 1 year ago • 3 comments

Details

This PR closes #10169 It implements the sanitized model state as dict inside the model_deleted event. Another option would be to implement it as diff like in the model_created event: https://github.com/goauthentik/authentik/blob/a448107feb5261cf133830148a938ea2368d3c9b/authentik/enterprise/audit/middleware.py#L109 As the diff field is implemented in enterprise/audit/middleware.py I've done the same with the model_state. I'm not sure if events/middleware.py would be the better place for it, but enterprise/audit/middleware.py already provides the serialize_simple() function.


Checklist

  • [x] Local tests pass (ak test authentik/)
  • It passes the test if I apply the changes to the last release 2024.4.2 https://github.com/goauthentik/authentik/commit/6802614fbf878cec1d872bd01da922aa95b136fd
  • I can't get the current main running because of https://github.com/goauthentik/authentik/issues/9866 and the tests also won't pass for the current main (even without my changes)
  • [x] The code has been formatted (make lint-fix)

If an API change has been made

  • [ ] The API schema has been updated (make gen-build)

If changes to the frontend have been made

  • [ ] The code has been formatted (make web)

If applicable

  • [ ] The documentation has been updated
  • [ ] The documentation has been formatted (make website)

local-it-dev avatar Jun 19 '24 14:06 local-it-dev

Deploy Preview for authentik-storybook canceled.

Name Link
Latest commit 20152eb5e1c8e84dff95329e4269cd0eff504854
Latest deploy log https://app.netlify.com/sites/authentik-storybook/deploys/6672eb8e9265c50008383584

netlify[bot] avatar Jun 19 '24 14:06 netlify[bot]

Deploy Preview for authentik-docs ready!

Name Link
Latest commit 20152eb5e1c8e84dff95329e4269cd0eff504854
Latest deploy log https://app.netlify.com/sites/authentik-docs/deploys/6672eb8eb1a9990008c31df4
Deploy Preview https://deploy-preview-10172--authentik-docs.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Jun 19 '24 14:06 netlify[bot]

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 92.63%. Comparing base (1eb1039) to head (20152eb). Report is 87 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10172      +/-   ##
==========================================
+ Coverage   92.62%   92.63%   +0.01%     
==========================================
  Files         712      712              
  Lines       34924    34931       +7     
==========================================
+ Hits        32349    32360      +11     
+ Misses       2575     2571       -4     
Flag Coverage Δ
e2e 49.58% <100.00%> (+<0.01%) :arrow_up:
integration 25.40% <11.11%> (-0.01%) :arrow_down:
unit 90.11% <100.00%> (+0.01%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jun 28 '24 11:06 codecov[bot]

Can someone please give some feedback? Is there any way to get this feature upstream? Something I should change or add?

local-it-dev avatar Jul 15 '24 11:07 local-it-dev

@local-it-dev thank you for this straightforward and sensible PR! Our only hold-up in merging this is that it touches /enterprise code, so in terms of licensing, we will likely have to get a CLA in place; we're looking into the easiest way to do so.

fheisler avatar Jul 15 '24 12:07 fheisler

@local-it-dev thank you for this straightforward and sensible PR! Our only hold-up in merging this is that it touches /enterprise code, so in terms of licensing, we will likely have to get a CLA in place; we're looking into the easiest way to do so.

Thank you for your response. If it's easier in terms of licensing I could also place the code in events/middleware.py and may reimplement serialize_simple() there or import it from enterprise/audit/middleware.py (if this is not a licensing issue). Will the enterprise code like enterprise/audit/middleware.py, that is already used in the community version, always be part of the community version or is does it may happen at some point that it can only be accessed with an enterprise licence?

local-it-dev avatar Jul 17 '24 11:07 local-it-dev

Will the enterprise code like enterprise/audit/middleware.py, that is already used in the community version, always be part of the community version or is does it may happen at some point that it can only be accessed with an enterprise licence?

While it is always included (since we only create one package that has everything included), when no enterprise license (the license in authentik not the code license) is activated, that middleware is not used

BeryJu avatar Jul 17 '24 13:07 BeryJu

While it is always included (since we only create one package that has everything included), when no enterprise license (the license in authentik not the code license) is activated, that middleware is not used

But at the moment this middleware is also used without a license. So as I understand in future it could only be used with a license. Than I would place the code in events/middleware.py

local-it-dev avatar Jul 17 '24 13:07 local-it-dev