diff --git a/backend/src/app/rpc/management/nitrate.clj b/backend/src/app/rpc/management/nitrate.clj index f6f5073d8a..c6178cda54 100644 --- a/backend/src/app/rpc/management/nitrate.clj +++ b/backend/src/app/rpc/management/nitrate.clj @@ -825,11 +825,21 @@ RETURNING id, deleted_at;") t.name, t.photo_id, t.created_at, - (SELECT MAX(p2.modified_at) - FROM project AS p2 - WHERE p2.team_id = t.id - AND p2.deleted_at IS NULL - AND p2.is_default IS FALSE) AS last_activity_at, + (SELECT MAX(activity.modified_at) + FROM ( + SELECT p2.modified_at + FROM project AS p2 + WHERE p2.team_id = t.id + AND p2.deleted_at IS NULL + AND p2.is_default IS FALSE + UNION ALL + SELECT f.modified_at + FROM file AS f + JOIN project AS p ON p.id = f.project_id + WHERE p.team_id = t.id + AND p.deleted_at IS NULL + AND f.deleted_at IS NULL + ) AS activity) AS last_activity_at, owner_tpr.profile_id AS owner_profile_id, owner_p.fullname AS owner_name, owner_p.photo_id AS owner_photo_id, diff --git a/backend/test/backend_tests/rpc_management_nitrate_test.clj b/backend/test/backend_tests/rpc_management_nitrate_test.clj index bff2a59478..8ca30ccfce 100644 --- a/backend/test/backend_tests/rpc_management_nitrate_test.clj +++ b/backend/test/backend_tests/rpc_management_nitrate_test.clj @@ -171,6 +171,62 @@ (t/is (= #{(:id team1) (:id team2)} (->> out :result :teams (map :id) set))))) +(t/deftest get-teams-detail-last-activity-reflects-file-modifications + (let [profile (th/create-profile* 1 {:is-active true}) + team (th/create-team* 1 {:profile-id (:id profile)}) + organization-id (uuid/random) + org-summary {:id organization-id + :teams [{:id (:id team)}]} + params {::th/type :get-teams-detail + ::rpc/profile-id (:id profile) + :organization-id organization-id} + + call! (fn [] + (with-redefs [nitrate/call (fn [_cfg method _params] + (case method + :get-org-summary org-summary + nil))] + (management-command-with-nitrate! params))) + + empty-out (call!) + empty-team (-> empty-out :result first) + + project (th/create-project* 1 {:profile-id (:id profile) + :team-id (:id team)}) + file (th/create-file* 1 {:profile-id (:id profile) + :project-id (:id project)}) + file-after-create (th/db-get :file {:id (:id file)}) + project-after-create (th/db-get :project {:id (:id project)}) + expected-activity-create (if (.isAfter (:modified-at file-after-create) + (:modified-at project-after-create)) + (:modified-at file-after-create) + (:modified-at project-after-create)) + + with-file-out (call!) + with-file (-> with-file-out :result first) + + new-activity (ct/in-future "1h") + _ (th/db-update! :file + {:modified-at new-activity} + {:id (:id file)}) + file-after-update (th/db-get :file {:id (:id file)}) + + updated-out (call!) + updated-team (-> updated-out :result first)] + + (t/is (th/success? empty-out)) + (t/is (= (:id team) (:id empty-team))) + (t/is (nil? (:last-activity-at empty-team))) + + (t/is (th/success? with-file-out)) + (t/is (= (:id team) (:id with-file))) + (t/is (= expected-activity-create (:last-activity-at with-file))) + + (t/is (th/success? updated-out)) + (t/is (= (:id team) (:id updated-team))) + (t/is (= (:modified-at file-after-update) (:last-activity-at updated-team))) + (t/is (not= (:last-activity-at with-file) (:last-activity-at updated-team))))) + (t/deftest notify-organization-deletion-prefixes-teams-and-publishes-org-deleted-event (let [profile (th/create-profile* 1 {:is-active true}) ;; One team will have files -> it will be kept and renamed.