|
|
@ -155,13 +155,13 @@ func GetEditorconfig(ctx *context.APIContext) {
|
|
|
|
ctx.JSON(http.StatusOK, def)
|
|
|
|
ctx.JSON(http.StatusOK, def)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// CanWriteFiles returns true if repository is editable and user has proper access level.
|
|
|
|
// canWriteFiles returns true if repository is editable and user has proper access level.
|
|
|
|
func CanWriteFiles(r *context.Repository) bool {
|
|
|
|
func canWriteFiles(r *context.Repository) bool {
|
|
|
|
return r.Permission.CanWrite(models.UnitTypeCode) && !r.Repository.IsMirror && !r.Repository.IsArchived
|
|
|
|
return r.Permission.CanWrite(models.UnitTypeCode) && !r.Repository.IsMirror && !r.Repository.IsArchived
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// CanReadFiles returns true if repository is readable and user has proper access level.
|
|
|
|
// canReadFiles returns true if repository is readable and user has proper access level.
|
|
|
|
func CanReadFiles(r *context.Repository) bool {
|
|
|
|
func canReadFiles(r *context.Repository) bool {
|
|
|
|
return r.Permission.CanRead(models.UnitTypeCode)
|
|
|
|
return r.Permission.CanRead(models.UnitTypeCode)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -321,7 +321,7 @@ func UpdateFile(ctx *context.APIContext, apiOpts api.UpdateFileOptions) {
|
|
|
|
|
|
|
|
|
|
|
|
// Called from both CreateFile or UpdateFile to handle both
|
|
|
|
// Called from both CreateFile or UpdateFile to handle both
|
|
|
|
func createOrUpdateFile(ctx *context.APIContext, opts *repofiles.UpdateRepoFileOptions) (*api.FileResponse, error) {
|
|
|
|
func createOrUpdateFile(ctx *context.APIContext, opts *repofiles.UpdateRepoFileOptions) (*api.FileResponse, error) {
|
|
|
|
if !CanWriteFiles(ctx.Repo) {
|
|
|
|
if !canWriteFiles(ctx.Repo) {
|
|
|
|
return nil, models.ErrUserDoesNotHaveAccessToRepo{
|
|
|
|
return nil, models.ErrUserDoesNotHaveAccessToRepo{
|
|
|
|
UserID: ctx.User.ID,
|
|
|
|
UserID: ctx.User.ID,
|
|
|
|
RepoName: ctx.Repo.Repository.LowerName,
|
|
|
|
RepoName: ctx.Repo.Repository.LowerName,
|
|
|
@ -377,7 +377,7 @@ func DeleteFile(ctx *context.APIContext, apiOpts api.DeleteFileOptions) {
|
|
|
|
// "404":
|
|
|
|
// "404":
|
|
|
|
// "$ref": "#/responses/error"
|
|
|
|
// "$ref": "#/responses/error"
|
|
|
|
|
|
|
|
|
|
|
|
if !CanWriteFiles(ctx.Repo) {
|
|
|
|
if !canWriteFiles(ctx.Repo) {
|
|
|
|
ctx.Error(http.StatusForbidden, "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,
|
|
|
@ -474,7 +474,7 @@ func GetContents(ctx *context.APIContext) {
|
|
|
|
// "404":
|
|
|
|
// "404":
|
|
|
|
// "$ref": "#/responses/notFound"
|
|
|
|
// "$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{
|
|
|
|
UserID: ctx.User.ID,
|
|
|
|
UserID: ctx.User.ID,
|
|
|
|
RepoName: ctx.Repo.Repository.LowerName,
|
|
|
|
RepoName: ctx.Repo.Repository.LowerName,
|
|
|
|