forgejo/routers/api/v1/repo
fluzz 2030f3b965
[FEAT] allow setting the update date on issues and comments
This field adds the possibility to set the update date when modifying
an issue through the API.

A 'NoAutoDate' in-memory field is added in the Issue struct.
If the update_at field is set, NoAutoDate is set to true and the
Issue's UpdatedUnix field is filled.

That information is passed down to the functions that actually updates
the database, which have been modified to not auto update dates if
requested.

A guard is added to the 'EditIssue' API call, to checks that the
udpate_at date is between the issue's creation date and the current
date (to avoid 'malicious' changes). It also limits the new feature
to project's owners and admins.

(cherry picked from commit c524d33402)

Add a SetIssueUpdateDate() function in services/issue.go

That function is used by some API calls to set the NoAutoDate and
UpdatedUnix fields of an Issue if an updated_at date is provided.

(cherry picked from commit f061caa655)

Add an updated_at field to the API calls related to Issue's Labels.

The update date is applied to the issue's comment created to inform
about the modification of the issue's labels.

(cherry picked from commit ea36cf80f5)

Add an updated_at field to the API call for issue's attachment creation

The update date is applied to the issue's comment created to inform
about the modification of the issue's content, and is set as the
asset creation date.

(cherry picked from commit 96150971ca)

Checking Issue changes, with and without providing an updated_at date

Those unit tests are added:

- TestAPIEditIssueWithAutoDate
- TestAPIEditIssueWithNoAutoDate

- TestAPIAddIssueLabelsWithAutoDate
- TestAPIAddIssueLabelsWithNoAutoDate

- TestAPICreateIssueAttachmentWithAutoDate
- TestAPICreateIssueAttachmentWithNoAutoDate

(cherry picked from commit 4926a5d7a2)

Add an updated_at field to the API call for issue's comment creation

The update date is used as the comment creation date, and is applied to
the issue as the update creation date.

(cherry picked from commit 76c8faecdc)

Add an updated_at field to the API call for issue's comment edition

The update date is used as the comment update date, and is applied to
the issue as an update date.

(cherry picked from commit cf787ad7fd)

Add an updated_at field to the API call for comment's attachment creation

The update date is applied to the comment, and is set as the asset
creation date.

(cherry picked from commit 1e4ff424d3)

Checking Comment changes, with and without providing an updated_at date

Those unit tests are added:

- TestAPICreateCommentWithAutoDate
- TestAPICreateCommentWithNoAutoDate

- TestAPIEditCommentWithAutoDate
- TestAPIEditCommentWithNoAutoDate

- TestAPICreateCommentAttachmentWithAutoDate
- TestAPICreateCommentAttachmentWithNoAutoDate

(cherry picked from commit da932152f1)

Pettier code to set the update time of comments

Now uses sess.AllCols().NoAutoToime().SetExpr("updated_unix", ...)

XORM is smart enough to compose one single SQL UPDATE which all
columns + updated_unix.

(cherry picked from commit 1f6a42808d)

Issue edition: Keep the max of the milestone and issue update dates.

When editing an issue via the API, an updated_at date can be provided.
If the EditIssue call changes the issue's milestone, the milestone's
update date is to be changed accordingly, but only with a greater
value.

This ensures that a milestone's update date is the max of all issue's
update dates.

(cherry picked from commit 8f22ea182e)

Rewrite the 'AutoDate' tests using subtests

Also add a test to check the permissions to set a date, and a test
to check update dates on milestones.

The tests related to 'AutoDate' are:
- TestAPIEditIssueAutoDate
- TestAPIAddIssueLabelsAutoDate
- TestAPIEditIssueMilestoneAutoDate
- TestAPICreateIssueAttachmentAutoDate
- TestAPICreateCommentAutoDate
- TestAPIEditCommentWithDate
- TestAPICreateCommentAttachmentAutoDate

(cherry picked from commit 961fd13c55)
(cherry picked from commit d52f4eea44)
(cherry picked from commit 3540ea2a43)

Conflicts:
	services/issue/issue.go
	https://codeberg.org/forgejo/forgejo/pulls/1415
(cherry picked from commit 56720ade00)

Conflicts:
	routers/api/v1/repo/issue_label.go
	https://codeberg.org/forgejo/forgejo/pulls/1462
(cherry picked from commit 47c78927d6)
2023-09-25 16:02:39 +02:00
..
action.go Refactor secrets modification logic (#26873) 2023-09-05 15:21:02 +00:00
avatar.go Add missing 404 response to Swagger (#27038) 2023-09-13 10:37:54 +08:00
blob.go Add missing 404 response to Swagger (#27038) 2023-09-13 10:37:54 +08:00
branch.go Updates to the API for archived repos (#27149) 2023-09-21 23:43:29 +00:00
collaborators.go Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
commits.go Filter get single commit (#24613) 2023-05-10 09:34:07 +08:00
file.go Updates to the API for archived repos (#27149) 2023-09-21 23:43:29 +00:00
fork.go Reduce usage of db.DefaultContext (#27073) 2023-09-14 17:09:32 +00:00
git_hook.go Add missing 404 response to Swagger (#27038) 2023-09-13 10:37:54 +08:00
git_ref.go Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
hook.go Add missing 404 response to Swagger (#27038) 2023-09-13 10:37:54 +08:00
hook_test.go Move web/api context related testing function into a separate package (#26859) 2023-09-01 11:26:07 +00:00
issue.go [FEAT] allow setting the update date on issues and comments 2023-09-25 16:02:39 +02:00
issue_attachment.go [FEAT] allow setting the update date on issues and comments 2023-09-25 16:02:39 +02:00
issue_comment.go [FEAT] allow setting the update date on issues and comments 2023-09-25 16:02:39 +02:00
issue_comment_attachment.go [FEAT] allow setting the update date on issues and comments 2023-09-25 16:02:39 +02:00
issue_dependency.go Updates to the API for archived repos (#27149) 2023-09-21 23:43:29 +00:00
issue_label.go [FEAT] allow setting the update date on issues and comments 2023-09-25 16:02:39 +02:00
issue_pin.go Add missing 404 response to Swagger (#27038) 2023-09-13 10:37:54 +08:00
issue_reaction.go Add missing 404 response to Swagger (#27038) 2023-09-13 10:37:54 +08:00
issue_stopwatch.go Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
issue_subscription.go Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
issue_tracked_time.go Add missing 404 response to Swagger (#27038) 2023-09-13 10:37:54 +08:00
key.go Add missing 404 response to Swagger (#27038) 2023-09-13 10:37:54 +08:00
label.go Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
language.go Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
main_test.go Merge setting.InitXXX into one function with options (#24389) 2023-05-04 11:55:35 +08:00
migrate.go move repository deletion to service layer (#26948) 2023-09-08 04:51:15 +00:00
milestone.go Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
mirror.go Add RemoteAddress to mirrors (#26952) 2023-09-16 16:03:02 +00:00
notes.go Filters for GetAllCommits (#24568) 2023-05-09 09:06:05 +08:00
patch.go Updates to the API for archived repos (#27149) 2023-09-21 23:43:29 +00:00
pull.go Updates to the API for archived repos (#27149) 2023-09-21 23:43:29 +00:00
pull_review.go Add missing 404 response to Swagger (#27038) 2023-09-13 10:37:54 +08:00
release.go Add missing 404 response to Swagger (#27038) 2023-09-13 10:37:54 +08:00
release_attachment.go More refactoring of db.DefaultContext (#27083) 2023-09-15 06:13:19 +00:00
release_tags.go For API attachments, use API URL (#25639) 2023-07-10 09:31:19 +00:00
repo.go Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
repo_test.go Move web/api context related testing function into a separate package (#26859) 2023-09-01 11:26:07 +00:00
star.go More refactoring of db.DefaultContext (#27083) 2023-09-15 06:13:19 +00:00
status.go Add missing 404 response to Swagger (#27038) 2023-09-13 10:37:54 +08:00
subscriber.go More refactoring of db.DefaultContext (#27083) 2023-09-15 06:13:19 +00:00
tag.go Updates to the API for archived repos (#27149) 2023-09-21 23:43:29 +00:00
teams.go More refactoring of db.DefaultContext (#27083) 2023-09-15 06:13:19 +00:00
topic.go Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
transfer.go Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
tree.go Add missing 404 response to Swagger (#27038) 2023-09-13 10:37:54 +08:00
wiki.go Updates to the API for archived repos (#27149) 2023-09-21 23:43:29 +00:00