mirror of
https://github.com/penpot/penpot.git
synced 2025-05-25 22:26:11 +02:00
✨ Move share link mutations to commands
This commit is contained in:
parent
4258a840ac
commit
1e1f551383
7 changed files with 88 additions and 36 deletions
|
@ -332,6 +332,7 @@
|
||||||
'app.rpc.commands.demo
|
'app.rpc.commands.demo
|
||||||
'app.rpc.commands.files
|
'app.rpc.commands.files
|
||||||
'app.rpc.commands.files-create
|
'app.rpc.commands.files-create
|
||||||
|
'app.rpc.commands.files-share
|
||||||
'app.rpc.commands.files-temp
|
'app.rpc.commands.files-temp
|
||||||
'app.rpc.commands.files-update
|
'app.rpc.commands.files-update
|
||||||
'app.rpc.commands.ldap
|
'app.rpc.commands.ldap
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
[app.rpc.doc :as-alias doc]
|
[app.rpc.doc :as-alias doc]
|
||||||
[app.rpc.helpers :as rph]
|
[app.rpc.helpers :as rph]
|
||||||
[app.rpc.permissions :as perms]
|
[app.rpc.permissions :as perms]
|
||||||
[app.rpc.queries.share-link :refer [retrieve-share-link]]
|
|
||||||
[app.util.blob :as blob]
|
[app.util.blob :as blob]
|
||||||
[app.util.pointer-map :as pmap]
|
[app.util.pointer-map :as pmap]
|
||||||
[app.util.services :as sv]
|
[app.util.services :as sv]
|
||||||
|
@ -128,7 +127,9 @@
|
||||||
|
|
||||||
([conn profile-id file-id share-id]
|
([conn profile-id file-id share-id]
|
||||||
(let [perms (get-permissions conn profile-id file-id)
|
(let [perms (get-permissions conn profile-id file-id)
|
||||||
ldata (retrieve-share-link conn file-id share-id)]
|
ldata (some-> (db/get* conn :share-link {:id share-id :file-id file-id})
|
||||||
|
(dissoc :flags)
|
||||||
|
(update :pages db/decode-pgarray #{}))]
|
||||||
|
|
||||||
;; NOTE: in a future when share-link becomes more powerful and
|
;; NOTE: in a future when share-link becomes more powerful and
|
||||||
;; will allow us specify which parts of the app is available, we
|
;; will allow us specify which parts of the app is available, we
|
||||||
|
|
71
backend/src/app/rpc/commands/files_share.clj
Normal file
71
backend/src/app/rpc/commands/files_share.clj
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
|
(ns app.rpc.commands.files-share
|
||||||
|
"Share link related rpc mutation methods."
|
||||||
|
(:require
|
||||||
|
[app.common.spec :as us]
|
||||||
|
[app.common.uuid :as uuid]
|
||||||
|
[app.db :as db]
|
||||||
|
[app.rpc :as-alias rpc]
|
||||||
|
[app.rpc.commands.files :as files]
|
||||||
|
[app.rpc.doc :as-alias doc]
|
||||||
|
[app.util.services :as sv]
|
||||||
|
[clojure.spec.alpha :as s]))
|
||||||
|
|
||||||
|
;; --- Helpers & Specs
|
||||||
|
|
||||||
|
(s/def ::file-id ::us/uuid)
|
||||||
|
(s/def ::who-comment ::us/string)
|
||||||
|
(s/def ::who-inspect ::us/string)
|
||||||
|
(s/def ::pages (s/every ::us/uuid :kind set?))
|
||||||
|
|
||||||
|
;; --- MUTATION: Create Share Link
|
||||||
|
|
||||||
|
(declare create-share-link)
|
||||||
|
|
||||||
|
(s/def ::create-share-link
|
||||||
|
(s/keys :req [::rpc/profile-id]
|
||||||
|
:req-un [::file-id ::who-comment ::who-inspect ::pages]))
|
||||||
|
|
||||||
|
(sv/defmethod ::create-share-link
|
||||||
|
"Creates a share-link object.
|
||||||
|
|
||||||
|
Share links are resources that allows external users access to specific
|
||||||
|
pages of a file with specific permissions (who-comment and who-inspect)."
|
||||||
|
{::doc/added "1.18"}
|
||||||
|
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id file-id] :as params}]
|
||||||
|
(db/with-atomic [conn pool]
|
||||||
|
(files/check-edition-permissions! conn profile-id file-id)
|
||||||
|
(create-share-link conn (assoc params :profile-id profile-id))))
|
||||||
|
|
||||||
|
(defn create-share-link
|
||||||
|
[conn {:keys [profile-id file-id pages who-comment who-inspect]}]
|
||||||
|
(let [pages (db/create-array conn "uuid" pages)
|
||||||
|
slink (db/insert! conn :share-link
|
||||||
|
{:id (uuid/next)
|
||||||
|
:file-id file-id
|
||||||
|
:who-comment who-comment
|
||||||
|
:who-inspect who-inspect
|
||||||
|
:pages pages
|
||||||
|
:owner-id profile-id})]
|
||||||
|
|
||||||
|
(update slink :pages db/decode-pgarray #{})))
|
||||||
|
|
||||||
|
;; --- MUTATION: Delete Share Link
|
||||||
|
|
||||||
|
(s/def ::delete-share-link
|
||||||
|
(s/keys :req [::rpc/profile-id]
|
||||||
|
:req-un [::us/id]))
|
||||||
|
|
||||||
|
(sv/defmethod ::delete-share-link
|
||||||
|
{::doc/added "1.18"}
|
||||||
|
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id id] :as params}]
|
||||||
|
(db/with-atomic [conn pool]
|
||||||
|
(let [slink (db/get-by-id conn :share-link id)]
|
||||||
|
(files/check-edition-permissions! conn profile-id (:file-id slink))
|
||||||
|
(db/delete! conn :share-link {:id id})
|
||||||
|
nil)))
|
|
@ -13,11 +13,10 @@
|
||||||
[app.rpc.commands.files :as files]
|
[app.rpc.commands.files :as files]
|
||||||
[app.rpc.cond :as-alias cond]
|
[app.rpc.cond :as-alias cond]
|
||||||
[app.rpc.doc :as-alias doc]
|
[app.rpc.doc :as-alias doc]
|
||||||
[app.rpc.queries.share-link :as slnk]
|
|
||||||
[app.util.services :as sv]
|
[app.util.services :as sv]
|
||||||
[clojure.spec.alpha :as s]))
|
[clojure.spec.alpha :as s]))
|
||||||
|
|
||||||
;; --- Query: View Only Bundle
|
;; --- QUERY: View Only Bundle
|
||||||
|
|
||||||
(defn- get-project
|
(defn- get-project
|
||||||
[conn id]
|
[conn id]
|
||||||
|
@ -31,7 +30,8 @@
|
||||||
users (comments/get-file-comments-users conn file-id profile-id)
|
users (comments/get-file-comments-users conn file-id profile-id)
|
||||||
|
|
||||||
links (->> (db/query conn :share-link {:file-id file-id})
|
links (->> (db/query conn :share-link {:file-id file-id})
|
||||||
(mapv slnk/decode-share-link-row))
|
(mapv (fn [row]
|
||||||
|
(update row :pages db/decode-pgarray #{}))))
|
||||||
|
|
||||||
fonts (db/query conn :team-font-variant
|
fonts (db/query conn :team-font-variant
|
||||||
{:team-id (:team-id project)
|
{:team-id (:team-id project)
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.rpc.commands.files :as files]
|
[app.rpc.commands.files :as files]
|
||||||
|
[app.rpc.doc :as-alias doc]
|
||||||
[app.util.services :as sv]
|
[app.util.services :as sv]
|
||||||
[clojure.spec.alpha :as s]))
|
[clojure.spec.alpha :as s]))
|
||||||
|
|
||||||
|
@ -35,8 +36,9 @@
|
||||||
|
|
||||||
Share links are resources that allows external users access to specific
|
Share links are resources that allows external users access to specific
|
||||||
pages of a file with specific permissions (who-comment and who-inspect)."
|
pages of a file with specific permissions (who-comment and who-inspect)."
|
||||||
|
{::doc/added "1.5"
|
||||||
[{:keys [pool] :as cfg} {:keys [profile-id file-id] :as params}]
|
::doc/deprecated "1.18"}
|
||||||
|
[{:keys [::db/pool] :as cfg} {:keys [profile-id file-id] :as params}]
|
||||||
(db/with-atomic [conn pool]
|
(db/with-atomic [conn pool]
|
||||||
(files/check-edition-permissions! conn profile-id file-id)
|
(files/check-edition-permissions! conn profile-id file-id)
|
||||||
(create-share-link conn params)))
|
(create-share-link conn params)))
|
||||||
|
@ -51,18 +53,17 @@
|
||||||
:who-inspect who-inspect
|
:who-inspect who-inspect
|
||||||
:pages pages
|
:pages pages
|
||||||
:owner-id profile-id})]
|
:owner-id profile-id})]
|
||||||
(-> slink
|
(update slink :pages db/decode-pgarray #{})))
|
||||||
(update :pages db/decode-pgarray #{}))))
|
|
||||||
|
|
||||||
;; --- Mutation: Delete Share Link
|
;; --- Mutation: Delete Share Link
|
||||||
|
|
||||||
(declare delete-share-link)
|
|
||||||
|
|
||||||
(s/def ::delete-share-link
|
(s/def ::delete-share-link
|
||||||
(s/keys :req-un [::profile-id ::id]))
|
(s/keys :req-un [::profile-id ::id]))
|
||||||
|
|
||||||
(sv/defmethod ::delete-share-link
|
(sv/defmethod ::delete-share-link
|
||||||
[{:keys [pool] :as cfg} {:keys [profile-id id] :as params}]
|
{::doc/added "1.5"
|
||||||
|
::doc/deprecated "1.18"}
|
||||||
|
[{:keys [::db/pool] :as cfg} {:keys [profile-id id] :as params}]
|
||||||
(db/with-atomic [conn pool]
|
(db/with-atomic [conn pool]
|
||||||
(let [slink (db/get-by-id conn :share-link id)]
|
(let [slink (db/get-by-id conn :share-link id)]
|
||||||
(files/check-edition-permissions! conn profile-id (:file-id slink))
|
(files/check-edition-permissions! conn profile-id (:file-id slink))
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
;;
|
|
||||||
;; Copyright (c) KALEIDOS INC
|
|
||||||
|
|
||||||
(ns app.rpc.queries.share-link
|
|
||||||
(:require
|
|
||||||
[app.db :as db]))
|
|
||||||
|
|
||||||
(defn decode-share-link-row
|
|
||||||
[row]
|
|
||||||
(-> row
|
|
||||||
(dissoc :flags)
|
|
||||||
(update :pages db/decode-pgarray #{})))
|
|
||||||
|
|
||||||
(defn retrieve-share-link
|
|
||||||
[conn file-id share-id]
|
|
||||||
(some-> (db/get* conn :share-link
|
|
||||||
{:id share-id :file-id file-id})
|
|
||||||
(decode-share-link-row)))
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
(ptk/reify ::create-share-link
|
(ptk/reify ::create-share-link
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ _ _]
|
(watch [_ _ _]
|
||||||
(->> (rp/mutation! :create-share-link params)
|
(->> (rp/cmd! :create-share-link params)
|
||||||
(rx/map share-link-created)))))
|
(rx/map share-link-created)))))
|
||||||
|
|
||||||
(defn delete-share-link
|
(defn delete-share-link
|
||||||
|
@ -41,6 +41,6 @@
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ _ _]
|
(watch [_ _ _]
|
||||||
(->> (rp/mutation! :delete-share-link {:id id})
|
(->> (rp/cmd! :delete-share-link {:id id})
|
||||||
(rx/ignore)))))
|
(rx/ignore)))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue