|
|
|
@ -252,37 +252,55 @@ func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) {
|
|
|
|
|
ctx.JSON(201, ToApiRepository(ctxUser, repo, api.Permission{true, true, true}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DeleteRepo(ctx *middleware.Context) {
|
|
|
|
|
user, err := models.GetUserByName(ctx.Params(":username"))
|
|
|
|
|
func parseOwnerAndRepo(ctx *middleware.Context) (*models.User, *models.Repository) {
|
|
|
|
|
owner, err := models.GetUserByName(ctx.Params(":username"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
if models.IsErrUserNotExist(err) {
|
|
|
|
|
ctx.APIError(422, "", err)
|
|
|
|
|
} else {
|
|
|
|
|
ctx.APIError(500, "GetUserByName", err)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
repo, err := models.GetRepositoryByName(user.Id, ctx.Params(":reponame"))
|
|
|
|
|
repo, err := models.GetRepositoryByName(owner.Id, ctx.Params(":reponame"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
if models.IsErrRepoNotExist(err) {
|
|
|
|
|
ctx.Error(404)
|
|
|
|
|
} else {
|
|
|
|
|
ctx.APIError(500, "GetRepositoryByName", err)
|
|
|
|
|
}
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return owner, repo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetRepo(ctx *middleware.Context) {
|
|
|
|
|
owner, repo := parseOwnerAndRepo(ctx)
|
|
|
|
|
if ctx.Written() {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.JSON(200, ToApiRepository(owner, repo, api.Permission{true, true, true}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DeleteRepo(ctx *middleware.Context) {
|
|
|
|
|
owner, repo := parseOwnerAndRepo(ctx)
|
|
|
|
|
if ctx.Written() {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if user.IsOrganization() && !user.IsOwnedBy(ctx.User.Id) {
|
|
|
|
|
if owner.IsOrganization() && !owner.IsOwnedBy(ctx.User.Id) {
|
|
|
|
|
ctx.APIError(403, "", "Given user is not owner of organization.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := models.DeleteRepository(user.Id, repo.ID); err != nil {
|
|
|
|
|
if err := models.DeleteRepository(owner.Id, repo.ID); err != nil {
|
|
|
|
|
ctx.APIError(500, "DeleteRepository", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Trace("Repository deleted: %s/%s", user.Name, repo.Name)
|
|
|
|
|
log.Trace("Repository deleted: %s/%s", owner.Name, repo.Name)
|
|
|
|
|
ctx.Status(204)
|
|
|
|
|
}
|
|
|
|
|