Skip to content

Commit

Permalink
add proto and sevice to update language user
Browse files Browse the repository at this point in the history
  • Loading branch information
mldzs committed Apr 1, 2021
1 parent cc09d5a commit 9a15e99
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
9 changes: 8 additions & 1 deletion bothub/api/grpc/user/handlers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from bothub.api.grpc.user.services import UserPermissionService, UserService
from bothub.api.grpc.user.services import (
UserPermissionService,
UserService,
UserLanguageService,
)
from bothub.protos import authentication_pb2_grpc


Expand All @@ -9,3 +13,6 @@ def grpc_handlers(server):
authentication_pb2_grpc.add_UserPermissionControllerServicer_to_server(
UserPermissionService.as_servicer(), server
)
authentication_pb2_grpc.add_UserLanguageControllerServicer_to_server(
UserLanguageService.as_servicer(), server
)
16 changes: 16 additions & 0 deletions bothub/api/grpc/user/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,19 @@ class UserPermissionProtoSerializer(proto_serializers.ProtoSerializer):

class Meta:
proto_class = authentication_pb2.Permission


class UserLanguageProtoSerializer(proto_serializers.ModelProtoSerializer):
class Meta:
model = User
proto_class = authentication_pb2.User
fields = ["language"]
read_only = [
"id",
"email",
"nickname",
"name",
"joined_at",
"is_active",
"is_superuser",
]
7 changes: 7 additions & 0 deletions bothub/api/grpc/user/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from bothub.api.grpc.user.serializers import (
UserProtoSerializer,
UserPermissionProtoSerializer,
UserLanguageProtoSerializer,
)
from bothub.authentication.models import User
from bothub.common.models import Organization
Expand Down Expand Up @@ -55,3 +56,9 @@ class UserService(mixins.RetrieveModelMixin, generics.GenericService):
serializer_class = UserProtoSerializer
queryset = User.objects
lookup_field = "email"


class UserLanguageService(mixins.UpdateModelMixin, generics.GenericService):
serializer_class = UserLanguageProtoSerializer
queryset = User.objects
lookup_field = "email"
2 changes: 1 addition & 1 deletion bothub/protos/authentication.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ message UserPermissionRemoveRequest {
}

message UserLanguageUpdateRequest {
string user_email = 1;
string email = 1;
string language = 2;
}

Expand Down

0 comments on commit 9a15e99

Please sign in to comment.