🐛 Fix incorrect feature checking on move project

This commit is contained in:
Andrey Antukh 2023-12-13 17:45:55 +01:00
parent ba01f314dd
commit bdb1742d59
2 changed files with 70 additions and 58 deletions

View file

@ -391,7 +391,15 @@
;; Check the teams compatibility ;; Check the teams compatibility
(let [orig-team (teams/get-team conn :profile-id profile-id :team-id (:team-id project)) (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)] 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 ;; move project to the destination team
(db/update! conn :project (db/update! conn :project

View file

@ -69,12 +69,12 @@
(t/is (not= (:id file1) (:id result))) (t/is (not= (:id file1) (:id result)))
;; Check that the new file has a correct file library relation ;; 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 (= 1 (count rows)))
(t/is (= (:id file2) (:library-file-id item)))) (t/is (= (:id file2) (:library-file-id item))))
;; Check that the new file has a correct file media objects ;; 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))) (t/is (= 1 (count rows)))
;; Check that both items have different ids ;; Check that both items have different ids
@ -91,7 +91,7 @@
(t/is (not (contains? (get-in result [:data :media]) (:id mobj))))) (t/is (not (contains? (get-in result [:data :media]) (:id mobj)))))
;; Check the total number of files ;; 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/is (= 3 (count rows))))))))
(t/deftest duplicate-file-with-deleted-relations (t/deftest duplicate-file-with-deleted-relations
@ -139,15 +139,15 @@
(t/is (not= (:id file1) (:id result))) (t/is (not= (:id file1) (:id result)))
;; Check that there are no relation to a deleted library ;; 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)))) (t/is (= 0 (count rows))))
;; Check that the new file has no media objects ;; 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)))) (t/is (= 0 (count rows))))
;; Check the total number of files ;; 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/is (= 3 (count rows))))))))
(t/deftest duplicate-project (t/deftest duplicate-project
@ -196,16 +196,16 @@
(t/is (not= (:id project) (:id result))) (t/is (not= (:id project) (:id result)))
;; Check the total number of projects (previously is 2, now is 3) ;; 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)))) (t/is (= 3 (count rows))))
;; Check that the new project has the same files ;; Check that the new project has the same files
(let [p1-files (db/query th/*pool* :file (let [p1-files (th/db-query :file
{:project-id (:id project)} {:project-id (:id project)}
{:order-by [:name]}) {:order-by [:name]})
p2-files (db/query th/*pool* :file p2-files (th/db-query :file
{:project-id (:id result)} {:project-id (:id result)}
{:order-by [:name]})] {:order-by [:name]})]
(t/is (= (count p1-files) (t/is (= (count p1-files)
(count p2-files))) (count p2-files)))
@ -260,16 +260,16 @@
(t/is (not= (:id project) (:id result))) (t/is (not= (:id project) (:id result)))
;; Check the total number of projects (previously is 2, now is 3) ;; 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)))) (t/is (= 3 (count rows))))
;; Check that the new project has only the second file ;; Check that the new project has only the second file
(let [p1-files (db/query th/*pool* :file (let [p1-files (th/db-query :file
{:project-id (:id project)} {:project-id (:id project)}
{:order-by [:name]}) {:order-by [:name]})
p2-files (db/query th/*pool* :file p2-files (th/db-query :file
{:project-id (:id result)} {:project-id (:id result)}
{:order-by [:name]})] {:order-by [:name]})]
(t/is (= (count (rest p1-files)) (t/is (= (count (rest p1-files))
(count p2-files))) (count p2-files)))
@ -318,11 +318,11 @@
(t/is (th/ex-of-code? error :cant-move-to-same-project))) (t/is (th/ex-of-code? error :cant-move-to-same-project)))
;; initially project1 should have 2 files ;; 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)))) (t/is (= 2 (count rows))))
;; initially project2 should be empty ;; 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)))) (t/is (= 0 (count rows))))
;; move a file1 to project2 (in the same team) ;; move a file1 to project2 (in the same team)
@ -337,21 +337,21 @@
(t/is (nil? (:result out))) (t/is (nil? (:result out)))
;; project1 now should contain 1 file ;; 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)))) (t/is (= 1 (count rows))))
;; project2 now should contain 1 file ;; 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)))) (t/is (= 1 (count rows))))
;; file1 should be still linked to file2 ;; 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 (= 1 (count rows)))
(t/is (= (:file-id item) (:id file1))) (t/is (= (:file-id item) (:id file1)))
(t/is (= (:library-file-id item) (:id file2)))) (t/is (= (:library-file-id item) (:id file2))))
;; should be no libraries on 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))))))) (t/is (= 0 (count rows)))))))
@ -384,27 +384,27 @@
;; --- initial data checks ;; --- initial data checks
;; the project1 should have 3 files ;; 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)))) (t/is (= 3 (count rows))))
;; should be no files on project2 ;; 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)))) (t/is (= 0 (count rows))))
;; the file1 should be linked to file2 ;; 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 (= 1 (count rows)))
(t/is (= (:file-id item) (:id file1))) (t/is (= (:file-id item) (:id file1)))
(t/is (= (:library-file-id item) (:id file2)))) (t/is (= (:library-file-id item) (:id file2))))
;; the file2 should be linked to file3 ;; 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 (= 1 (count rows)))
(t/is (= (:file-id item) (:id file2))) (t/is (= (:file-id item) (:id file2)))
(t/is (= (:library-file-id item) (:id file3)))) (t/is (= (:library-file-id item) (:id file3))))
;; should be no libraries on 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)))) (t/is (= 0 (count rows))))
;; move to other project in other team ;; move to other project in other team
@ -418,23 +418,23 @@
(t/is (nil? (:result out))) (t/is (nil? (:result out)))
;; project1 now should have 2 file ;; project1 now should have 2 file
(let [[item1 item2 :as rows] (db/query th/*pool* :file {:project-id (:id project1)} (let [[item1 item2 :as rows] (th/db-query :file {:project-id (:id project1)}
{:order-by [:created-at]})] {:order-by [:created-at]})]
;; (clojure.pprint/pprint rows) ;; (clojure.pprint/pprint rows)
(t/is (= 2 (count rows))) (t/is (= 2 (count rows)))
(t/is (= (:id item1) (:id file2)))) (t/is (= (:id item1) (:id file2))))
;; project2 now should have 1 file ;; 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 (= 1 (count rows)))
(t/is (= (:id item) (:id file1)))) (t/is (= (:id item) (:id file1))))
;; the moved file1 should not have any link to libraries ;; 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)))) (t/is (zero? (count rows))))
;; the file2 should still be linked to file3 ;; 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 (= 1 (count rows)))
(t/is (= (:file-id item) (:id file2))) (t/is (= (:file-id item) (:id file2)))
(t/is (= (:library-file-id item) (:id file3))))))) (t/is (= (:library-file-id item) (:id file3)))))))
@ -462,21 +462,21 @@
;; --- initial data checks ;; --- initial data checks
;; the project1 should have 2 files ;; 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)))) (t/is (= 2 (count rows))))
;; should be no files on project2 ;; 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)))) (t/is (= 0 (count rows))))
;; the file1 should be linked to file2 ;; 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 (= 1 (count rows)))
(t/is (= (:file-id item) (:id file1))) (t/is (= (:file-id item) (:id file1)))
(t/is (= (:library-file-id item) (:id file2)))) (t/is (= (:library-file-id item) (:id file2))))
;; should be no libraries on 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)))) (t/is (= 0 (count rows))))
;; move the library to other project ;; move the library to other project
@ -490,22 +490,22 @@
(t/is (nil? (:result out))) (t/is (nil? (:result out)))
;; project1 now should have 1 file ;; project1 now should have 1 file
(let [[item :as rows] (db/query th/*pool* :file {:project-id (:id project1)} (let [[item :as rows] (th/db-query :file {:project-id (:id project1)}
{:order-by [:created-at]})] {:order-by [:created-at]})]
(t/is (= 1 (count rows))) (t/is (= 1 (count rows)))
(t/is (= (:id item) (:id file1)))) (t/is (= (:id item) (:id file1))))
;; project2 now should have 1 file ;; 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 (= 1 (count rows)))
(t/is (= (:id item) (:id file2)))) (t/is (= (:id item) (:id file2))))
;; the file1 should not have any link to libraries ;; 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)))) (t/is (zero? (count rows))))
;; the file2 should not have any link to libraries ;; 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/is (zero? (count rows)))))))
(t/deftest move-project (t/deftest move-project
@ -538,16 +538,17 @@
;; --- initial data checks ;; --- initial data checks
;; the project1 should have 2 files ;; 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)))) (t/is (= 2 (count rows))))
;; the project2 should have 1 file ;; 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)))) (t/is (= 1 (count rows))))
;; the file1 should be linked to file2 and file3 ;; 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)} (let [[item1 item2 :as rows] (th/db-query :file-library-rel
{:order-by [:created-at]})] {:file-id (:id file1)}
{:order-by [:created-at]})]
(t/is (= 2 (count rows))) (t/is (= 2 (count rows)))
(t/is (= (:file-id item1) (:id file1))) (t/is (= (:file-id item1) (:id file1)))
(t/is (= (:library-file-id item1) (:id file2))) (t/is (= (:library-file-id item1) (:id file2)))
@ -555,15 +556,14 @@
(t/is (= (:library-file-id item2) (:id file3)))) (t/is (= (:library-file-id item2) (:id file3))))
;; the file2 should not be linked to any file ;; 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)))) (t/is (= 0 (count rows))))
;; the file3 should not be linked to any file ;; 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)))) (t/is (= 0 (count rows))))
;; move project1 to other team ;; move project1 to other team
;; TODO: correct team change of project
(let [data {::th/type :move-project (let [data {::th/type :move-project
::rpc/profile-id (:id profile) ::rpc/profile-id (:id profile)
:project-id (:id project1) :project-id (:id project1)
@ -574,21 +574,25 @@
(t/is (nil? (:result out))) (t/is (nil? (:result out)))
;; project1 now should still have 2 files ;; project1 now should still have 2 files
(let [[item1 item2 :as rows] (db/query th/*pool* :file {:project-id (:id project1)} (let [[item1 item2 :as rows] (th/db-query :file
{:order-by [:created-at]})] {:project-id (:id project1)}
{:order-by [:created-at]})]
;; (clojure.pprint/pprint rows) ;; (clojure.pprint/pprint rows)
(t/is (= 2 (count rows))) (t/is (= 2 (count rows)))
(t/is (= (:id item1) (:id file1))) (t/is (= (:id item1) (:id file1)))
(t/is (= (:id item2) (:id file2)))) (t/is (= (:id item2) (:id file2))))
;; project2 now should still have 1 file ;; 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 (= 1 (count rows)))
(t/is (= (:id item) (:id file3)))) (t/is (= (:id item) (:id file3))))
;; the file1 should be linked to file2 but not 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)} (let [[item1 :as rows] (th/db-query :file-library-rel
{:order-by [:created-at]})] {:file-id (:id file1)}
{:order-by [:created-at]})]
(t/is (= 1 (count rows))) (t/is (= 1 (count rows)))
(t/is (= (:file-id item1) (:id file1))) (t/is (= (:file-id item1) (:id file1)))
(t/is (= (:library-file-id item1) (:id file2))))))) (t/is (= (:library-file-id item1) (:id file2)))))))