-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: Audit log login did not record user #2691
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,7 +179,7 @@ class Login(APIView): | |
| responses=LoginSerializer().get_response_body_api(), | ||
| security=[], | ||
| tags=[_("User")]) | ||
| @log(menu='User', operate='Log in', get_user=lambda r: {'user_name': r.data.get('username', None)}, | ||
| @log(menu='User', operate='Log in', get_user=lambda r: {'username': r.data.get('username', None)}, | ||
| get_details=_get_details, | ||
| get_operation_object=lambda r, k: {'name': r.data.get('username')}) | ||
| def post(self, request: Request): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code is largely correct, but there are a few minor improvements and clarifications that can be made:
Here's a revised version with these points addressed: from rest_framework.decorators import api_view
from rest_framework.response import Response
@api_view(['POST'])
def login(request: Request):
serializer = LoginSerializer(data=request.data)
if serializer.is_valid(raise_exception=True):
return login_successful(serializer.user)
@log(
menu='User',
operate='Log in',
get_user=lambda r: {'user_name': r.data.get('username', None)},
get_details=_get_details,
get_operation_object=lambda r, k: {'name': r.data.get('username')}
)
# Define other functions needed here...Make sure all necessary imports (like |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code does not appear to contain any significant errors or issues, but there are a few minor improvements that can be made:
Improvements and Suggestions
Consistency with
gettext: The current implementation uses'unknown', which should be consistent across the application. If you intended to use it for internationalization (i18n), make sure everything else in your project respects this practice.Default Parameters: It's good practice to include default parameters when defining functions, especially if some arguments might be optional. Although not strictly necessary here, adding them can improve readability and usage patterns.
Simplified Dictionary Assignment: You can simplify the dictionary assignment inside the function using f-strings:
This streamlined version maintains the same functionality while being slightly more concise and adhering to common Python practices.