Skip to content

Commit

Permalink
added some listing filters to user
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo committed Jan 2, 2024
1 parent fa0f58c commit 8ded5da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 8 additions & 2 deletions core/api/views/objects/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ....models import User, graduating_year_choices


class Serializer(serializers.ModelSerializer):
class UserSerializer(serializers.ModelSerializer):
email_hash = serializers.SerializerMethodField(read_only=True)
gravatar_url = serializers.SerializerMethodField(read_only=True)
username = serializers.CharField(required=False)
Expand Down Expand Up @@ -184,6 +184,12 @@ def has_object_permission(self, request, view, user):
class UserProvider(BaseProvider):
model = User
additional_lookup_fields = ["username"]
listing_filters = {
"organizations": int,
"organizations_leading": int,
"organizations_owning": int,
"organizations_supervising": int,
}

@property
def permission_classes(self):
Expand All @@ -194,7 +200,7 @@ def serializer_class(self):
return dict(
new=NewSerializer,
list=ListSerializer,
).get(self.request.kind, Serializer)
).get(self.request.kind, UserSerializer)

@staticmethod
def get_queryset(request):
Expand Down
7 changes: 6 additions & 1 deletion docs/api3.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,12 @@ properties:
## User

`username` can be used for the lookup query string to filter by username.


#### Listing filters
- organizations: The id of the organization to get members of.
- organizations_leading: The id of the organization to get execs of.
- organizations_owning: The id of the organization to get the owner of.
- organizations_supervising: The id of the organization to get supervisors of.
```yaml
$schema: https://json-schema.org/draft/2020-12/schema
$id: https://maclyonsden.com/api/v3/schema/user.json
Expand Down

0 comments on commit 8ded5da

Please sign in to comment.