mirror of
https://github.com/penpot/penpot.git
synced 2025-05-18 07:46:11 +02:00
✨ Add update plugin permission dialog
This commit is contained in:
parent
1e68d4ec87
commit
6a07e6ae01
7 changed files with 182 additions and 76 deletions
|
@ -6,14 +6,24 @@
|
||||||
|
|
||||||
(ns app.main.data.plugins
|
(ns app.main.data.plugins
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
|
[app.main.data.modal :as modal]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.plugins.register :as pr]
|
[app.plugins.register :as preg]
|
||||||
[app.util.globals :as ug]
|
[app.util.globals :as ug]
|
||||||
|
[app.util.http :as http]
|
||||||
[beicon.v2.core :as rx]
|
[beicon.v2.core :as rx]
|
||||||
[potok.v2.core :as ptk]))
|
[potok.v2.core :as ptk]))
|
||||||
|
|
||||||
|
(defn fetch-manifest
|
||||||
|
[plugin-url]
|
||||||
|
(->> (http/send! {:method :get
|
||||||
|
:uri plugin-url
|
||||||
|
:omit-default-headers true
|
||||||
|
:response-type :json})
|
||||||
|
(rx/map :body)
|
||||||
|
(rx/map #(preg/parse-manifest plugin-url %))))
|
||||||
|
|
||||||
(defn save-current-plugin
|
(defn save-current-plugin
|
||||||
[id]
|
[id]
|
||||||
(ptk/reify ::save-current-plugin
|
(ptk/reify ::save-current-plugin
|
||||||
|
@ -28,7 +38,7 @@
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(update-in state [:workspace-local :open-plugins] (fnil disj #{}) id))))
|
(update-in state [:workspace-local :open-plugins] (fnil disj #{}) id))))
|
||||||
|
|
||||||
(defn open-plugin!
|
(defn- load-plugin!
|
||||||
[{:keys [plugin-id name description host code icon permissions]}]
|
[{:keys [plugin-id name description host code icon permissions]}]
|
||||||
(try
|
(try
|
||||||
(st/emit! (save-current-plugin plugin-id))
|
(st/emit! (save-current-plugin plugin-id))
|
||||||
|
@ -48,6 +58,36 @@
|
||||||
(st/emit! (remove-current-plugin plugin-id))
|
(st/emit! (remove-current-plugin plugin-id))
|
||||||
(.error js/console "Error" e))))
|
(.error js/console "Error" e))))
|
||||||
|
|
||||||
|
(defn open-plugin!
|
||||||
|
[{:keys [url] :as manifest}]
|
||||||
|
(if url
|
||||||
|
;; If the saved manifest has a URL we fetch the manifest to check
|
||||||
|
;; for updates
|
||||||
|
(->> (fetch-manifest url)
|
||||||
|
(rx/subs!
|
||||||
|
(fn [new-manifest]
|
||||||
|
(let [new-manifest (merge new-manifest (select-keys manifest [:plugin-id]))]
|
||||||
|
(cond
|
||||||
|
(not= (:permissions new-manifest) (:permissions manifest))
|
||||||
|
(modal/show!
|
||||||
|
:plugin-permissions-update
|
||||||
|
{:plugin new-manifest
|
||||||
|
:on-accept
|
||||||
|
#(do
|
||||||
|
(preg/install-plugin! new-manifest)
|
||||||
|
(load-plugin! new-manifest))})
|
||||||
|
|
||||||
|
(not= new-manifest manifest)
|
||||||
|
(do (preg/install-plugin! new-manifest)
|
||||||
|
(load-plugin! manifest))
|
||||||
|
:else
|
||||||
|
(load-plugin! manifest))))
|
||||||
|
(fn []
|
||||||
|
;; Error fetching the manifest we'll load the plugin with the
|
||||||
|
;; old manifest
|
||||||
|
(load-plugin! manifest))))
|
||||||
|
(load-plugin! manifest)))
|
||||||
|
|
||||||
(defn close-plugin!
|
(defn close-plugin!
|
||||||
[{:keys [plugin-id]}]
|
[{:keys [plugin-id]}]
|
||||||
(try
|
(try
|
||||||
|
@ -62,7 +102,7 @@
|
||||||
(effect [_ state _]
|
(effect [_ state _]
|
||||||
(let [ids (dm/get-in state [:workspace-local :open-plugins])]
|
(let [ids (dm/get-in state [:workspace-local :open-plugins])]
|
||||||
(doseq [id ids]
|
(doseq [id ids]
|
||||||
(close-plugin! (pr/get-plugin id)))))))
|
(close-plugin! (preg/get-plugin id)))))))
|
||||||
|
|
||||||
(defn delay-open-plugin
|
(defn delay-open-plugin
|
||||||
[plugin]
|
[plugin]
|
||||||
|
@ -77,5 +117,5 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(when-let [pid (::open-plugin state)]
|
(when-let [pid (::open-plugin state)]
|
||||||
(open-plugin! (pr/get-plugin pid))
|
(open-plugin! (preg/get-plugin pid))
|
||||||
(rx/of #(dissoc % ::open-plugin))))))
|
(rx/of #(dissoc % ::open-plugin))))))
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
[app.main.ui.workspace.plugins]
|
[app.main.ui.workspace.plugins]
|
||||||
[app.plugins.register :as preg]
|
[app.plugins.register :as preg]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[app.util.http :as http]
|
|
||||||
[app.util.keyboard :as kbd]
|
[app.util.keyboard :as kbd]
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
[app.util.router :as rt]
|
[app.util.router :as rt]
|
||||||
|
@ -202,19 +201,14 @@
|
||||||
(mf/with-layout-effect
|
(mf/with-layout-effect
|
||||||
[plugin-url team-id project-id]
|
[plugin-url team-id project-id]
|
||||||
(when plugin-url
|
(when plugin-url
|
||||||
(->> (http/send! {:method :get
|
(->> (dp/fetch-manifest plugin-url)
|
||||||
:uri plugin-url
|
|
||||||
:omit-default-headers true
|
|
||||||
:response-type :json})
|
|
||||||
(rx/map :body)
|
|
||||||
(rx/subs!
|
(rx/subs!
|
||||||
(fn [body]
|
(fn [plugin]
|
||||||
(if-let [plugin (preg/parse-manifest plugin-url body)]
|
(if plugin
|
||||||
(do
|
(do
|
||||||
(st/emit! (ptk/event ::ev/event {::ev/name "install-plugin" :name (:name plugin) :url plugin-url}))
|
(st/emit! (ptk/event ::ev/event {::ev/name "install-plugin" :name (:name plugin) :url plugin-url}))
|
||||||
(open-permissions-dialog plugin))
|
(open-permissions-dialog plugin))
|
||||||
(st/emit! (notif/error "Cannot parser the plugin manifest"))))
|
(st/emit! (notif/error "Cannot parser the plugin manifest"))))
|
||||||
|
|
||||||
(fn [_]
|
(fn [_]
|
||||||
(st/emit! (notif/error "The plugin URL is incorrect")))))))))
|
(st/emit! (notif/error "The plugin URL is incorrect")))))))))
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
[app.plugins.register :as preg]
|
[app.plugins.register :as preg]
|
||||||
[app.util.avatars :as avatars]
|
[app.util.avatars :as avatars]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[app.util.http :as http]
|
|
||||||
[app.util.i18n :as i18n :refer [tr]]
|
[app.util.i18n :as i18n :refer [tr]]
|
||||||
[beicon.v2.core :as rx]
|
[beicon.v2.core :as rx]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
|
@ -96,15 +95,11 @@
|
||||||
(mf/deps plugins-state plugin-url)
|
(mf/deps plugins-state plugin-url)
|
||||||
(fn []
|
(fn []
|
||||||
(reset! fetching-manifest? true)
|
(reset! fetching-manifest? true)
|
||||||
(->> (http/send! {:method :get
|
(->> (dp/fetch-manifest plugin-url)
|
||||||
:uri plugin-url
|
|
||||||
:omit-default-headers true
|
|
||||||
:response-type :json})
|
|
||||||
(rx/map :body)
|
|
||||||
(rx/subs!
|
(rx/subs!
|
||||||
(fn [body]
|
(fn [plugin]
|
||||||
(reset! fetching-manifest? false)
|
(reset! fetching-manifest? false)
|
||||||
(if-let [plugin (preg/parse-manifest plugin-url body)]
|
(if plugin
|
||||||
(do
|
(do
|
||||||
(st/emit! (ptk/event ::ev/event {::ev/name "install-plugin" :name (:name plugin) :url plugin-url}))
|
(st/emit! (ptk/event ::ev/event {::ev/name "install-plugin" :name (:name plugin) :url plugin-url}))
|
||||||
(modal/show!
|
(modal/show!
|
||||||
|
@ -118,7 +113,8 @@
|
||||||
(reset! plugin-url* ""))
|
(reset! plugin-url* ""))
|
||||||
;; Cannot get the manifest
|
;; Cannot get the manifest
|
||||||
(reset! input-status* :error-manifest)))
|
(reset! input-status* :error-manifest)))
|
||||||
(fn [_]
|
(fn [err]
|
||||||
|
(.error js/console err)
|
||||||
(reset! fetching-manifest? false)
|
(reset! fetching-manifest? false)
|
||||||
(reset! input-status* :error-url))))))
|
(reset! input-status* :error-url))))))
|
||||||
|
|
||||||
|
@ -199,6 +195,62 @@
|
||||||
:on-open-plugin handle-open-plugin
|
:on-open-plugin handle-open-plugin
|
||||||
:on-remove-plugin handle-remove-plugin}])]])]]]))
|
:on-remove-plugin handle-remove-plugin}])]])]]]))
|
||||||
|
|
||||||
|
(mf/defc plugins-permission-list
|
||||||
|
[{:keys [permissions]}]
|
||||||
|
[:div {:class (stl/css :permissions-list)}
|
||||||
|
(cond
|
||||||
|
(contains? permissions "content:write")
|
||||||
|
[:div {:class (stl/css :permissions-list-entry)}
|
||||||
|
i/oauth-1
|
||||||
|
[:p {:class (stl/css :permissions-list-text)}
|
||||||
|
(tr "workspace.plugins.permissions.content-write")]]
|
||||||
|
|
||||||
|
(contains? permissions "content:read")
|
||||||
|
[:div {:class (stl/css :permissions-list-entry)}
|
||||||
|
i/oauth-1
|
||||||
|
[:p {:class (stl/css :permissions-list-text)}
|
||||||
|
(tr "workspace.plugins.permissions.content-read")]])
|
||||||
|
|
||||||
|
(cond
|
||||||
|
(contains? permissions "user:read")
|
||||||
|
[:div {:class (stl/css :permissions-list-entry)}
|
||||||
|
i/oauth-2
|
||||||
|
[:p {:class (stl/css :permissions-list-text)}
|
||||||
|
(tr "workspace.plugins.permissions.user-read")]])
|
||||||
|
|
||||||
|
(cond
|
||||||
|
(contains? permissions "library:write")
|
||||||
|
[:div {:class (stl/css :permissions-list-entry)}
|
||||||
|
i/oauth-3
|
||||||
|
[:p {:class (stl/css :permissions-list-text)}
|
||||||
|
(tr "workspace.plugins.permissions.library-write")]]
|
||||||
|
|
||||||
|
(contains? permissions "library:read")
|
||||||
|
[:div {:class (stl/css :permissions-list-entry)}
|
||||||
|
i/oauth-3
|
||||||
|
[:p {:class (stl/css :permissions-list-text)}
|
||||||
|
(tr "workspace.plugins.permissions.library-read")]])
|
||||||
|
|
||||||
|
(cond
|
||||||
|
(contains? permissions "comment:write")
|
||||||
|
[:div {:class (stl/css :permissions-list-entry)}
|
||||||
|
i/oauth-1
|
||||||
|
[:p {:class (stl/css :permissions-list-text)}
|
||||||
|
(tr "workspace.plugins.permissions.comment-write")]]
|
||||||
|
|
||||||
|
(contains? permissions "comment:read")
|
||||||
|
[:div {:class (stl/css :permissions-list-entry)}
|
||||||
|
i/oauth-1
|
||||||
|
[:p {:class (stl/css :permissions-list-text)}
|
||||||
|
(tr "workspace.plugins.permissions.comment-read")]])
|
||||||
|
|
||||||
|
(cond
|
||||||
|
(contains? permissions "allow:downloads")
|
||||||
|
[:div {:class (stl/css :permissions-list-entry)}
|
||||||
|
i/oauth-1
|
||||||
|
[:p {:class (stl/css :permissions-list-text)}
|
||||||
|
(tr "workspace.plugins.permissions.allow-download")]])])
|
||||||
|
|
||||||
(mf/defc plugins-permissions-dialog
|
(mf/defc plugins-permissions-dialog
|
||||||
{::mf/register modal/components
|
{::mf/register modal/components
|
||||||
::mf/register-as :plugin-permissions}
|
::mf/register-as :plugin-permissions}
|
||||||
|
@ -233,59 +285,7 @@
|
||||||
[:div {:class (stl/css :modal-title)} (tr "workspace.plugins.permissions.title" (str/upper (:name plugin)))]
|
[:div {:class (stl/css :modal-title)} (tr "workspace.plugins.permissions.title" (str/upper (:name plugin)))]
|
||||||
|
|
||||||
[:div {:class (stl/css :modal-content)}
|
[:div {:class (stl/css :modal-content)}
|
||||||
[:div {:class (stl/css :permissions-list)}
|
[:& plugins-permission-list {:permissions permissions}]
|
||||||
(cond
|
|
||||||
(contains? permissions "content:write")
|
|
||||||
[:div {:class (stl/css :permissions-list-entry)}
|
|
||||||
i/oauth-1
|
|
||||||
[:p {:class (stl/css :permissions-list-text)}
|
|
||||||
(tr "workspace.plugins.permissions.content-write")]]
|
|
||||||
|
|
||||||
(contains? permissions "content:read")
|
|
||||||
[:div {:class (stl/css :permissions-list-entry)}
|
|
||||||
i/oauth-1
|
|
||||||
[:p {:class (stl/css :permissions-list-text)}
|
|
||||||
(tr "workspace.plugins.permissions.content-read")]])
|
|
||||||
|
|
||||||
(cond
|
|
||||||
(contains? permissions "user:read")
|
|
||||||
[:div {:class (stl/css :permissions-list-entry)}
|
|
||||||
i/oauth-2
|
|
||||||
[:p {:class (stl/css :permissions-list-text)}
|
|
||||||
(tr "workspace.plugins.permissions.user-read")]])
|
|
||||||
|
|
||||||
(cond
|
|
||||||
(contains? permissions "library:write")
|
|
||||||
[:div {:class (stl/css :permissions-list-entry)}
|
|
||||||
i/oauth-3
|
|
||||||
[:p {:class (stl/css :permissions-list-text)}
|
|
||||||
(tr "workspace.plugins.permissions.library-write")]]
|
|
||||||
|
|
||||||
(contains? permissions "library:read")
|
|
||||||
[:div {:class (stl/css :permissions-list-entry)}
|
|
||||||
i/oauth-3
|
|
||||||
[:p {:class (stl/css :permissions-list-text)}
|
|
||||||
(tr "workspace.plugins.permissions.library-read")]])
|
|
||||||
|
|
||||||
(cond
|
|
||||||
(contains? permissions "comment:write")
|
|
||||||
[:div {:class (stl/css :permissions-list-entry)}
|
|
||||||
i/oauth-1
|
|
||||||
[:p {:class (stl/css :permissions-list-text)}
|
|
||||||
(tr "workspace.plugins.permissions.comment-write")]]
|
|
||||||
|
|
||||||
(contains? permissions "comment:read")
|
|
||||||
[:div {:class (stl/css :permissions-list-entry)}
|
|
||||||
i/oauth-1
|
|
||||||
[:p {:class (stl/css :permissions-list-text)}
|
|
||||||
(tr "workspace.plugins.permissions.comment-read")]])
|
|
||||||
|
|
||||||
(cond
|
|
||||||
(contains? permissions "allow:downloads")
|
|
||||||
[:div {:class (stl/css :permissions-list-entry)}
|
|
||||||
i/oauth-1
|
|
||||||
[:p {:class (stl/css :permissions-list-text)}
|
|
||||||
(tr "workspace.plugins.permissions.allow-download")]])]
|
|
||||||
|
|
||||||
[:div {:class (stl/css :permissions-disclaimer)}
|
[:div {:class (stl/css :permissions-disclaimer)}
|
||||||
(tr "workspace.plugins.permissions.disclaimer")]]
|
(tr "workspace.plugins.permissions.disclaimer")]]
|
||||||
|
@ -305,6 +305,60 @@
|
||||||
:on-click handle-accept-dialog}]]]]]))
|
:on-click handle-accept-dialog}]]]]]))
|
||||||
|
|
||||||
|
|
||||||
|
(mf/defc plugins-permissions-updated-dialog
|
||||||
|
{::mf/register modal/components
|
||||||
|
::mf/register-as :plugin-permissions-update}
|
||||||
|
[{:keys [plugin on-accept on-close]}]
|
||||||
|
|
||||||
|
(let [{:keys [host permissions]} plugin
|
||||||
|
permissions (set permissions)
|
||||||
|
|
||||||
|
handle-accept-dialog
|
||||||
|
(mf/use-callback
|
||||||
|
(fn [event]
|
||||||
|
(dom/prevent-default event)
|
||||||
|
(st/emit! (ptk/event ::ev/event {::ev/name "allow-plugin-permissions"
|
||||||
|
:host host
|
||||||
|
:permissions (->> permissions (str/join ", "))})
|
||||||
|
(modal/hide))
|
||||||
|
(when on-accept (on-accept))))
|
||||||
|
|
||||||
|
handle-close-dialog
|
||||||
|
(mf/use-callback
|
||||||
|
(fn [event]
|
||||||
|
(dom/prevent-default event)
|
||||||
|
(st/emit! (ptk/event ::ev/event {::ev/name "reject-plugin-permissions"
|
||||||
|
:host host
|
||||||
|
:permissions (->> permissions (str/join ", "))})
|
||||||
|
(modal/hide))
|
||||||
|
(when on-close (on-close))))]
|
||||||
|
|
||||||
|
[:div {:class (stl/css :modal-overlay)}
|
||||||
|
[:div {:class (stl/css :modal-dialog :plugin-permissions)}
|
||||||
|
[:button {:class (stl/css :close-btn) :on-click handle-close-dialog} close-icon]
|
||||||
|
[:div {:class (stl/css :modal-title)}
|
||||||
|
(tr "workspace.plugins.permissions-update.title" (str/upper (:name plugin)))]
|
||||||
|
|
||||||
|
[:div {:class (stl/css :modal-content)}
|
||||||
|
[:div {:class (stl/css :modal-paragraph)}
|
||||||
|
(tr "workspace.plugins.permissions-update.warning")]
|
||||||
|
[:& plugins-permission-list {:permissions permissions}]]
|
||||||
|
|
||||||
|
[:div {:class (stl/css :modal-footer)}
|
||||||
|
[:div {:class (stl/css :action-buttons)}
|
||||||
|
[:input
|
||||||
|
{:class (stl/css :cancel-button :button-expand)
|
||||||
|
:type "button"
|
||||||
|
:value (tr "ds.confirm-cancel")
|
||||||
|
:on-click handle-close-dialog}]
|
||||||
|
|
||||||
|
[:input
|
||||||
|
{:class (stl/css :primary-button :button-expand)
|
||||||
|
:type "button"
|
||||||
|
:value (tr "ds.confirm-allow")
|
||||||
|
:on-click handle-accept-dialog}]]]]]))
|
||||||
|
|
||||||
|
|
||||||
(mf/defc plugins-try-out-dialog
|
(mf/defc plugins-try-out-dialog
|
||||||
{::mf/register modal/components
|
{::mf/register modal/components
|
||||||
::mf/register-as :plugin-try-out}
|
::mf/register-as :plugin-try-out}
|
||||||
|
|
|
@ -76,6 +76,11 @@
|
||||||
color: var(--color-foreground-secondary);
|
color: var(--color-foreground-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.modal-paragraph {
|
||||||
|
font-size: $fs-14;
|
||||||
|
color: var(--color-foreground-primary);
|
||||||
|
}
|
||||||
|
|
||||||
.primary-button {
|
.primary-button {
|
||||||
@extend .button-primary;
|
@extend .button-primary;
|
||||||
@include headlineSmallTypography;
|
@include headlineSmallTypography;
|
||||||
|
|
|
@ -64,6 +64,7 @@
|
||||||
manifest
|
manifest
|
||||||
(d/without-nils
|
(d/without-nils
|
||||||
{:plugin-id plugin-id
|
{:plugin-id plugin-id
|
||||||
|
:url plugin-url
|
||||||
:name name
|
:name name
|
||||||
:description desc
|
:description desc
|
||||||
:host origin
|
:host origin
|
||||||
|
|
|
@ -5610,6 +5610,12 @@ msgstr "'%s' PLUGIN WANTS ACCESS TO:"
|
||||||
msgid "workspace.plugins.permissions.user-read"
|
msgid "workspace.plugins.permissions.user-read"
|
||||||
msgstr "Read the profile information of the current user."
|
msgstr "Read the profile information of the current user."
|
||||||
|
|
||||||
|
msgid "workspace.plugins.permissions-update.title"
|
||||||
|
msgstr "UPDATE THIS PLUGIN"
|
||||||
|
|
||||||
|
msgid "workspace.plugins.permissions-update.warning"
|
||||||
|
msgstr "The plugin has been modified since you last opened it. It now also wants to access:"
|
||||||
|
|
||||||
msgid "workspace.plugins.try-out.title"
|
msgid "workspace.plugins.try-out.title"
|
||||||
msgstr "'%s' PLUGIN IS INSTALLED FOR YOUR USER!"
|
msgstr "'%s' PLUGIN IS INSTALLED FOR YOUR USER!"
|
||||||
|
|
||||||
|
|
|
@ -5594,6 +5594,12 @@ msgstr "LA EXTENSIÓN '%s' SOLICITA PERMISO PARA ACCEDER:"
|
||||||
msgid "workspace.plugins.permissions.user-read"
|
msgid "workspace.plugins.permissions.user-read"
|
||||||
msgstr "Leer la información del usuario actual."
|
msgstr "Leer la información del usuario actual."
|
||||||
|
|
||||||
|
msgid "workspace.plugins.permissions-update.title"
|
||||||
|
msgstr "EXTENSIÓN ACTUALIZADA"
|
||||||
|
|
||||||
|
msgid "workspace.plugins.permissions-update.warning"
|
||||||
|
msgstr "La extensión ha cambiado desde la última vez que la abriste. Ahora quiere acceder a:"
|
||||||
|
|
||||||
msgid "workspace.plugins.try-out.title"
|
msgid "workspace.plugins.try-out.title"
|
||||||
msgstr "¡LA EXTENSIÓN '%s' HA SIDO INSTALADA PARA TU USUARIO!"
|
msgstr "¡LA EXTENSIÓN '%s' HA SIDO INSTALADA PARA TU USUARIO!"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue