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

[WIP] Add Teams Endpoints #1031

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
f85d289
Add Teams Endpoints
tdrivas Nov 25, 2024
c09516e
Add .env to .gitignore
tdrivas Nov 25, 2024
8b2fbe1
Updated serializers and views for team and organization
tdrivas Nov 25, 2024
59d229f
Delete unnecessary comments
tdrivas Nov 25, 2024
9937cae
Refactor code formatting: Add/remove line spacing for improved readab…
tdrivas Nov 25, 2024
b502707
Add test_team.py with unit tests for Team functionality
tdrivas Nov 25, 2024
9fef851
Add test_team_member.py with unit tests for Team Member functionality…
tdrivas Nov 25, 2024
34265a4
Update users_views.py: Delete unnecessary comments and messages from …
tdrivas Nov 25, 2024
9464241
Extend serializers for team and team member functionality with access…
tdrivas Nov 25, 2024
c66cc9d
Add static method for Team model
tdrivas Nov 25, 2024
d9934af
Fix quotes in static method for Team model
tdrivas Nov 25, 2024
e1483d7
Update test for retrieving team details
tdrivas Nov 25, 2024
d7697dc
Apply coding style
tdrivas Nov 25, 2024
9eab570
Delete duplicate file
tdrivas Nov 25, 2024
be34d84
Delete unneseccary comments
tdrivas Nov 25, 2024
5f536d7
Apply changes after pre-commit
tdrivas Nov 25, 2024
8168563
Delete TeamDeleteSerializer
tdrivas Nov 25, 2024
2dc4f0b
Remove response message when team is deleted
tdrivas Nov 25, 2024
3638f60
Fix permission check by using permission_utils functions
tdrivas Nov 25, 2024
d1393ea
Use TeamSerializer instead of TeamAccessSerializer
tdrivas Nov 25, 2024
29a541d
Delete TeamAccessSerializer
tdrivas Nov 25, 2024
f2e0277
Add user email to the addMember validation process
tdrivas Nov 25, 2024
10b6b1a
Update names of urls
tdrivas Nov 25, 2024
7535def
Delete duplicate validation checks
tdrivas Nov 25, 2024
26ece82
Update permission checks by using existing functions
tdrivas Nov 25, 2024
513abf5
Use of drf-based permission for CRUD operations
tdrivas Nov 25, 2024
8d0d2b2
Refactor Team and Team Member views using DRF generics and centralize…
tdrivas Nov 25, 2024
8f20bc7
Change to StringRelatedField
tdrivas Nov 25, 2024
5d64da3
Delete TeamDetailSerializer
tdrivas Nov 25, 2024
5ba980e
Fix method headers
tdrivas Nov 25, 2024
56dca87
Delete member validation method
tdrivas Nov 25, 2024
222f737
Delete TeamListSerializer
tdrivas Nov 25, 2024
5e6544a
Optimize user validation using Q function
tdrivas Nov 25, 2024
adcc199
Optimize query
tdrivas Nov 25, 2024
dcde6cb
Fix: Include field in OrganizationSerializer with SerializerMethodField
tdrivas Nov 25, 2024
dad91cd
Fix tests
tdrivas Nov 25, 2024
14002f4
Add urls
tdrivas Nov 25, 2024
f212e63
Fix Team
tdrivas Nov 25, 2024
b091e49
Fix tests and other nice things :)
suricactus Nov 26, 2024
36145a3
Fix and finalize Tests
tdrivas Nov 27, 2024
edb6c3d
Split teams and users in views, update urls and serializers
tdrivas Nov 27, 2024
d01a082
Remove unwanted file
tdrivas Nov 27, 2024
ec82929
Restore file to inital state
tdrivas Nov 27, 2024
5eb1169
Fix noise
tdrivas Nov 28, 2024
1efbc1b
Add try-except in TeamMemberSerializer
tdrivas Nov 29, 2024
a5e933c
Add extend_schema_view decorators
tdrivas Nov 29, 2024
0e78aec
Add typing
tdrivas Nov 29, 2024
7de2fd5
Fix noise
tdrivas Nov 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docker-app/qfieldcloud/core/models.py
suricactus marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,17 @@ class UserManager(InheritanceManagerMixin, DjangoUserManager):
def get_queryset(self):
return super().get_queryset().select_subclasses()

def fast_search(self, username_or_email: str) -> "User":
"""Searches a user by `username` or `email` field

Args:
username_or_email (str): username or email to search for

Returns:
User: The user with that username or email.
"""
return self.get(Q(username=username_or_email) | Q(email=username_or_email))


class PersonManager(UserManager):
def get_queryset(self):
Expand Down Expand Up @@ -823,6 +834,13 @@ def save(self, *args, **kwargs):
def teamname(self):
return self.username.replace(f"@{self.team_organization.username}/", "")

@staticmethod
def format_team_name(organization_name, team_name):
tdrivas marked this conversation as resolved.
Show resolved Hide resolved
if not team_name:
raise ValueError("Team name is required.")

return f"@{organization_name}/{team_name}"


class TeamMember(models.Model):
class Roles(models.TextChoices):
Expand Down
36 changes: 32 additions & 4 deletions docker-app/qfieldcloud/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Project,
ProjectCollaborator,
Team,
TeamMember,
User,
)
from rest_framework import serializers
Expand Down Expand Up @@ -171,6 +172,7 @@ class OrganizationSerializer(serializers.ModelSerializer):
membership_is_public = serializers.BooleanField(
read_only=True, source="membership_role_is_public"
)
teams = serializers.SerializerMethodField()

def get_members(self, obj):
return [
Expand All @@ -180,6 +182,10 @@ def get_members(self, obj):
).values("member__username")
]

def get_teams(self, obj):
teams = Team.objects.filter(team_organization=obj)
return TeamSerializer(teams, many=True).data

tdrivas marked this conversation as resolved.
Show resolved Hide resolved
def get_avatar_url(self, obj):
return get_avatar_url(obj)

Expand Down Expand Up @@ -277,9 +283,7 @@ def to_internal_value(self, data):
if self._choices[i] == data:
return i
raise serializers.ValidationError(
"Invalid status. Acceptable values are {}.".format(
list(self._choices.values())
)
"Invalid status. Acceptable values are {}.".format((self._choices.values()))
tdrivas marked this conversation as resolved.
Show resolved Hide resolved
)


Expand Down Expand Up @@ -517,7 +521,7 @@ class FileVersionSerializer(serializers.Serializer):
class FileSerializer(serializers.Serializer):
"""NOTE not used for actual serialization, but for documentation suing Django Spectacular."""

versions = serializers.ListField(child=FileVersionSerializer())
versions = serializers.Field(child=FileVersionSerializer())
sha256 = serializers.CharField(required=False)
name = serializers.CharField()
size = serializers.IntegerField()
Expand All @@ -535,3 +539,27 @@ class LatestPackageSerializer(serializers.Serializer):
package_id = serializers.UUIDField()
packaged_at = serializers.DateTimeField()
data_last_updated_at = serializers.DateTimeField()


class TeamSerializer(serializers.ModelSerializer):
organization = serializers.StringRelatedField(source="team_organization")

class Meta:
model = Team
fields = ("username", "organization")


class TeamMemberSerializer(serializers.ModelSerializer):
member = serializers.CharField()

def to_internal_value(self, data):
validated_data = super().to_internal_value(data)
email_or_username = data.get("member")

validated_data["member"] = User.objects.fast_search(email_or_username)

return validated_data

class Meta:
model = TeamMember
fields = ("member",)
Loading