forgejo/models/repo
fluzz 47c78927d6
[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
2023-09-18 14:11:24 +02:00
..
archiver.go Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
attachment.go [FEAT] allow setting the update date on issues and comments 2023-09-18 14:11:24 +02:00
attachment_test.go More refactoring of db.DefaultContext (#27083) 2023-09-15 06:13:19 +00:00
avatar.go Add context cache as a request level cache (#22294) 2023-02-15 21:37:34 +08:00
collaboration.go Always reuse transaction (#22362) 2023-01-08 09:34:58 +08:00
collaboration_test.go Add unit test for repository collaboration (#25640) 2023-07-03 21:41:14 +00:00
fork.go Reduce usage of db.DefaultContext (#27073) 2023-09-14 17:09:32 +00:00
fork_test.go refactor some functions to support ctx as first parameter (#21878) 2022-12-03 10:48:26 +08:00
git.go Reduce usage of db.DefaultContext (#27073) 2023-09-14 17:09:32 +00:00
issue.go Rename almost all Ctx functions (#22071) 2022-12-10 10:46:31 +08:00
language_stats.go Round language stats percentage using largest remainder (#22026) 2022-12-08 10:47:47 +08:00
main_test.go move repository deletion to service layer (#26948) 2023-09-08 04:51:15 +00:00
mirror.go Add RemoteAddress to mirrors (#26952) 2023-09-16 16:03:02 +00:00
pushmirror.go Add RemoteAddress to mirrors (#26952) 2023-09-16 16:03:02 +00:00
pushmirror_test.go Replace interface{} with any (#25686) 2023-07-04 18:36:08 +00:00
redirect.go Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
redirect_test.go Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
release.go Move some functions to service layer (#26969) 2023-09-08 21:09:23 +00:00
release_test.go Move some functions to service layer (#26969) 2023-09-08 21:09:23 +00:00
repo.go Add RemoteAddress to mirrors (#26952) 2023-09-16 16:03:02 +00:00
repo_indexer.go Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
repo_list.go Fix counting and filtering on the dashboard page for issues (#26657) 2023-08-23 02:29:17 +00:00
repo_list_test.go Replace 'userxx' with 'orgxx' in all test files when the user type is org (#27052) 2023-09-14 02:59:53 +00:00
repo_test.go Replace 'userxx' with 'orgxx' in all test files when the user type is org (#27052) 2023-09-14 02:59:53 +00:00
repo_unit.go Replace util.SliceXxx with slices.Xxx (#26958) 2023-09-07 09:37:47 +00:00
repo_unit_test.go add disable workflow feature (#26413) 2023-08-14 15:14:30 +00:00
search.go Split "modules/context.go" to separate files (#24569) 2023-05-08 17:36:54 +08:00
star.go More refactoring of db.DefaultContext (#27083) 2023-09-15 06:13:19 +00:00
star_test.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
topic_test.go Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
update.go Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
upload.go More refactoring of db.DefaultContext (#27083) 2023-09-15 06:13:19 +00:00
user_repo.go Refactor authors dropdown (send get request from frontend to avoid long wait time) (#23890) 2023-04-07 08:11:02 +08:00
user_repo_test.go Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
watch.go More refactoring of db.DefaultContext (#27083) 2023-09-15 06:13:19 +00:00
watch_test.go More refactoring of db.DefaultContext (#27083) 2023-09-15 06:13:19 +00:00
wiki.go Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
wiki_test.go Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00