Skip to content

Commit ddd4786

Browse files
committed
Allow Card#last_updated_at to be set
This is useful when doing an import from another system. I'm currently working on a script to import our Github issues into Fizzy. This is discussed in #2056 (comment)
1 parent 5d181af commit ddd4786

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

app/controllers/cards_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ def ensure_permission_to_administer_card
6161
end
6262

6363
def card_params
64-
params.expect(card: [ :status, :title, :description, :image, :created_at, tag_ids: [] ])
64+
params.expect(card: [ :status, :title, :description, :image, :created_at, :last_active_at, tag_ids: [] ])
6565
end
6666
end

app/models/card/eventable.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ module Card::Eventable
44
include ::Eventable
55

66
included do
7-
before_create { self.last_active_at = Time.current }
7+
before_create { self.last_active_at ||= created_at }
88

99
after_save :track_title_change, if: :saved_change_to_title?
1010
end
1111

1212
def event_was_created(event)
1313
transaction do
1414
create_system_comment_for(event)
15-
touch_last_active_at
15+
touch_last_active_at unless was_just_published?
1616
end
1717
end
1818

docs/API.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ Creates a new card in a board.
495495
| `image` | file | No | Header image for the card |
496496
| `tag_ids` | array | No | Array of tag IDs to apply to the card |
497497
| `created_at` | datetime | No | Override creation timestamp (ISO 8601 format) |
498+
| `last_active_at` | datetime | No | Override last activity timestamp (ISO 8601 format) |
498499

499500
__Request:__
500501

@@ -522,6 +523,7 @@ Updates a card.
522523
| `status` | string | No | Card status: `drafted`, `published` |
523524
| `image` | file | No | Header image for the card |
524525
| `tag_ids` | array | No | Array of tag IDs to apply to the card |
526+
| `last_active_at` | datetime | No | Override last activity timestamp (ISO 8601 format) |
525527

526528
__Request:__
527529

test/controllers/cards_controller_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,22 @@ class CardsControllerTest < ActionDispatch::IntegrationTest
173173
assert_equal custom_time, Card.last.created_at
174174
end
175175

176+
test "create as JSON with custom last_active_at" do
177+
created_time = Time.utc(2024, 1, 15, 10, 30, 0)
178+
last_active_time = Time.utc(2024, 6, 1, 12, 0, 0)
179+
180+
assert_difference -> { Card.count }, +1 do
181+
post board_cards_path(boards(:writebook)),
182+
params: { card: { title: "Card with activity", created_at: created_time, last_active_at: last_active_time } },
183+
as: :json
184+
end
185+
186+
assert_response :created
187+
card = Card.last
188+
assert_equal created_time, card.created_at
189+
assert_equal last_active_time, card.last_active_at
190+
end
191+
176192
test "update as JSON" do
177193
card = cards(:logo)
178194
put card_path(card, format: :json), params: { card: { title: "Update test" } }

0 commit comments

Comments
 (0)