Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ownership relation between domain and user #86

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add domain ownership test to PURL save endpoint
  • Loading branch information
fabiante committed Sep 24, 2023
commit 0f930df9ebfce28d4fcf95c9ce77fd9fd76b7254
7 changes: 7 additions & 0 deletions api/err.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package api

import (
"errors"

"github.com/fabiante/persurl/api/res"
"github.com/gin-gonic/gin"
)

var (
ErrForbidden = errors.New("you are not allowed to do this")
)

// respondWithError responds with an error and aborts the request.
func respondWithError(ctx *gin.Context, status int, err error) {
response := res.ErrorList{
Errors: []res.Error{
7 changes: 6 additions & 1 deletion api/server_admin.go
Original file line number Diff line number Diff line change
@@ -30,7 +30,12 @@ func (s *Server) SavePURL(ctx *gin.Context) {
return
}

// todo: check user authorization on this url
// check authorization
user := getAuthenticatedUser(ctx)
if domain.OwnerID != user.ID {
respondWithError(ctx, http.StatusForbidden, ErrForbidden)
return
}

err = s.admin.SavePURL(domain, name, req.Target)
switch {