-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
Add Teams Endpoints to manage teams #1031
Conversation
Planned Tasks
|
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.
Hey! There are a few things cleanup to be done before you continue working on these. Would you mind to address the feedback first, so it will be much easier for review.
In short:
- don't leave random commented code here and there
- no need to comment obvious things
- please install
pre-commit
- please rebase on master
- remove
docker-compose.override.local.yml
changes
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.
General comment:
- there are still archeological treasures from the initial development, please make sure you remove these and push them
- merge all the tests in one
test_teams.py
file - the views can be a bit more
django-rest-framework
-like (DRF) , e.g. you can useRetrieveUpdateDestroyAPIView
or similar for the views baseclasses for "teams" and "team members". This will greatly reduce your codebase and simplify maintainence.
- cleanup the initial comments in this PR and push all the changes.
- rebase to the latest master and push
- run
pre-commit
and push - address most of the requests not related the the views.py or tests
- try to automate views behavior with DRF
- continue with tests
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.
Can you please rebase on the latest master and squash all the changes in a single commit?
Please add typing on all the methods that you add in this PR, except the tests.
Also, unfortunately I see some of our verbal conversation feedback was not addressed.
raise serializers.ValidationError( | ||
{ | ||
"member": f"A user with username '{email_or_username}' already exists." | ||
} | ||
) |
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.
You are not adding a user, I guess the message should be different.
raise serializers.ValidationError( | |
{ | |
"member": f"A user with username '{email_or_username}' already exists." | |
} | |
) | |
raise serializers.ValidationError( | |
{ | |
"member": f"A member with username '{email_or_username}' already exists." | |
} | |
) |
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.
This comments is answering all the comments above related to function internal_value:
The idea is the following:
- check if the username of the member that is going to be added already exists in another member
- check if member is indeed a user (this might be overkill due to an existing check via permissions in the view(???)
- otherwise use the fast_search to obtain the user
try:
existing_user = User.objects.fast_search(email_or_username)
if TeamMember.objects.filter(member=existing_user):
raise serializers.ValidationError(
{
"member": f"A member with username '{email_or_username}' already exists."
}
)
validated_data["member"] = existing_user
except User.DoesNotExist:
raise serializers.ValidationError(
{
"member": f"A user with username '{email_or_username}' does not exists."
}
)
return validated_data
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.
What happens if we don't explicitly handle the DoesNotExist
error, or we attempt to break the uniqueness of the members in the organization? Do we get a proper error or just error 500? What is the HTTP response body?
If we get 500, then we need to handle it. Your proposal is good.
Note that the messages are weird, you can get a validation message like: "A member with username [email protected] already exists". Just say 'The team member "[email protected]" already exists." We always put placeholders in double quotes in user strings.
Do you want to add typing also in variables or is it overkill? for example |
Add typing only when the type cannot be guessed by the type checker. In the case you mentioned, the typechecker has no way to get what is the type at key "member", so it will be But if you have:
There is no need to set the type of |
|
||
def to_internal_value(self, data: Dict[str, Any]) -> Dict[str, Any]: | ||
validated_data = super().to_internal_value(data) | ||
email_or_username = data.get("member") |
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.
email_or_username = data.get("member") | |
email_or_username: str = data["member"] |
We can safely assume the value will always be present in the dict, as the Serializer will automatically check for it. I might be wrong, to be verified.
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.
I will check it!
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.
Are you going to check it :P
Task linked: QF-4536 Add API endpoint to manage teams |
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.
Good! We are ready to merge this PR. One last renaming and we are good to merge!
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.
We are there! Thanks a lot!
Please squash all the changes into a single commit and merge the PR.
Add .env to .gitignore Updated serializers and views for team and organization Delete unnecessary comments Refactor code formatting: Add/remove line spacing for improved readability and consistency Add test_team.py with unit tests for Team functionality Add test_team_member.py with unit tests for Team Member functionality and permissions Update users_views.py: Delete unnecessary comments and messages from responses Extend serializers for team and team member functionality with access control validation. Add static method for Team model Fix quotes in static method for Team model Update test for retrieving team details Apply coding style Delete duplicate file Delete unneseccary comments Apply changes after pre-commit Delete TeamDeleteSerializer Remove response message when team is deleted Fix permission check by using permission_utils functions Use TeamSerializer instead of TeamAccessSerializer Delete TeamAccessSerializer Add user email to the addMember validation process Update names of urls Delete duplicate validation checks Update permission checks by using existing functions Use of drf-based permission for CRUD operations Refactor Team and Team Member views using DRF generics and centralized permissions Change to StringRelatedField Delete TeamDetailSerializer Fix method headers Delete member validation method Delete TeamListSerializer Optimize user validation using Q function Optimize query Fix: Include field in OrganizationSerializer with SerializerMethodField Fix tests Add urls Fix Team Fix tests and other nice things :) Fix and finalize Tests Split teams and users in views, update urls and serializers Remove unwanted file Restore file to inital state Fix noise Add try-except in TeamMemberSerializer Add extend_schema_view decorators Add typing Fix noise Fix Serializers not to use request_method Add typing, fix serializers and noise Fix formatting, Team serializer and order tests in a logical way Add typing Group tests per user category Add teams field in the Meta class of OrganizationSerializer Rename serializer field
New endpoints have been created for managing both teams and member under organization for CRUD actions