|
@ -362,9 +362,15 @@ func DeleteFile(ctx *context.APIContext, apiOpts api.DeleteFileOptions) { |
|
|
// responses:
|
|
|
// responses:
|
|
|
// "200":
|
|
|
// "200":
|
|
|
// "$ref": "#/responses/FileDeleteResponse"
|
|
|
// "$ref": "#/responses/FileDeleteResponse"
|
|
|
|
|
|
// "400":
|
|
|
|
|
|
// "$ref": "#/responses/error"
|
|
|
|
|
|
// "403":
|
|
|
|
|
|
// "$ref": "#/responses/error"
|
|
|
|
|
|
// "404":
|
|
|
|
|
|
// "$ref": "#/responses/error"
|
|
|
|
|
|
|
|
|
if !CanWriteFiles(ctx.Repo) { |
|
|
if !CanWriteFiles(ctx.Repo) { |
|
|
ctx.Error(http.StatusInternalServerError, "DeleteFile", models.ErrUserDoesNotHaveAccessToRepo{ |
|
|
|
|
|
|
|
|
ctx.Error(http.StatusForbidden, "DeleteFile", models.ErrUserDoesNotHaveAccessToRepo{ |
|
|
UserID: ctx.User.ID, |
|
|
UserID: ctx.User.ID, |
|
|
RepoName: ctx.Repo.Repository.LowerName, |
|
|
RepoName: ctx.Repo.Repository.LowerName, |
|
|
}) |
|
|
}) |
|
@ -402,9 +408,23 @@ func DeleteFile(ctx *context.APIContext, apiOpts api.DeleteFileOptions) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if fileResponse, err := repofiles.DeleteRepoFile(ctx.Repo.Repository, ctx.User, opts); err != nil { |
|
|
if fileResponse, err := repofiles.DeleteRepoFile(ctx.Repo.Repository, ctx.User, opts); err != nil { |
|
|
|
|
|
if git.IsErrBranchNotExist(err) || models.IsErrRepoFileDoesNotExist(err) || git.IsErrNotExist(err) { |
|
|
|
|
|
ctx.Error(http.StatusNotFound, "DeleteFile", err) |
|
|
|
|
|
return |
|
|
|
|
|
} else if models.IsErrBranchAlreadyExists(err) || |
|
|
|
|
|
models.IsErrFilenameInvalid(err) || |
|
|
|
|
|
models.IsErrSHADoesNotMatch(err) || |
|
|
|
|
|
models.IsErrCommitIDDoesNotMatch(err) || |
|
|
|
|
|
models.IsErrSHAOrCommitIDNotProvided(err) { |
|
|
|
|
|
ctx.Error(http.StatusBadRequest, "DeleteFile", err) |
|
|
|
|
|
return |
|
|
|
|
|
} else if models.IsErrUserCannotCommit(err) { |
|
|
|
|
|
ctx.Error(http.StatusForbidden, "DeleteFile", err) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
ctx.Error(http.StatusInternalServerError, "DeleteFile", err) |
|
|
ctx.Error(http.StatusInternalServerError, "DeleteFile", err) |
|
|
} else { |
|
|
} else { |
|
|
ctx.JSON(http.StatusOK, fileResponse) |
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, fileResponse) // FIXME on APIv2: return http.StatusNoContent
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -439,6 +459,8 @@ func GetContents(ctx *context.APIContext) { |
|
|
// responses:
|
|
|
// responses:
|
|
|
// "200":
|
|
|
// "200":
|
|
|
// "$ref": "#/responses/ContentsResponse"
|
|
|
// "$ref": "#/responses/ContentsResponse"
|
|
|
|
|
|
// "404":
|
|
|
|
|
|
// "$ref": "#/responses/notFound"
|
|
|
|
|
|
|
|
|
if !CanReadFiles(ctx.Repo) { |
|
|
if !CanReadFiles(ctx.Repo) { |
|
|
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", models.ErrUserDoesNotHaveAccessToRepo{ |
|
|
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", models.ErrUserDoesNotHaveAccessToRepo{ |
|
@ -452,6 +474,10 @@ func GetContents(ctx *context.APIContext) { |
|
|
ref := ctx.QueryTrim("ref") |
|
|
ref := ctx.QueryTrim("ref") |
|
|
|
|
|
|
|
|
if fileList, err := repofiles.GetContentsOrList(ctx.Repo.Repository, treePath, ref); err != nil { |
|
|
if fileList, err := repofiles.GetContentsOrList(ctx.Repo.Repository, treePath, ref); err != nil { |
|
|
|
|
|
if git.IsErrNotExist(err) { |
|
|
|
|
|
ctx.NotFound("GetContentsOrList", err) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", err) |
|
|
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", err) |
|
|
} else { |
|
|
} else { |
|
|
ctx.JSON(http.StatusOK, fileList) |
|
|
ctx.JSON(http.StatusOK, fileList) |
|
@ -484,6 +510,8 @@ func GetContentsList(ctx *context.APIContext) { |
|
|
// responses:
|
|
|
// responses:
|
|
|
// "200":
|
|
|
// "200":
|
|
|
// "$ref": "#/responses/ContentsListResponse"
|
|
|
// "$ref": "#/responses/ContentsListResponse"
|
|
|
|
|
|
// "404":
|
|
|
|
|
|
// "$ref": "#/responses/notFound"
|
|
|
|
|
|
|
|
|
// same as GetContents(), this function is here because swagger fails if path is empty in GetContents() interface
|
|
|
// same as GetContents(), this function is here because swagger fails if path is empty in GetContents() interface
|
|
|
GetContents(ctx) |
|
|
GetContents(ctx) |
|
|