feat: restrict certain endpoints from API tokens and/or read-only tokens
This commit is contained in:
parent
2716471fa9
commit
ff75075b81
13 changed files with 62 additions and 14 deletions
|
@ -14,6 +14,10 @@ func (s *Server) startExport(w http.ResponseWriter, r *http.Request) error {
|
|||
ctx := r.Context()
|
||||
claims, _ := server.ClaimsFromContext(ctx)
|
||||
|
||||
if claims.APIToken {
|
||||
return server.APIError{Code: server.ErrMissingPermissions, Details: "This endpoint cannot be used by API tokens"}
|
||||
}
|
||||
|
||||
hasExport, err := s.DB.HasRecentExport(ctx, claims.UserID)
|
||||
if err != nil {
|
||||
log.Errorf("checking if user has recent export: %v", err)
|
||||
|
@ -56,6 +60,10 @@ func (s *Server) getExport(w http.ResponseWriter, r *http.Request) error {
|
|||
ctx := r.Context()
|
||||
claims, _ := server.ClaimsFromContext(ctx)
|
||||
|
||||
if claims.APIToken {
|
||||
return server.APIError{Code: server.ErrMissingPermissions, Details: "This endpoint cannot be used by API tokens"}
|
||||
}
|
||||
|
||||
de, err := s.DB.UserExport(ctx, claims.UserID)
|
||||
if err != nil {
|
||||
if err == db.ErrNoExport {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue