diff --git a/backend/src/app/rpc.clj b/backend/src/app/rpc.clj index 1243f9364..15f5b8b40 100644 --- a/backend/src/app/rpc.clj +++ b/backend/src/app/rpc.clj @@ -332,6 +332,7 @@ 'app.rpc.commands.demo 'app.rpc.commands.files 'app.rpc.commands.files-create + 'app.rpc.commands.files-share 'app.rpc.commands.files-temp 'app.rpc.commands.files-update 'app.rpc.commands.ldap diff --git a/backend/src/app/rpc/commands/files.clj b/backend/src/app/rpc/commands/files.clj index 054e15d89..a0eee2288 100644 --- a/backend/src/app/rpc/commands/files.clj +++ b/backend/src/app/rpc/commands/files.clj @@ -28,7 +28,6 @@ [app.rpc.doc :as-alias doc] [app.rpc.helpers :as rph] [app.rpc.permissions :as perms] - [app.rpc.queries.share-link :refer [retrieve-share-link]] [app.util.blob :as blob] [app.util.pointer-map :as pmap] [app.util.services :as sv] @@ -128,7 +127,9 @@ ([conn profile-id file-id share-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 ;; will allow us specify which parts of the app is available, we diff --git a/backend/src/app/rpc/commands/files_share.clj b/backend/src/app/rpc/commands/files_share.clj new file mode 100644 index 000000000..f517fbb1f --- /dev/null +++ b/backend/src/app/rpc/commands/files_share.clj @@ -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))) diff --git a/backend/src/app/rpc/commands/viewer.clj b/backend/src/app/rpc/commands/viewer.clj index e9c1b0086..136bc309b 100644 --- a/backend/src/app/rpc/commands/viewer.clj +++ b/backend/src/app/rpc/commands/viewer.clj @@ -13,11 +13,10 @@ [app.rpc.commands.files :as files] [app.rpc.cond :as-alias cond] [app.rpc.doc :as-alias doc] - [app.rpc.queries.share-link :as slnk] [app.util.services :as sv] [clojure.spec.alpha :as s])) -;; --- Query: View Only Bundle +;; --- QUERY: View Only Bundle (defn- get-project [conn id] @@ -31,7 +30,8 @@ users (comments/get-file-comments-users conn file-id profile-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 {:team-id (:team-id project) diff --git a/backend/src/app/rpc/mutations/share_link.clj b/backend/src/app/rpc/mutations/share_link.clj index 9e8ab45d6..365aa77bd 100644 --- a/backend/src/app/rpc/mutations/share_link.clj +++ b/backend/src/app/rpc/mutations/share_link.clj @@ -11,6 +11,7 @@ [app.common.uuid :as uuid] [app.db :as db] [app.rpc.commands.files :as files] + [app.rpc.doc :as-alias doc] [app.util.services :as sv] [clojure.spec.alpha :as s])) @@ -35,8 +36,9 @@ Share links are resources that allows external users access to specific pages of a file with specific permissions (who-comment and who-inspect)." - - [{:keys [pool] :as cfg} {:keys [profile-id file-id] :as params}] + {::doc/added "1.5" + ::doc/deprecated "1.18"} + [{:keys [::db/pool] :as cfg} {:keys [profile-id file-id] :as params}] (db/with-atomic [conn pool] (files/check-edition-permissions! conn profile-id file-id) (create-share-link conn params))) @@ -51,18 +53,17 @@ :who-inspect who-inspect :pages pages :owner-id profile-id})] - (-> slink - (update :pages db/decode-pgarray #{})))) + (update slink :pages db/decode-pgarray #{}))) ;; --- Mutation: Delete Share Link -(declare delete-share-link) - (s/def ::delete-share-link (s/keys :req-un [::profile-id ::id])) (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] (let [slink (db/get-by-id conn :share-link id)] (files/check-edition-permissions! conn profile-id (:file-id slink)) diff --git a/backend/src/app/rpc/queries/share_link.clj b/backend/src/app/rpc/queries/share_link.clj deleted file mode 100644 index 8272e991f..000000000 --- a/backend/src/app/rpc/queries/share_link.clj +++ /dev/null @@ -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))) - diff --git a/frontend/src/app/main/data/common.cljs b/frontend/src/app/main/data/common.cljs index e5072d13c..2b10703a4 100644 --- a/frontend/src/app/main/data/common.cljs +++ b/frontend/src/app/main/data/common.cljs @@ -27,7 +27,7 @@ (ptk/reify ::create-share-link ptk/WatchEvent (watch [_ _ _] - (->> (rp/mutation! :create-share-link params) + (->> (rp/cmd! :create-share-link params) (rx/map share-link-created))))) (defn delete-share-link @@ -41,6 +41,6 @@ ptk/WatchEvent (watch [_ _ _] - (->> (rp/mutation! :delete-share-link {:id id}) + (->> (rp/cmd! :delete-share-link {:id id}) (rx/ignore)))))