mirror of
https://github.com/aykhans/slash-e.git
synced 2025-07-05 12:42:35 +00:00
feat: impl delete user apiv2
This commit is contained in:
@ -14,6 +14,7 @@ func isUnauthorizeAllowedMethod(methodName string) bool {
|
||||
|
||||
var allowedMethodsOnlyForAdmin = map[string]bool{
|
||||
"/slash.api.v2.UserService/CreateUser": true,
|
||||
"/slash.api.v2.UserService/DeleteUser": true,
|
||||
}
|
||||
|
||||
// isOnlyForAdminAllowedMethod returns true if the method is allowed to be called only by admin.
|
||||
|
@ -86,6 +86,22 @@ func (s *UserService) CreateUser(ctx context.Context, request *apiv2pb.CreateUse
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *UserService) DeleteUser(ctx context.Context, request *apiv2pb.DeleteUserRequest) (*apiv2pb.DeleteUserResponse, error) {
|
||||
userID := ctx.Value(UserIDContextKey).(int32)
|
||||
if userID == request.Id {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "cannot delete self")
|
||||
}
|
||||
|
||||
err := s.Store.DeleteUser(ctx, &store.DeleteUser{
|
||||
ID: request.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to delete user: %v", err)
|
||||
}
|
||||
response := &apiv2pb.DeleteUserResponse{}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *UserService) ListUserAccessTokens(ctx context.Context, request *apiv2pb.ListUserAccessTokensRequest) (*apiv2pb.ListUserAccessTokensResponse, error) {
|
||||
userID := ctx.Value(UserIDContextKey).(int32)
|
||||
if userID != request.Id {
|
||||
|
Reference in New Issue
Block a user