Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: update get memo api (#2079)

boojack3df9da91b44a
diff --git a/api/v2/jwt.go b/api/v2/acl.go
similarity index 100%
rename from api/v2/jwt.go
rename to api/v2/acl.go
diff --git a/api/v2/memo_service.go b/api/v2/memo_service.go
index 329dbe74b..9d14a30c5 100644
--- a/api/v2/memo_service.go
+++ b/api/v2/memo_service.go
@@ -49,17 +49,43 @@ func (s *MemoService) ListMemos(ctx context.Context, request *apiv2pb.ListMemosR
memoMessages[i] = convertMemoFromStore(memo)
}
+ // TODO(steven): Add privalige checks.
response := &apiv2pb.ListMemosResponse{
- Memos: memoMessages,
+ Memos: nil,
}
return response, nil
}
-const visibilityFilterExample = `visibility == "PRIVATE"`
+func (s *MemoService) GetMemo(ctx context.Context, request *apiv2pb.GetMemoRequest) (*apiv2pb.GetMemoResponse, error) {
+ memo, err := s.Store.GetMemo(ctx, &store.FindMemo{
+ ID: &request.Id,
+ })
+ if err != nil {
+ return nil, err
+ }
+ if memo == nil {
+ return nil, status.Errorf(codes.NotFound, "memo not found")
+ }
+ if memo.Visibility != store.Public {
+ userIDPtr := ctx.Value(UserIDContextKey)
+ if userIDPtr == nil {
+ return nil, status.Errorf(codes.Unauthenticated, "unauthenticated")
+ }
+ userID := userIDPtr.(int32)
+ if memo.Visibility == store.Private && memo.CreatorID != userID {
+ return nil, status.Errorf(codes.PermissionDenied, "permission denied")
+ }
+ }
+
+ response := &apiv2pb.GetMemoResponse{
+ Memo: convertMemoFromStore(memo),
+ }
+ return response, nil
+}
// getVisibilityFilter will parse the simple filter such as `visibility = "PRIVATE"` to "PRIVATE" .
func getVisibilityFilter(filter string) (string, error) {
- formatInvalidErr := errors.Errorf("invalid filter %q, example %q", filter, visibilityFilterExample)
+ formatInvalidErr := errors.Errorf("invalid filter %q", filter)
e, err := cel.NewEnv(cel.Variable("visibility", cel.StringType))
if err != nil {
return "", err
diff --git a/api/v2/v2.go b/api/v2/v2.go
index b5f9aeb8f..a8aaf63f8 100644
--- a/api/v2/v2.go
+++ b/api/v2/v2.go
@@ -30,6 +30,7 @@ func NewAPIV2Service(secret string, profile *profile.Profile, store *store.Store
),
)
apiv2pb.RegisterUserServiceServer(grpcServer, NewUserService(store))
+ apiv2pb.RegisterMemoServiceServer(grpcServer, NewMemoService(store))
apiv2pb.RegisterTagServiceServer(grpcServer, NewTagService(store))
return &APIV2Service{
@@ -62,6 +63,9 @@ func (s *APIV2Service) RegisterGateway(ctx context.Context, e *echo.Echo) error
if err := apiv2pb.RegisterUserServiceHandler(context.Background(), gwMux, conn); err != nil {
return err
}
+ if err := apiv2pb.RegisterMemoServiceHandler(context.Background(), gwMux, conn); err != nil {
+ return err
+ }
if err := apiv2pb.RegisterTagServiceHandler(context.Background(), gwMux, conn); err != nil {
return err
}