mirror of
https://github.com/penpot/penpot.git
synced 2025-05-31 05:26:11 +02:00
♻️ Add admin facilities on the code base
- Fix bugs related to orphan teams on profile deletion - Separate session based profile-id param from api user provided
This commit is contained in:
parent
53d9b547c3
commit
b929564fa7
53 changed files with 872 additions and 468 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
(ns backend-tests.helpers
|
||||
(:require
|
||||
[app.auth]
|
||||
[app.common.data :as d]
|
||||
[app.common.flags :as flags]
|
||||
[app.common.pages :as cp]
|
||||
|
@ -17,6 +18,7 @@
|
|||
[app.main :as main]
|
||||
[app.media]
|
||||
[app.migrations]
|
||||
[app.rpc :as-alias rpc]
|
||||
[app.rpc.commands.auth :as cmd.auth]
|
||||
[app.rpc.commands.files :as files]
|
||||
[app.rpc.commands.files.create :as files.create]
|
||||
|
@ -101,8 +103,9 @@
|
|||
*pool* (:app.db/pool system)]
|
||||
(with-redefs [app.config/flags (flags/parse flags/default default-flags (:flags config))
|
||||
app.config/config config
|
||||
app.rpc.commands.auth/derive-password identity
|
||||
app.rpc.commands.auth/verify-password (fn [a b] {:valid (= a b)})]
|
||||
app.loggers.audit/submit! (constantly nil)
|
||||
app.auth/derive-password identity
|
||||
app.auth/verify-password (fn [a b] {:valid (= a b)})]
|
||||
(next)))
|
||||
(finally
|
||||
(ig/halt! system)))))
|
||||
|
@ -322,14 +325,21 @@
|
|||
(try-on! (method-fn (dissoc data ::type)))))
|
||||
|
||||
(defn mutation!
|
||||
[{:keys [::type] :as data}]
|
||||
[{:keys [::type profile-id] :as data}]
|
||||
(let [method-fn (get-in *system* [:app.rpc/methods :mutations type])]
|
||||
(try-on! (method-fn (dissoc data ::type)))))
|
||||
(try-on! (method-fn (-> data
|
||||
(dissoc ::type)
|
||||
(assoc ::rpc/profile-id profile-id)
|
||||
(d/without-nils))))))
|
||||
|
||||
(defn query!
|
||||
[{:keys [::type] :as data}]
|
||||
[{:keys [::type profile-id] :as data}]
|
||||
(let [method-fn (get-in *system* [:app.rpc/methods :queries type])]
|
||||
(try-on! (method-fn (dissoc data ::type)))))
|
||||
(try-on! (method-fn (-> data
|
||||
(dissoc ::type)
|
||||
(assoc ::rpc/profile-id profile-id)
|
||||
(d/without-nils))))))
|
||||
|
||||
|
||||
(defn run-task!
|
||||
([name]
|
||||
|
|
|
@ -65,8 +65,7 @@
|
|||
|
||||
;; Refresh webhook
|
||||
(let [whk' (th/db-get :webhook {:id (:id whk)})]
|
||||
(t/is (nil? (:error-code whk')))
|
||||
(prn whk'))
|
||||
(t/is (nil? (:error-code whk'))))
|
||||
|
||||
)))
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
[app.common.uuid :as uuid]
|
||||
[app.db :as db]
|
||||
[app.util.time :as dt]
|
||||
[app.rpc :as-alias rpc]
|
||||
[backend-tests.helpers :as th]
|
||||
[clojure.test :as t]))
|
||||
|
||||
|
@ -37,7 +38,7 @@
|
|||
|
||||
params {::th/type :push-audit-events
|
||||
:app.http/request http-request
|
||||
:profile-id (:id prof)
|
||||
::rpc/profile-id (:id prof)
|
||||
:events [{:name "navigate"
|
||||
:props {:project-id proj-id
|
||||
:team-id team-id
|
||||
|
@ -67,7 +68,7 @@
|
|||
|
||||
params {::th/type :push-audit-events
|
||||
:app.http/request http-request
|
||||
:profile-id (:id prof)
|
||||
::rpc/profile-id (:id prof)
|
||||
:events [{:name "navigate"
|
||||
:props {:project-id proj-id
|
||||
:team-id team-id
|
||||
|
|
|
@ -6,12 +6,13 @@
|
|||
|
||||
(ns backend-tests.rpc-cond-middleware-test
|
||||
(:require
|
||||
[backend-tests.storage-test :refer [configure-storage-backend]]
|
||||
[backend-tests.helpers :as th]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.db :as db]
|
||||
[app.http :as http]
|
||||
[app.rpc :as-alias rpc]
|
||||
[app.rpc.cond :as cond]
|
||||
[backend-tests.helpers :as th]
|
||||
[backend-tests.storage-test :refer [configure-storage-backend]]
|
||||
[clojure.test :as t]
|
||||
[datoteka.core :as fs]))
|
||||
|
||||
|
@ -24,7 +25,9 @@
|
|||
:profile-id (:id profile)})
|
||||
file1 (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id (:id project)})
|
||||
params {::th/type :get-file :id (:id file1) :profile-id (:id profile)}]
|
||||
params {::th/type :get-file
|
||||
:id (:id file1)
|
||||
::rpc/profile-id (:id profile)}]
|
||||
|
||||
(binding [cond/*enabled* true]
|
||||
(let [{:keys [error result]} (th/command! params)]
|
||||
|
|
|
@ -583,6 +583,7 @@
|
|||
:object-id (str page-id frame1-id)
|
||||
:data nil}
|
||||
{:keys [error result] :as out} (th/mutation! data)]
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? error))
|
||||
(t/is (nil? result)))
|
||||
|
||||
|
|
|
@ -6,12 +6,13 @@
|
|||
|
||||
(ns backend-tests.rpc-management-test
|
||||
(:require
|
||||
[backend-tests.storage-test :refer [configure-storage-backend]]
|
||||
[backend-tests.helpers :as th]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.db :as db]
|
||||
[app.http :as http]
|
||||
[app.rpc :as-alias rpc]
|
||||
[app.storage :as sto]
|
||||
[backend-tests.helpers :as th]
|
||||
[backend-tests.storage-test :refer [configure-storage-backend]]
|
||||
[buddy.core.bytes :as b]
|
||||
[clojure.test :as t]
|
||||
[datoteka.core :as fs]))
|
||||
|
@ -50,7 +51,7 @@
|
|||
:object (select-keys mobj [:id :width :height :mtype :name])}]})
|
||||
|
||||
(let [data {::th/type :duplicate-file
|
||||
:profile-id (:id profile)
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id (:id file1)
|
||||
:name "file 1 (copy)"}
|
||||
out (th/command! data)]
|
||||
|
@ -122,7 +123,7 @@
|
|||
@(sto/del-object! storage sobject)
|
||||
|
||||
(let [data {::th/type :duplicate-file
|
||||
:profile-id (:id profile)
|
||||
::rpc/profile-id (:id profile)
|
||||
:file-id (:id file1)
|
||||
:name "file 1 (copy)"}
|
||||
out (th/command! data)]
|
||||
|
@ -184,7 +185,7 @@
|
|||
|
||||
|
||||
(let [data {::th/type :duplicate-project
|
||||
:profile-id (:id profile)
|
||||
::rpc/profile-id (:id profile)
|
||||
:project-id (:id project)
|
||||
:name "project 1 (copy)"}
|
||||
out (th/command! data)]
|
||||
|
@ -250,7 +251,7 @@
|
|||
(th/mark-file-deleted* {:id (:id file1)})
|
||||
|
||||
(let [data {::th/type :duplicate-project
|
||||
:profile-id (:id profile)
|
||||
::rpc/profile-id (:id profile)
|
||||
:project-id (:id project)
|
||||
:name "project 1 (copy)"}
|
||||
out (th/command! data)]
|
||||
|
@ -313,7 +314,7 @@
|
|||
|
||||
;; Try to move to same project
|
||||
(let [data {::th/type :move-files
|
||||
:profile-id (:id profile)
|
||||
::rpc/profile-id (:id profile)
|
||||
:project-id (:id project1)
|
||||
:ids #{(:id file1)}}
|
||||
|
||||
|
@ -333,7 +334,7 @@
|
|||
|
||||
;; move a file1 to project2 (in the same team)
|
||||
(let [data {::th/type :move-files
|
||||
:profile-id (:id profile)
|
||||
::rpc/profile-id (:id profile)
|
||||
:project-id (:id project2)
|
||||
:ids #{(:id file1)}}
|
||||
|
||||
|
@ -416,7 +417,7 @@
|
|||
|
||||
;; move to other project in other team
|
||||
(let [data {::th/type :move-files
|
||||
:profile-id (:id profile)
|
||||
::rpc/profile-id (:id profile)
|
||||
:project-id (:id project2)
|
||||
:ids #{(:id file1)}}
|
||||
out (th/command! data)]
|
||||
|
@ -489,7 +490,7 @@
|
|||
|
||||
;; move the library to other project
|
||||
(let [data {::th/type :move-files
|
||||
:profile-id (:id profile)
|
||||
::rpc/profile-id (:id profile)
|
||||
:project-id (:id project2)
|
||||
:ids #{(:id file2)}}
|
||||
out (th/command! data)]
|
||||
|
@ -575,7 +576,7 @@
|
|||
;; move project1 to other team
|
||||
;; TODO: correct team change of project
|
||||
(let [data {::th/type :move-project
|
||||
:profile-id (:id profile)
|
||||
::rpc/profile-id (:id profile)
|
||||
:project-id (:id project1)
|
||||
:team-id (:id team)}
|
||||
out (th/command! data)]
|
||||
|
@ -608,7 +609,7 @@
|
|||
(t/deftest clone-template
|
||||
(let [prof (th/create-profile* 1 {:is-active true})
|
||||
data {::th/type :clone-template
|
||||
:profile-id (:id prof)
|
||||
::rpc/profile-id (:id prof)
|
||||
:project-id (:default-project-id prof)
|
||||
:template-id "test"}
|
||||
|
||||
|
@ -624,7 +625,7 @@
|
|||
(t/deftest retrieve-list-of-buitin-templates
|
||||
(let [prof (th/create-profile* 1 {:is-active true})
|
||||
data {::th/type :retrieve-list-of-builtin-templates
|
||||
:profile-id (:id prof)}
|
||||
::rpc/profile-id (:id prof)}
|
||||
out (th/command! data)]
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? (:error out)))
|
||||
|
|
|
@ -146,7 +146,12 @@
|
|||
|
||||
;; execute permanent deletion task
|
||||
(let [result (th/run-task! :objects-gc {:min-age (dt/duration "-1m")})]
|
||||
(t/is (= 1 (:processed result))))
|
||||
(t/is (= 2 (:processed result))))
|
||||
|
||||
(let [row (th/db-get :team
|
||||
{:id (:default-team-id prof)}
|
||||
{:check-deleted? false})]
|
||||
(t/is (dt/instant? (:deleted-at row))))
|
||||
|
||||
;; query profile after delete
|
||||
(let [params {::th/type :profile
|
||||
|
|
|
@ -6,13 +6,14 @@
|
|||
|
||||
(ns backend-tests.rpc-team-test
|
||||
(:require
|
||||
[backend-tests.helpers :as th]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.db :as db]
|
||||
[app.http :as http]
|
||||
[app.rpc :as-alias rpc]
|
||||
[app.storage :as sto]
|
||||
[app.tokens :as tokens]
|
||||
[app.util.time :as dt]
|
||||
[backend-tests.helpers :as th]
|
||||
[clojure.test :as t]
|
||||
[datoteka.core :as fs]
|
||||
[mockery.core :refer [with-mocks]]))
|
||||
|
@ -65,7 +66,7 @@
|
|||
|
||||
;; get invitation token
|
||||
(let [params {::th/type :get-team-invitation-token
|
||||
:profile-id (:id profile1)
|
||||
::rpc/profile-id (:id profile1)
|
||||
:team-id (:id team)
|
||||
:email "foo@bar.com"}
|
||||
out (th/command! params)]
|
||||
|
@ -214,7 +215,7 @@
|
|||
:role "editor"
|
||||
:valid-until (dt/in-future "48h")})
|
||||
|
||||
(let [data {::th/type :verify-token :token token :profile-id (:id profile2)}
|
||||
(let [data {::th/type :verify-token :token token ::rpc/profile-id (:id profile2)}
|
||||
out (th/command! data)]
|
||||
;; (th/print-result! out)
|
||||
(t/is (th/success? out))
|
||||
|
@ -235,7 +236,7 @@
|
|||
:role "editor"
|
||||
:valid-until (dt/in-future "48h")})
|
||||
|
||||
(let [data {::th/type :verify-token :token token :profile-id (:id profile1)}
|
||||
(let [data {::th/type :verify-token :token token ::rpc/profile-id (:id profile1)}
|
||||
out (th/command! data)]
|
||||
;; (th/print-result! out)
|
||||
(t/is (not (th/success? out)))
|
||||
|
|
|
@ -100,6 +100,7 @@
|
|||
out (th/query! data)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? (:error out)))
|
||||
(let [result (:result out)]
|
||||
(t/is (contains? result :file))
|
||||
(t/is (contains? result :project)))))
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
[app.db :as db]
|
||||
[app.http :as http]
|
||||
[app.storage :as sto]
|
||||
[app.rpc :as-alias rpc]
|
||||
[backend-tests.helpers :as th]
|
||||
[clojure.test :as t]
|
||||
[mockery.core :refer [with-mocks]]))
|
||||
|
@ -28,7 +29,7 @@
|
|||
|
||||
(t/testing "create webhook"
|
||||
(let [params {::th/type :create-webhook
|
||||
:profile-id (:id prof)
|
||||
::rpc/profile-id (:id prof)
|
||||
:team-id team-id
|
||||
:uri "http://example.com"
|
||||
:mtype "application/json"}
|
||||
|
@ -54,7 +55,7 @@
|
|||
|
||||
(t/testing "update webhook 1 (success)"
|
||||
(let [params {::th/type :update-webhook
|
||||
:profile-id (:id prof)
|
||||
::rpc/profile-id (:id prof)
|
||||
:id (:id @whook)
|
||||
:uri (:uri @whook)
|
||||
:mtype "application/transit+json"
|
||||
|
@ -82,7 +83,7 @@
|
|||
|
||||
(t/testing "update webhook 2 (change uri)"
|
||||
(let [params {::th/type :update-webhook
|
||||
:profile-id (:id prof)
|
||||
::rpc/profile-id (:id prof)
|
||||
:id (:id @whook)
|
||||
:uri (str (:uri @whook) "/test")
|
||||
:mtype "application/transit+json"
|
||||
|
@ -97,7 +98,7 @@
|
|||
|
||||
(t/testing "update webhook 3 (not authorized)"
|
||||
(let [params {::th/type :update-webhook
|
||||
:profile-id uuid/zero
|
||||
::rpc/profile-id uuid/zero
|
||||
:id (:id @whook)
|
||||
:uri (str (:uri @whook) "/test")
|
||||
:mtype "application/transit+json"
|
||||
|
@ -115,7 +116,7 @@
|
|||
|
||||
(t/testing "delete webhook (success)"
|
||||
(let [params {::th/type :delete-webhook
|
||||
:profile-id (:id prof)
|
||||
::rpc/profile-id (:id prof)
|
||||
:id (:id @whook)}
|
||||
out (th/command! params)]
|
||||
|
||||
|
@ -128,7 +129,7 @@
|
|||
|
||||
(t/testing "delete webhook (unauthorozed)"
|
||||
(let [params {::th/type :delete-webhook
|
||||
:profile-id uuid/zero
|
||||
::rpc/profile-id uuid/zero
|
||||
:id (:id @whook)}
|
||||
out (th/command! params)]
|
||||
|
||||
|
@ -149,7 +150,7 @@
|
|||
(let [prof (th/create-profile* 1 {:is-active true})
|
||||
team-id (:default-team-id prof)
|
||||
params {::th/type :create-webhook
|
||||
:profile-id (:id prof)
|
||||
::rpc/profile-id (:id prof)
|
||||
:team-id team-id
|
||||
:uri "http://example.com"
|
||||
:mtype "application/json"}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue