Merge pull request #6470 from cd1989/retag-problem

Give meaningful error messages when retag is forbidden
This commit is contained in:
Wenkai Yin 2018-12-06 18:47:58 +08:00 committed by GitHub
commit bcd6947fcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -61,9 +61,9 @@ func (b *BaseAPI) HandleUnauthorized() {
}
// HandleForbidden ...
func (b *BaseAPI) HandleForbidden(username string) {
log.Infof("forbidden: %s", username)
b.RenderError(http.StatusForbidden, "")
func (b *BaseAPI) HandleForbidden(text string) {
log.Infof("forbidden: %s", text)
b.RenderError(http.StatusForbidden, text)
}
// HandleBadRequest ...

View File

@ -480,14 +480,14 @@ func (ra *RepositoryAPI) Retag() {
// Check whether use has read permission to source project
if !ra.SecurityCtx.HasReadPerm(srcImage.Project) {
log.Errorf("user has no read permission to project '%s'", srcImage.Project)
ra.HandleForbidden(ra.SecurityCtx.GetUsername())
ra.HandleForbidden(fmt.Sprintf("%s has no read permission to project %s", ra.SecurityCtx.GetUsername(), srcImage.Project))
return
}
// Check whether user has write permission to target project
if !ra.SecurityCtx.HasWritePerm(project) {
log.Errorf("user has no write permission to project '%s'", project)
ra.HandleForbidden(ra.SecurityCtx.GetUsername())
ra.HandleForbidden(fmt.Sprintf("%s has no write permission to project %s", ra.SecurityCtx.GetUsername(), project))
return
}