forgejo/models/issues
Earl Warren 77ba6be1da
[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
(cherry picked from commit d072525b35)
(cherry picked from commit 8424d0ab3d)
(cherry picked from commit 5cc62caec7)
(cherry picked from commit d6300d5dcd)

[FEAT] allow setting the update date on issues and comments (squash) apply the 'update_at' value to the cross-ref comments (#1676)

[this is a follow-up to PR #764]

When a comment of issue A referencing issue B is added with a forced 'updated_at' date, that date has to be applied to the comment created in issue B.

-----

Comment:

While trying my 'RoundUp migration script', I found that this case was forgotten in PR #764 - my apologies...

I'll try to write a functional test, base on models/issues/issue_xref_test.go

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/1676
Co-authored-by: fluzz <fluzz@freedroid.org>
Co-committed-by: fluzz <fluzz@freedroid.org>
(cherry picked from commit ac4f727f63)
(cherry picked from commit 5110476ee9)
2023-11-13 12:21:09 +01: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 [FEAT] allow setting the update date on issues and comments 2023-11-13 12:21:09 +01:00
comment_code.go Penultimate round of db.DefaultContext refactor (#27414) 2023-10-11 04:24:07 +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 Penultimate round of db.DefaultContext refactor (#27414) 2023-10-11 04:24:07 +00:00
dependency_test.go Penultimate round of db.DefaultContext refactor (#27414) 2023-10-11 04:24:07 +00:00
issue.go [FEAT] allow setting the update date on issues and comments 2023-11-13 12:21:09 +01:00
issue_index.go Another round of db.DefaultContext refactor (#27103) 2023-09-25 13:17:37 +00:00
issue_label.go Penultimate round of db.DefaultContext refactor (#27414) 2023-10-11 04:24:07 +00:00
issue_label_test.go Penultimate round of db.DefaultContext refactor (#27414) 2023-10-11 04:24:07 +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 Penultimate round of db.DefaultContext refactor (#27414) 2023-10-11 04:24:07 +00:00
issue_project.go Clean some functions about project issue (#27705) 2023-10-20 14:01:25 +02:00
issue_search.go Fix issue not showing on default board and add test (#27720) 2023-10-25 11:51:49 +00:00
issue_stats.go Another round of db.DefaultContext refactor (#27103) 2023-09-25 13:17:37 +00:00
issue_test.go Show total TrackedTime on issue/pull/milestone lists (#26672) 2023-10-19 14:08:31 +00:00
issue_update.go [FEAT] allow setting the update date on issues and comments 2023-11-13 12:21:09 +01: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 [FEAT] allow setting the update date on issues and comments 2023-11-13 12:21:09 +01: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 Penultimate round of db.DefaultContext refactor (#27414) 2023-10-11 04:24:07 +00:00
main_test.go make writing main test easier (#27270) 2023-09-28 01:38:53 +00:00
milestone.go [FEAT] allow setting the update date on issues and comments 2023-11-13 12:21:09 +01:00
milestone_list.go Penultimate round of db.DefaultContext refactor (#27414) 2023-10-11 04:24:07 +00:00
milestone_test.go Penultimate round of db.DefaultContext refactor (#27414) 2023-10-11 04:24:07 +00:00
pull.go Replace -1 with GhostUserID (#27703) 2023-10-20 14:43:08 +00:00
pull_list.go More refactoring of db.DefaultContext (#27083) 2023-09-15 06:13:19 +00:00
pull_test.go Penultimate round of db.DefaultContext refactor (#27414) 2023-10-11 04:24:07 +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 Fix 500 when deleting a dismissed review (#27903) 2023-11-05 13:25:40 +00:00
review_list.go Another round of db.DefaultContext refactor (#27103) 2023-09-25 13:17:37 +00:00
review_test.go Fix 500 when deleting a dismissed review (#27903) 2023-11-05 13:25:40 +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 Show total TrackedTime on issue/pull/milestone lists (#26672) 2023-10-19 14:08:31 +00:00
tracked_time_test.go Show total TrackedTime on issue/pull/milestone lists (#26672) 2023-10-19 14:08:31 +00:00