Allow admin to migrate repositories for other users
This commit is contained in:
parent
e0ffe0b58d
commit
0cf6c338e7
|
|
@ -242,7 +242,8 @@ func TestAPIRepoMigrate(t *testing.T) {
|
||||||
cloneURL, repoName string
|
cloneURL, repoName string
|
||||||
expectedStatus int
|
expectedStatus int
|
||||||
}{
|
}{
|
||||||
{ctxUserID: 2, userID: 2, cloneURL: "https://github.com/go-gitea/git.git", repoName: "git", expectedStatus: http.StatusCreated},
|
{ctxUserID: 1, userID: 2, cloneURL: "https://github.com/go-gitea/git.git", repoName: "git-admin", expectedStatus: http.StatusCreated},
|
||||||
|
{ctxUserID: 2, userID: 2, cloneURL: "https://github.com/go-gitea/git.git", repoName: "git-own", expectedStatus: http.StatusCreated},
|
||||||
{ctxUserID: 2, userID: 1, cloneURL: "https://github.com/go-gitea/git.git", repoName: "git-bad", expectedStatus: http.StatusForbidden},
|
{ctxUserID: 2, userID: 1, cloneURL: "https://github.com/go-gitea/git.git", repoName: "git-bad", expectedStatus: http.StatusForbidden},
|
||||||
{ctxUserID: 2, userID: 3, cloneURL: "https://github.com/go-gitea/git.git", repoName: "git-org", expectedStatus: http.StatusCreated},
|
{ctxUserID: 2, userID: 3, cloneURL: "https://github.com/go-gitea/git.git", repoName: "git-org", expectedStatus: http.StatusCreated},
|
||||||
{ctxUserID: 2, userID: 6, cloneURL: "https://github.com/go-gitea/git.git", repoName: "git-bad-org", expectedStatus: http.StatusForbidden},
|
{ctxUserID: 2, userID: 6, cloneURL: "https://github.com/go-gitea/git.git", repoName: "git-bad-org", expectedStatus: http.StatusForbidden},
|
||||||
|
|
|
||||||
|
|
@ -306,20 +306,22 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctxUser.IsOrganization() && ctx.User.ID != ctxUser.ID {
|
if !ctx.User.IsAdmin {
|
||||||
ctx.Error(403, "", "Given user is not an organization.")
|
if !ctxUser.IsOrganization() && ctx.User.ID != ctxUser.ID {
|
||||||
return
|
ctx.Error(403, "", "Given user is not an organization.")
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if ctxUser.IsOrganization() && !ctx.User.IsAdmin {
|
if ctxUser.IsOrganization() {
|
||||||
// Check ownership of organization.
|
// Check ownership of organization.
|
||||||
isOwner, err := ctxUser.IsOwnedBy(ctx.User.ID)
|
isOwner, err := ctxUser.IsOwnedBy(ctx.User.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(500, "IsOwnedBy", err)
|
ctx.Error(500, "IsOwnedBy", err)
|
||||||
return
|
return
|
||||||
} else if !isOwner {
|
} else if !isOwner {
|
||||||
ctx.Error(403, "", "Given user is not owner of organization.")
|
ctx.Error(403, "", "Given user is not owner of organization.")
|
||||||
return
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user