|
|
@ -61,42 +61,50 @@ func SearchRepos(ctx *middleware.Context) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func Migrate(ctx *middleware.Context, form auth.MigrateRepoForm) { |
|
|
|
func Migrate(ctx *middleware.Context, form auth.MigrateRepoForm) { |
|
|
|
ctxUser := ctx.User |
|
|
|
u, err := models.GetUserByName(ctx.Query("username")) |
|
|
|
// Not equal means current user is an organization.
|
|
|
|
if err != nil { |
|
|
|
if form.Uid != ctx.User.Id { |
|
|
|
|
|
|
|
org, err := models.GetUserById(form.Uid) |
|
|
|
|
|
|
|
if err != nil && err != models.ErrUserNotExist { |
|
|
|
|
|
|
|
ctx.JSON(500, map[string]interface{}{ |
|
|
|
ctx.JSON(500, map[string]interface{}{ |
|
|
|
"ok": false, |
|
|
|
"ok": false, |
|
|
|
"data": err.Error(), |
|
|
|
"error": err.Error(), |
|
|
|
}) |
|
|
|
}) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
ctxUser = org |
|
|
|
if !u.ValidtePassword(ctx.Query("password")) { |
|
|
|
|
|
|
|
ctx.JSON(500, map[string]interface{}{ |
|
|
|
|
|
|
|
"ok": false, |
|
|
|
|
|
|
|
"error": "username or password is not correct", |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := ctx.User.GetOrganizations(); err != nil { |
|
|
|
ctxUser := u |
|
|
|
|
|
|
|
// Not equal means current user is an organization.
|
|
|
|
|
|
|
|
if form.Uid != u.Id { |
|
|
|
|
|
|
|
org, err := models.GetUserById(form.Uid) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
ctx.JSON(500, map[string]interface{}{ |
|
|
|
ctx.JSON(500, map[string]interface{}{ |
|
|
|
"ok": false, |
|
|
|
"ok": false, |
|
|
|
"data": err.Error(), |
|
|
|
"error": err.Error(), |
|
|
|
}) |
|
|
|
}) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ctxUser = org |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
if ctx.HasError() { |
|
|
|
ctx.JSON(500, map[string]interface{}{ |
|
|
|
ctx.JSON(500, map[string]interface{}{ |
|
|
|
"ok": false, |
|
|
|
"ok": false, |
|
|
|
"data": ctx.GetErrMsg(), |
|
|
|
"error": ctx.GetErrMsg(), |
|
|
|
}) |
|
|
|
}) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ctxUser.IsOrganization() { |
|
|
|
if ctxUser.IsOrganization() { |
|
|
|
// Check ownership of organization.
|
|
|
|
// Check ownership of organization.
|
|
|
|
if !ctxUser.IsOrgOwner(ctx.User.Id) { |
|
|
|
if !ctxUser.IsOrgOwner(u.Id) { |
|
|
|
ctx.JSON(403, map[string]interface{}{ |
|
|
|
ctx.JSON(403, map[string]interface{}{ |
|
|
|
"ok": false, |
|
|
|
"ok": false, |
|
|
|
"data": "Not allowed", |
|
|
|
"error": "given user is not owner of organization", |
|
|
|
}) |
|
|
|
}) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -109,25 +117,11 @@ func Migrate(ctx *middleware.Context, form auth.MigrateRepoForm) { |
|
|
|
form.Mirror, url) |
|
|
|
form.Mirror, url) |
|
|
|
if err == nil { |
|
|
|
if err == nil { |
|
|
|
log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName) |
|
|
|
log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName) |
|
|
|
ctx.JSON(200, |
|
|
|
ctx.JSON(200, map[string]interface{}{ |
|
|
|
map[string]interface{}{ |
|
|
|
|
|
|
|
"ok": true, |
|
|
|
"ok": true, |
|
|
|
"data": "/" + ctxUser.Name + "/" + form.RepoName, |
|
|
|
"data": "/" + ctxUser.Name + "/" + form.RepoName, |
|
|
|
}) |
|
|
|
}) |
|
|
|
return |
|
|
|
return |
|
|
|
} else if err == models.ErrRepoAlreadyExist { |
|
|
|
|
|
|
|
ctx.JSON(500, |
|
|
|
|
|
|
|
map[string]interface{}{ |
|
|
|
|
|
|
|
"ok": false, |
|
|
|
|
|
|
|
"data": err.Error(), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} else if err == models.ErrRepoNameIllegal { |
|
|
|
|
|
|
|
ctx.JSON(500, map[string]interface{}{ |
|
|
|
|
|
|
|
"ok": false, |
|
|
|
|
|
|
|
"data": err.Error(), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if repo != nil { |
|
|
|
if repo != nil { |
|
|
@ -138,6 +132,6 @@ func Migrate(ctx *middleware.Context, form auth.MigrateRepoForm) { |
|
|
|
|
|
|
|
|
|
|
|
ctx.JSON(500, map[string]interface{}{ |
|
|
|
ctx.JSON(500, map[string]interface{}{ |
|
|
|
"ok": false, |
|
|
|
"ok": false, |
|
|
|
"data": err.Error(), |
|
|
|
"error": err.Error(), |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|