From bdb1742d59596b2561058b4d47276cb291264373 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 13 Dec 2023 17:45:55 +0100 Subject: [PATCH] :bug: Fix incorrect feature checking on move project --- backend/src/app/rpc/commands/management.clj | 10 +- .../backend_tests/rpc_management_test.clj | 118 +++++++++--------- 2 files changed, 70 insertions(+), 58 deletions(-) diff --git a/backend/src/app/rpc/commands/management.clj b/backend/src/app/rpc/commands/management.clj index 33df92839..7b8a03bc3 100644 --- a/backend/src/app/rpc/commands/management.clj +++ b/backend/src/app/rpc/commands/management.clj @@ -391,7 +391,15 @@ ;; Check the teams compatibility (let [orig-team (teams/get-team conn :profile-id profile-id :team-id (:team-id project)) dest-team (teams/get-team conn :profile-id profile-id :team-id team-id)] - (cfeat/check-teams-compatibility! orig-team dest-team)) + (cfeat/check-teams-compatibility! orig-team dest-team) + + ;; Check if all pending to move files are compaib + (let [features (cfeat/get-team-enabled-features cf/flags dest-team)] + (doseq [file (->> (db/query conn :file + {:project-id project-id} + {:columns [:features]}) + (map files/decode-row))] + (cfeat/check-file-features! features (:features file))))) ;; move project to the destination team (db/update! conn :project diff --git a/backend/test/backend_tests/rpc_management_test.clj b/backend/test/backend_tests/rpc_management_test.clj index 2b5f182e8..f9b62d1b0 100644 --- a/backend/test/backend_tests/rpc_management_test.clj +++ b/backend/test/backend_tests/rpc_management_test.clj @@ -69,12 +69,12 @@ (t/is (not= (:id file1) (:id result))) ;; Check that the new file has a correct file library relation - (let [[item :as rows] (db/query th/*pool* :file-library-rel {:file-id (:id result)})] + (let [[item :as rows] (th/db-query :file-library-rel {:file-id (:id result)})] (t/is (= 1 (count rows))) (t/is (= (:id file2) (:library-file-id item)))) ;; Check that the new file has a correct file media objects - (let [[item :as rows] (db/query th/*pool* :file-media-object {:file-id (:id result)})] + (let [[item :as rows] (th/db-query :file-media-object {:file-id (:id result)})] (t/is (= 1 (count rows))) ;; Check that both items have different ids @@ -91,7 +91,7 @@ (t/is (not (contains? (get-in result [:data :media]) (:id mobj))))) ;; Check the total number of files - (let [rows (db/query th/*pool* :file {:project-id (:id project)})] + (let [rows (th/db-query :file {:project-id (:id project)})] (t/is (= 3 (count rows)))))))) (t/deftest duplicate-file-with-deleted-relations @@ -139,15 +139,15 @@ (t/is (not= (:id file1) (:id result))) ;; Check that there are no relation to a deleted library - (let [[item :as rows] (db/query th/*pool* :file-library-rel {:file-id (:id result)})] + (let [[item :as rows] (th/db-query :file-library-rel {:file-id (:id result)})] (t/is (= 0 (count rows)))) ;; Check that the new file has no media objects - (let [[item :as rows] (db/query th/*pool* :file-media-object {:file-id (:id result)})] + (let [[item :as rows] (th/db-query :file-media-object {:file-id (:id result)})] (t/is (= 0 (count rows)))) ;; Check the total number of files - (let [rows (db/query th/*pool* :file {:project-id (:id project)})] + (let [rows (th/db-query :file {:project-id (:id project)})] (t/is (= 3 (count rows)))))))) (t/deftest duplicate-project @@ -196,16 +196,16 @@ (t/is (not= (:id project) (:id result))) ;; Check the total number of projects (previously is 2, now is 3) - (let [rows (db/query th/*pool* :project {:team-id (:default-team-id profile)})] + (let [rows (th/db-query :project {:team-id (:default-team-id profile)})] (t/is (= 3 (count rows)))) ;; Check that the new project has the same files - (let [p1-files (db/query th/*pool* :file - {:project-id (:id project)} - {:order-by [:name]}) - p2-files (db/query th/*pool* :file - {:project-id (:id result)} - {:order-by [:name]})] + (let [p1-files (th/db-query :file + {:project-id (:id project)} + {:order-by [:name]}) + p2-files (th/db-query :file + {:project-id (:id result)} + {:order-by [:name]})] (t/is (= (count p1-files) (count p2-files))) @@ -260,16 +260,16 @@ (t/is (not= (:id project) (:id result))) ;; Check the total number of projects (previously is 2, now is 3) - (let [rows (db/query th/*pool* :project {:team-id (:default-team-id profile)})] + (let [rows (th/db-query :project {:team-id (:default-team-id profile)})] (t/is (= 3 (count rows)))) ;; Check that the new project has only the second file - (let [p1-files (db/query th/*pool* :file - {:project-id (:id project)} - {:order-by [:name]}) - p2-files (db/query th/*pool* :file - {:project-id (:id result)} - {:order-by [:name]})] + (let [p1-files (th/db-query :file + {:project-id (:id project)} + {:order-by [:name]}) + p2-files (th/db-query :file + {:project-id (:id result)} + {:order-by [:name]})] (t/is (= (count (rest p1-files)) (count p2-files))) @@ -318,11 +318,11 @@ (t/is (th/ex-of-code? error :cant-move-to-same-project))) ;; initially project1 should have 2 files - (let [rows (db/query th/*pool* :file {:project-id (:id project1)})] + (let [rows (th/db-query :file {:project-id (:id project1)})] (t/is (= 2 (count rows)))) ;; initially project2 should be empty - (let [rows (db/query th/*pool* :file {:project-id (:id project2)})] + (let [rows (th/db-query :file {:project-id (:id project2)})] (t/is (= 0 (count rows)))) ;; move a file1 to project2 (in the same team) @@ -337,21 +337,21 @@ (t/is (nil? (:result out))) ;; project1 now should contain 1 file - (let [rows (db/query th/*pool* :file {:project-id (:id project1)})] + (let [rows (th/db-query :file {:project-id (:id project1)})] (t/is (= 1 (count rows)))) ;; project2 now should contain 1 file - (let [rows (db/query th/*pool* :file {:project-id (:id project2)})] + (let [rows (th/db-query :file {:project-id (:id project2)})] (t/is (= 1 (count rows)))) ;; file1 should be still linked to file2 - (let [[item :as rows] (db/query th/*pool* :file-library-rel {:file-id (:id file1)})] + (let [[item :as rows] (th/db-query :file-library-rel {:file-id (:id file1)})] (t/is (= 1 (count rows))) (t/is (= (:file-id item) (:id file1))) (t/is (= (:library-file-id item) (:id file2)))) ;; should be no libraries on file2 - (let [rows (db/query th/*pool* :file-library-rel {:file-id (:id file2)})] + (let [rows (th/db-query :file-library-rel {:file-id (:id file2)})] (t/is (= 0 (count rows))))))) @@ -384,27 +384,27 @@ ;; --- initial data checks ;; the project1 should have 3 files - (let [rows (db/query th/*pool* :file {:project-id (:id project1)})] + (let [rows (th/db-query :file {:project-id (:id project1)})] (t/is (= 3 (count rows)))) ;; should be no files on project2 - (let [rows (db/query th/*pool* :file {:project-id (:id project2)})] + (let [rows (th/db-query :file {:project-id (:id project2)})] (t/is (= 0 (count rows)))) ;; the file1 should be linked to file2 - (let [[item :as rows] (db/query th/*pool* :file-library-rel {:file-id (:id file1)})] + (let [[item :as rows] (th/db-query :file-library-rel {:file-id (:id file1)})] (t/is (= 1 (count rows))) (t/is (= (:file-id item) (:id file1))) (t/is (= (:library-file-id item) (:id file2)))) ;; the file2 should be linked to file3 - (let [[item :as rows] (db/query th/*pool* :file-library-rel {:file-id (:id file2)})] + (let [[item :as rows] (th/db-query :file-library-rel {:file-id (:id file2)})] (t/is (= 1 (count rows))) (t/is (= (:file-id item) (:id file2))) (t/is (= (:library-file-id item) (:id file3)))) ;; should be no libraries on file3 - (let [rows (db/query th/*pool* :file-library-rel {:file-id (:id file3)})] + (let [rows (th/db-query :file-library-rel {:file-id (:id file3)})] (t/is (= 0 (count rows)))) ;; move to other project in other team @@ -418,23 +418,23 @@ (t/is (nil? (:result out))) ;; project1 now should have 2 file - (let [[item1 item2 :as rows] (db/query th/*pool* :file {:project-id (:id project1)} - {:order-by [:created-at]})] + (let [[item1 item2 :as rows] (th/db-query :file {:project-id (:id project1)} + {:order-by [:created-at]})] ;; (clojure.pprint/pprint rows) (t/is (= 2 (count rows))) (t/is (= (:id item1) (:id file2)))) ;; project2 now should have 1 file - (let [[item :as rows] (db/query th/*pool* :file {:project-id (:id project2)})] + (let [[item :as rows] (th/db-query :file {:project-id (:id project2)})] (t/is (= 1 (count rows))) (t/is (= (:id item) (:id file1)))) ;; the moved file1 should not have any link to libraries - (let [rows (db/query th/*pool* :file-library-rel {:file-id (:id file1)})] + (let [rows (th/db-query :file-library-rel {:file-id (:id file1)})] (t/is (zero? (count rows)))) ;; the file2 should still be linked to file3 - (let [[item :as rows] (db/query th/*pool* :file-library-rel {:file-id (:id file2)})] + (let [[item :as rows] (th/db-query :file-library-rel {:file-id (:id file2)})] (t/is (= 1 (count rows))) (t/is (= (:file-id item) (:id file2))) (t/is (= (:library-file-id item) (:id file3))))))) @@ -462,21 +462,21 @@ ;; --- initial data checks ;; the project1 should have 2 files - (let [rows (db/query th/*pool* :file {:project-id (:id project1)})] + (let [rows (th/db-query :file {:project-id (:id project1)})] (t/is (= 2 (count rows)))) ;; should be no files on project2 - (let [rows (db/query th/*pool* :file {:project-id (:id project2)})] + (let [rows (th/db-query :file {:project-id (:id project2)})] (t/is (= 0 (count rows)))) ;; the file1 should be linked to file2 - (let [[item :as rows] (db/query th/*pool* :file-library-rel {:file-id (:id file1)})] + (let [[item :as rows] (th/db-query :file-library-rel {:file-id (:id file1)})] (t/is (= 1 (count rows))) (t/is (= (:file-id item) (:id file1))) (t/is (= (:library-file-id item) (:id file2)))) ;; should be no libraries on file2 - (let [rows (db/query th/*pool* :file-library-rel {:file-id (:id file2)})] + (let [rows (th/db-query :file-library-rel {:file-id (:id file2)})] (t/is (= 0 (count rows)))) ;; move the library to other project @@ -490,22 +490,22 @@ (t/is (nil? (:result out))) ;; project1 now should have 1 file - (let [[item :as rows] (db/query th/*pool* :file {:project-id (:id project1)} - {:order-by [:created-at]})] + (let [[item :as rows] (th/db-query :file {:project-id (:id project1)} + {:order-by [:created-at]})] (t/is (= 1 (count rows))) (t/is (= (:id item) (:id file1)))) ;; project2 now should have 1 file - (let [[item :as rows] (db/query th/*pool* :file {:project-id (:id project2)})] + (let [[item :as rows] (th/db-query :file {:project-id (:id project2)})] (t/is (= 1 (count rows))) (t/is (= (:id item) (:id file2)))) ;; the file1 should not have any link to libraries - (let [rows (db/query th/*pool* :file-library-rel {:file-id (:id file1)})] + (let [rows (th/db-query :file-library-rel {:file-id (:id file1)})] (t/is (zero? (count rows)))) ;; the file2 should not have any link to libraries - (let [rows (db/query th/*pool* :file-library-rel {:file-id (:id file2)})] + (let [rows (th/db-query :file-library-rel {:file-id (:id file2)})] (t/is (zero? (count rows))))))) (t/deftest move-project @@ -538,16 +538,17 @@ ;; --- initial data checks ;; the project1 should have 2 files - (let [rows (db/query th/*pool* :file {:project-id (:id project1)})] + (let [rows (th/db-query :file {:project-id (:id project1)})] (t/is (= 2 (count rows)))) ;; the project2 should have 1 file - (let [rows (db/query th/*pool* :file {:project-id (:id project2)})] + (let [rows (th/db-query :file {:project-id (:id project2)})] (t/is (= 1 (count rows)))) ;; the file1 should be linked to file2 and file3 - (let [[item1 item2 :as rows] (db/query th/*pool* :file-library-rel {:file-id (:id file1)} - {:order-by [:created-at]})] + (let [[item1 item2 :as rows] (th/db-query :file-library-rel + {:file-id (:id file1)} + {:order-by [:created-at]})] (t/is (= 2 (count rows))) (t/is (= (:file-id item1) (:id file1))) (t/is (= (:library-file-id item1) (:id file2))) @@ -555,15 +556,14 @@ (t/is (= (:library-file-id item2) (:id file3)))) ;; the file2 should not be linked to any file - (let [[rows] (db/query th/*pool* :file-library-rel {:file-id (:id file2)})] + (let [[rows] (th/db-query :file-library-rel {:file-id (:id file2)})] (t/is (= 0 (count rows)))) ;; the file3 should not be linked to any file - (let [[rows] (db/query th/*pool* :file-library-rel {:file-id (:id file3)})] + (let [[rows] (th/db-query :file-library-rel {:file-id (:id file3)})] (t/is (= 0 (count rows)))) ;; move project1 to other team - ;; TODO: correct team change of project (let [data {::th/type :move-project ::rpc/profile-id (:id profile) :project-id (:id project1) @@ -574,21 +574,25 @@ (t/is (nil? (:result out))) ;; project1 now should still have 2 files - (let [[item1 item2 :as rows] (db/query th/*pool* :file {:project-id (:id project1)} - {:order-by [:created-at]})] + (let [[item1 item2 :as rows] (th/db-query :file + {:project-id (:id project1)} + {:order-by [:created-at]})] ;; (clojure.pprint/pprint rows) (t/is (= 2 (count rows))) (t/is (= (:id item1) (:id file1))) (t/is (= (:id item2) (:id file2)))) ;; project2 now should still have 1 file - (let [[item :as rows] (db/query th/*pool* :file {:project-id (:id project2)})] + (let [[item :as rows] (th/db-query :file {:project-id (:id project2)})] + ;; (pp/pprint rows) (t/is (= 1 (count rows))) (t/is (= (:id item) (:id file3)))) ;; the file1 should be linked to file2 but not file3 - (let [[item1 :as rows] (db/query th/*pool* :file-library-rel {:file-id (:id file1)} - {:order-by [:created-at]})] + (let [[item1 :as rows] (th/db-query :file-library-rel + {:file-id (:id file1)} + {:order-by [:created-at]})] + (t/is (= 1 (count rows))) (t/is (= (:file-id item1) (:id file1))) (t/is (= (:library-file-id item1) (:id file2)))))))