Skip to content

Commit

Permalink
Merge pull request #565 from Ilhasoft/feature/add_grpc_route_to_chang…
Browse files Browse the repository at this point in the history
…e_language_user

Feature/add grpc route to change language user
  • Loading branch information
dyohan9 committed Apr 6, 2021
2 parents 348c739 + 695653c commit 3001b70
Show file tree
Hide file tree
Showing 4 changed files with 43 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
)
17 changes: 17 additions & 0 deletions bothub/api/grpc/user/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Meta:
"email",
"nickname",
"name",
"language",
"joined_at",
"is_active",
"is_superuser",
Expand All @@ -25,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"
12 changes: 11 additions & 1 deletion bothub/protos/authentication.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ service UserController {
rpc Retrieve(UserRetrieveRequest) returns (User) {}
}

service UserLanguageController {
rpc Update(UserLanguageUpdateRequest) returns (User) {}
}

message UserPermissionRetrieveRequest {
string org_user_email = 1;
int32 org_id = 2;
Expand All @@ -31,6 +35,11 @@ message UserPermissionRemoveRequest {
int32 permission = 3;
}

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

message Permission {
int32 role = 1;
}
Expand All @@ -44,7 +53,8 @@ message User {
string email = 2;
string nickname = 3;
string name = 4;
string language = 5;
string joined_at = 6;
bool is_active = 7;
bool is_superuser = 8;
}
}

0 comments on commit 3001b70

Please sign in to comment.