Skip to content

Commit fbab446

Browse files
committed
adapt latest refactors
1 parent e39c3de commit fbab446

File tree

6 files changed

+27
-30
lines changed

6 files changed

+27
-30
lines changed

models/repo/attachment.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,6 @@ func DeleteAttachmentsByComment(commentID int64, remove bool) (int, error) {
225225
return DeleteAttachments(db.DefaultContext, attachments, remove)
226226
}
227227

228-
// UpdateAttachment updates the given attachment in database
229-
func UpdateAttachment(atta *Attachment) error {
230-
return UpdateAttachmentCtx(db.DefaultContext, atta)
231-
}
232-
233228
// UpdateAttachmentByUUID Updates attachment via uuid
234229
func UpdateAttachmentByUUID(ctx context.Context, attach *Attachment, cols ...string) error {
235230
if attach.UUID == "" {

models/repo/attachment_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestUpdateAttachment(t *testing.T) {
8686
assert.Equal(t, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", attach.UUID)
8787

8888
attach.Name = "new_name"
89-
assert.NoError(t, UpdateAttachment(attach))
89+
assert.NoError(t, UpdateAttachmentCtx(db.DefaultContext, attach))
9090

9191
unittest.AssertExistsAndLoadBean(t, &Attachment{Name: "new_name"})
9292
}

routers/api/v1/repo/issue_attachment.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99

1010
"code.gitea.io/gitea/models"
11+
repo_model "code.gitea.io/gitea/models/repo"
1112
"code.gitea.io/gitea/modules/context"
1213
"code.gitea.io/gitea/modules/convert"
1314
"code.gitea.io/gitea/modules/log"
@@ -189,9 +190,9 @@ func CreateIssueAttachment(ctx *context.APIContext) {
189190
filename = query
190191
}
191192

192-
attach, err := attachment.UploadAttachment(file, setting.Attachment.AllowedTypes, &models.Attachment{
193+
attach, err := attachment.UploadAttachment(file, setting.Attachment.AllowedTypes, &repo_model.Attachment{
193194
Name: filename,
194-
UploaderID: ctx.User.ID,
195+
UploaderID: ctx.Doer.ID,
195196
RepoID: ctx.Repo.Repository.ID,
196197
IssueID: issue.ID,
197198
})
@@ -202,7 +203,7 @@ func CreateIssueAttachment(ctx *context.APIContext) {
202203

203204
issue.Attachments = append(issue.Attachments, attach)
204205

205-
if err := issue_service.ChangeContent(issue, ctx.User, issue.Content); err != nil {
206+
if err := issue_service.ChangeContent(issue, ctx.Doer, issue.Content); err != nil {
206207
ctx.Error(http.StatusInternalServerError, "ChangeContent", err)
207208
return
208209
}
@@ -262,7 +263,7 @@ func EditIssueAttachment(ctx *context.APIContext) {
262263
if form.Name != "" {
263264
attach.Name = form.Name
264265
}
265-
if err := models.UpdateAttachment(attach); err != nil {
266+
if err := repo_model.UpdateAttachmentCtx(ctx, attach); err != nil {
266267
ctx.Error(http.StatusInternalServerError, "UpdateAttachment", err)
267268
}
268269
ctx.JSON(http.StatusCreated, convert.ToAttachment(attach))
@@ -308,14 +309,14 @@ func DeleteIssueAttachment(ctx *context.APIContext) {
308309
if attach == nil {
309310
return
310311
}
311-
if err := models.DeleteAttachment(attach, true); err != nil {
312+
if err := repo_model.DeleteAttachment(attach, true); err != nil {
312313
ctx.Error(http.StatusInternalServerError, "DeleteAttachment", err)
313314
return
314315
}
315316
ctx.Status(http.StatusNoContent)
316317
}
317318

318-
func getIssueAttachmentSafeWrite(ctx *context.APIContext) *models.Attachment {
319+
func getIssueAttachmentSafeWrite(ctx *context.APIContext) *repo_model.Attachment {
319320
issueIndex := ctx.ParamsInt64(":index")
320321
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, issueIndex)
321322
if err != nil {
@@ -333,11 +334,11 @@ func getIssueAttachmentSafeWrite(ctx *context.APIContext) *models.Attachment {
333334
return attach
334335
}
335336

336-
func getIssueAttachmentSafeRead(ctx *context.APIContext, issue *models.Issue) *models.Attachment {
337+
func getIssueAttachmentSafeRead(ctx *context.APIContext, issue *models.Issue) *repo_model.Attachment {
337338
attachID := ctx.ParamsInt64(":asset")
338-
attach, err := models.GetAttachmentByID(attachID)
339+
attach, err := repo_model.GetAttachmentByID(attachID)
339340
if err != nil {
340-
ctx.NotFoundOrServerError("GetAttachmentByID", models.IsErrAttachmentNotExist, err)
341+
ctx.NotFoundOrServerError("GetAttachmentByID", repo_model.IsErrAttachmentNotExist, err)
341342
return nil
342343
}
343344
if !attachmentBelongsToRepoOrIssue(ctx, attach, issue) {
@@ -347,7 +348,7 @@ func getIssueAttachmentSafeRead(ctx *context.APIContext, issue *models.Issue) *m
347348
}
348349

349350
func canUserWriteIssueAttachment(ctx *context.APIContext, i *models.Issue) (success bool) {
350-
canEditIssue := ctx.User.ID == i.PosterID || ctx.IsUserRepoAdmin() || ctx.IsUserSiteAdmin()
351+
canEditIssue := ctx.Doer.ID == i.PosterID || ctx.IsUserRepoAdmin() || ctx.IsUserSiteAdmin()
351352
if !canEditIssue {
352353
ctx.Error(http.StatusForbidden, "IssueEditPerm", "user should have permission to edit issue")
353354
return
@@ -356,7 +357,7 @@ func canUserWriteIssueAttachment(ctx *context.APIContext, i *models.Issue) (succ
356357
return true
357358
}
358359

359-
func attachmentBelongsToRepoOrIssue(ctx *context.APIContext, a *models.Attachment, issue *models.Issue) (success bool) {
360+
func attachmentBelongsToRepoOrIssue(ctx *context.APIContext, a *repo_model.Attachment, issue *models.Issue) (success bool) {
360361
if a.RepoID != ctx.Repo.Repository.ID {
361362
log.Debug("Requested attachment[%d] does not belong to repo[%-v].", a.ID, ctx.Repo.Repository)
362363
ctx.NotFound("no such attachment in repo")

routers/api/v1/repo/issue_comment_attachment.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99

1010
"code.gitea.io/gitea/models"
11+
repo_model "code.gitea.io/gitea/models/repo"
1112
"code.gitea.io/gitea/modules/context"
1213
"code.gitea.io/gitea/modules/convert"
1314
"code.gitea.io/gitea/modules/log"
@@ -180,9 +181,9 @@ func CreateIssueCommentAttachment(ctx *context.APIContext) {
180181
filename = query
181182
}
182183

183-
attach, err := attachment.UploadAttachment(file, setting.Attachment.AllowedTypes, &models.Attachment{
184+
attach, err := attachment.UploadAttachment(file, setting.Attachment.AllowedTypes, &repo_model.Attachment{
184185
Name: filename,
185-
UploaderID: ctx.User.ID,
186+
UploaderID: ctx.Doer.ID,
186187
RepoID: ctx.Repo.Repository.ID,
187188
IssueID: comment.IssueID,
188189
CommentID: comment.ID,
@@ -196,7 +197,7 @@ func CreateIssueCommentAttachment(ctx *context.APIContext) {
196197
return
197198
}
198199

199-
if err = comment_service.UpdateComment(comment, ctx.User, comment.Content); err != nil {
200+
if err = comment_service.UpdateComment(comment, ctx.Doer, comment.Content); err != nil {
200201
ctx.ServerError("UpdateComment", err)
201202
return
202203
}
@@ -256,7 +257,7 @@ func EditIssueCommentAttachment(ctx *context.APIContext) {
256257
attach.Name = form.Name
257258
}
258259

259-
if err := models.UpdateAttachment(attach); err != nil {
260+
if err := repo_model.UpdateAttachmentCtx(ctx, attach); err != nil {
260261
ctx.Error(http.StatusInternalServerError, "UpdateAttachment", attach)
261262
}
262263
ctx.JSON(http.StatusCreated, convert.ToAttachment(attach))
@@ -303,7 +304,7 @@ func DeleteIssueCommentAttachment(ctx *context.APIContext) {
303304
return
304305
}
305306

306-
if err := models.DeleteAttachment(attach, true); err != nil {
307+
if err := repo_model.DeleteAttachment(attach, true); err != nil {
307308
ctx.Error(http.StatusInternalServerError, "DeleteAttachment", err)
308309
return
309310
}
@@ -329,7 +330,7 @@ func getIssueCommentSafe(ctx *context.APIContext) *models.Comment {
329330
return comment
330331
}
331332

332-
func getIssueCommentAttachmentSafeWrite(ctx *context.APIContext) *models.Attachment {
333+
func getIssueCommentAttachmentSafeWrite(ctx *context.APIContext) *repo_model.Attachment {
333334
comment := getIssueCommentSafe(ctx)
334335
if comment == nil {
335336
return nil
@@ -344,11 +345,11 @@ func getIssueCommentAttachmentSafeWrite(ctx *context.APIContext) *models.Attachm
344345
return attach
345346
}
346347

347-
func getIssueCommentAttachmentSafeRead(ctx *context.APIContext, comment *models.Comment) *models.Attachment {
348+
func getIssueCommentAttachmentSafeRead(ctx *context.APIContext, comment *models.Comment) *repo_model.Attachment {
348349
attachID := ctx.ParamsInt64(":asset")
349-
attach, err := models.GetAttachmentByID(attachID)
350+
attach, err := repo_model.GetAttachmentByID(attachID)
350351
if err != nil {
351-
ctx.NotFoundOrServerError("GetAttachmentByID", models.IsErrAttachmentNotExist, err)
352+
ctx.NotFoundOrServerError("GetAttachmentByID", repo_model.IsErrAttachmentNotExist, err)
352353
return nil
353354
}
354355
if !attachmentBelongsToRepoOrComment(ctx, attach, comment) {
@@ -358,7 +359,7 @@ func getIssueCommentAttachmentSafeRead(ctx *context.APIContext, comment *models.
358359
}
359360

360361
func canUserWriteIssueCommentAttachment(ctx *context.APIContext, c *models.Comment) (success bool) {
361-
canEditComment := ctx.User.ID == c.PosterID || ctx.IsUserRepoAdmin() || ctx.IsUserSiteAdmin()
362+
canEditComment := ctx.Doer.ID == c.PosterID || ctx.IsUserRepoAdmin() || ctx.IsUserSiteAdmin()
362363
if !canEditComment {
363364
ctx.Error(http.StatusForbidden, "", "user should have permission to edit comment")
364365
return
@@ -367,7 +368,7 @@ func canUserWriteIssueCommentAttachment(ctx *context.APIContext, c *models.Comme
367368
return true
368369
}
369370

370-
func attachmentBelongsToRepoOrComment(ctx *context.APIContext, a *models.Attachment, comment *models.Comment) (success bool) {
371+
func attachmentBelongsToRepoOrComment(ctx *context.APIContext, a *repo_model.Attachment, comment *models.Comment) (success bool) {
371372
if a.RepoID != ctx.Repo.Repository.ID {
372373
log.Debug("Requested attachment[%d] does not belong to repo[%-v].", a.ID, ctx.Repo.Repository)
373374
ctx.NotFound("no such attachment in repo")

routers/api/v1/repo/release_attachment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func EditReleaseAttachment(ctx *context.APIContext) {
262262
attach.Name = form.Name
263263
}
264264

265-
if err := repo_model.UpdateAttachment(attach); err != nil {
265+
if err := repo_model.UpdateAttachmentCtx(ctx, attach); err != nil {
266266
ctx.Error(http.StatusInternalServerError, "UpdateAttachment", attach)
267267
}
268268
ctx.JSON(http.StatusCreated, convert.ToAttachment(attach))

routers/web/repo/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,7 @@ func UpdateIssueContent(ctx *context.Context) {
18571857
}
18581858

18591859
content := ctx.FormString("content")
1860-
if err := issue_service.ChangeContent(issue, ctx.User, content); err != nil {
1860+
if err := issue_service.ChangeContent(issue, ctx.Doer, content); err != nil {
18611861
ctx.ServerError("ChangeContent", err)
18621862
return
18631863
}

0 commit comments

Comments
 (0)