Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
3df9da91
Unverified
Commit
3df9da91
authored
Aug 05, 2023
by
boojack
Committed by
GitHub
Aug 05, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update get memo api (#2079)
parent
57dd1fc4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
3 deletions
+33
-3
acl.go
api/v2/acl.go
+0
-0
memo_service.go
api/v2/memo_service.go
+29
-3
v2.go
api/v2/v2.go
+4
-0
No files found.
api/v2/
jwt
.go
→
api/v2/
acl
.go
View file @
3df9da91
File moved
api/v2/memo_service.go
View file @
3df9da91
...
@@ -49,17 +49,43 @@ func (s *MemoService) ListMemos(ctx context.Context, request *apiv2pb.ListMemosR
...
@@ -49,17 +49,43 @@ func (s *MemoService) ListMemos(ctx context.Context, request *apiv2pb.ListMemosR
memoMessages
[
i
]
=
convertMemoFromStore
(
memo
)
memoMessages
[
i
]
=
convertMemoFromStore
(
memo
)
}
}
// TODO(steven): Add privalige checks.
response
:=
&
apiv2pb
.
ListMemosResponse
{
response
:=
&
apiv2pb
.
ListMemosResponse
{
Memos
:
memoMessages
,
Memos
:
nil
,
}
}
return
response
,
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" .
// getVisibilityFilter will parse the simple filter such as `visibility = "PRIVATE"` to "PRIVATE" .
func
getVisibilityFilter
(
filter
string
)
(
string
,
error
)
{
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
))
e
,
err
:=
cel
.
NewEnv
(
cel
.
Variable
(
"visibility"
,
cel
.
StringType
))
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
...
...
api/v2/v2.go
View file @
3df9da91
...
@@ -30,6 +30,7 @@ func NewAPIV2Service(secret string, profile *profile.Profile, store *store.Store
...
@@ -30,6 +30,7 @@ func NewAPIV2Service(secret string, profile *profile.Profile, store *store.Store
),
),
)
)
apiv2pb
.
RegisterUserServiceServer
(
grpcServer
,
NewUserService
(
store
))
apiv2pb
.
RegisterUserServiceServer
(
grpcServer
,
NewUserService
(
store
))
apiv2pb
.
RegisterMemoServiceServer
(
grpcServer
,
NewMemoService
(
store
))
apiv2pb
.
RegisterTagServiceServer
(
grpcServer
,
NewTagService
(
store
))
apiv2pb
.
RegisterTagServiceServer
(
grpcServer
,
NewTagService
(
store
))
return
&
APIV2Service
{
return
&
APIV2Service
{
...
@@ -62,6 +63,9 @@ func (s *APIV2Service) RegisterGateway(ctx context.Context, e *echo.Echo) error
...
@@ -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
{
if
err
:=
apiv2pb
.
RegisterUserServiceHandler
(
context
.
Background
(),
gwMux
,
conn
);
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
apiv2pb
.
RegisterMemoServiceHandler
(
context
.
Background
(),
gwMux
,
conn
);
err
!=
nil
{
return
err
}
if
err
:=
apiv2pb
.
RegisterTagServiceHandler
(
context
.
Background
(),
gwMux
,
conn
);
err
!=
nil
{
if
err
:=
apiv2pb
.
RegisterTagServiceHandler
(
context
.
Background
(),
gwMux
,
conn
);
err
!=
nil
{
return
err
return
err
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment