forgejo/models/issues
Earl Warren d072525b35
[v1.22] [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)
(cherry picked from commit 2030f3b965)
(cherry picked from commit f02aeb7698)

Conflicts:
	routers/api/v1/repo/issue_attachment.go
	routers/api/v1/repo/issue_comment_attachment.go
	https://codeberg.org/forgejo/forgejo/pulls/1575
2023-10-09 19:11:03 +02:00
..
assignees.go Make more functions use ctx instead of db.DefaultContext (#24068) 2023-04-14 14:18:28 -04:00
assignees_test.go Even more db.DefaultContext refactor (#27352) 2023-10-03 10:30:41 +00:00
comment.go [v1.22] [FEAT] allow setting the update date on issues and comments 2023-10-09 19:11:03 +02:00
comment_code.go More db.DefaultContext refactor (#27265) 2023-09-29 12:12:54 +00:00
comment_list.go Add logs for data broken of comment review (#27326) 2023-09-29 02:31:36 +00:00
comment_test.go More db.DefaultContext refactor (#27265) 2023-09-29 12:12:54 +00:00
content_history.go Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
content_history_test.go Rename Sync2 -> Sync (#26479) 2023-08-13 21:17:21 +02:00
dependency.go Add API to manage issue dependencies (#17935) 2023-03-28 13:23:25 -04:00
dependency_test.go refactor some functions to support ctx as first parameter (#21878) 2022-12-03 10:48:26 +08:00
issue.go [v1.22] [FEAT] allow setting the update date on issues and comments 2023-10-09 19:11:03 +02:00
issue_index.go Another round of db.DefaultContext refactor (#27103) 2023-09-25 13:17:37 +00:00
issue_label.go Don't let API add 2 exclusive labels from same scope (#27433) 2023-10-05 03:37:36 +00:00
issue_label_test.go Don't let API add 2 exclusive labels from same scope (#27433) 2023-10-05 03:37:36 +00:00
issue_list.go Add context parameter to some database functions (#26055) 2023-07-22 22:14:27 +08:00
issue_list_test.go Add context parameter to some database functions (#26055) 2023-07-22 22:14:27 +08:00
issue_lock.go Rename almost all Ctx functions (#22071) 2022-12-10 10:46:31 +08:00
issue_project.go Use more IssueList instead of []*Issue (#26369) 2023-08-07 19:26:40 +00:00
issue_search.go Fix review request number and add more tests (#27104) 2023-09-21 13:59:50 +02:00
issue_stats.go Another round of db.DefaultContext refactor (#27103) 2023-09-25 13:17:37 +00:00
issue_test.go Even more db.DefaultContext refactor (#27352) 2023-10-03 10:30:41 +00:00
issue_update.go [v1.22] [FEAT] allow setting the update date on issues and comments 2023-10-09 19:11:03 +02:00
issue_user.go Add index to issue_user.issue_id (#27154) 2023-09-21 01:30:48 +00:00
issue_user_test.go Fix bug with sqlite load read (#26305) 2023-08-05 10:40:27 +08:00
issue_watch.go Even more db.DefaultContext refactor (#27352) 2023-10-03 10:30:41 +00:00
issue_watch_test.go Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
issue_xref.go [v1.22] [FEAT] allow setting the update date on issues and comments 2023-10-09 19:11:03 +02:00
issue_xref_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
label.go Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
label_test.go Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
main_test.go make writing main test easier (#27270) 2023-09-28 01:38:53 +00:00
milestone.go [v1.22] [FEAT] allow setting the update date on issues and comments 2023-10-09 19:11:03 +02:00
milestone_list.go Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
milestone_test.go Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
pull.go Even more db.DefaultContext refactor (#27352) 2023-10-03 10:30:41 +00:00
pull_list.go More refactoring of db.DefaultContext (#27083) 2023-09-15 06:13:19 +00:00
pull_test.go More refactoring of db.DefaultContext (#27083) 2023-09-15 06:13:19 +00:00
reaction.go Another round of db.DefaultContext refactor (#27103) 2023-09-25 13:17:37 +00:00
reaction_test.go Another round of db.DefaultContext refactor (#27103) 2023-09-25 13:17:37 +00:00
review.go More db.DefaultContext refactor (#27265) 2023-09-29 12:12:54 +00:00
review_list.go Another round of db.DefaultContext refactor (#27103) 2023-09-25 13:17:37 +00:00
review_test.go More db.DefaultContext refactor (#27265) 2023-09-29 12:12:54 +00:00
stopwatch.go Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
stopwatch_test.go Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
tracked_time.go Even more db.DefaultContext refactor (#27352) 2023-10-03 10:30:41 +00:00
tracked_time_test.go Even more db.DefaultContext refactor (#27352) 2023-10-03 10:30:41 +00:00