Skip to content

Commit

Permalink
Fix bug in uploadFile()'s URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
hsluoyz committed Jul 17, 2022
1 parent a0a762a commit c4793a5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions authz/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ p, *, *, GET, /api/get-payment, *, *
p, *, *, POST, /api/update-payment, *, *
p, *, *, POST, /api/invoice-payment, *, *
p, *, *, GET, /api/get-providers, *, *
p, *, *, POST, /api/notify-payment, *, *
p, *, *, POST, /api/unlink, *, *
p, *, *, POST, /api/set-password, *, *
p, *, *, POST, /api/send-verification-code, *, *
Expand Down
6 changes: 2 additions & 4 deletions object/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ func getPermanentAvatarUrl(organization string, username string, url string) str
return ""
}

fullFilePath := fmt.Sprintf("/avatar/%s/%s.png", organization, username)
uploadedFileUrl, _ := getUploadFileUrl(defaultStorageProvider, fullFilePath, false)

fileBuffer, err := downloadFile(url)
if err != nil {
panic(err)
}

_, _, err = UploadFileSafe(defaultStorageProvider, fullFilePath, fileBuffer)
fullFilePath := fmt.Sprintf("/avatar/%s/%s.png", organization, username)
uploadedFileUrl, _, err := UploadFileSafe(defaultStorageProvider, fullFilePath, fileBuffer)
if err != nil {
panic(err)
}
Expand Down
7 changes: 7 additions & 0 deletions object/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ func uploadFile(provider *Provider, fullFilePath string, fileBuffer *bytes.Buffe
return "", "", err
}

if provider.Type != "Local File System" {
fileUrl, err = storageProvider.GetURL(objectKey)
if err != nil {
return "", "", err
}
}

return fileUrl, objectKey, nil
}

Expand Down
4 changes: 4 additions & 0 deletions routers/authz_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func AuthzFilter(ctx *context.Context) {
urlPath := getUrlPath(ctx.Request.URL.Path)
objOwner, objName := getObject(ctx)

if strings.HasPrefix(urlPath, "/api/notify-payment") {
urlPath = "/api/notify-payment"
}

isAllowed := authz.IsAllowed(subOwner, subName, method, urlPath, objOwner, objName)

result := "deny"
Expand Down

0 comments on commit c4793a5

Please sign in to comment.