Repository: penpot/penpot
File: frontend/src/app/main/data/plugins.cljs (ClojureScript)

Code before:
                                       (:permissions plugin))
                is-edition-plugin? (or (contains? permissions "content:write")
                                       (contains? permissions "library:write"))]

            (when (or (not close-only-edition-plugins?)
                      is-edition-plugin?)
              (close-plugin! plugin))))))))

(defn delay-open-plugin
  [plugin]
  (ptk/reify ::delay-open-plugin
    ptk/UpdateEvent
    (update [_ state]
      (assoc state ::open-plugin (:plugin-id plugin)))))

(defn check-open-plugin
  []
  (ptk/reify ::check-open-plugin
    ptk/WatchEvent
    (watch [_ state _]
      (let [user-can-edit? (dm/get-in state [:permissions :can-edit])]
        (when-let [pid (::open-plugin state)]
          (let [plugin (preg/get-plugin pid)]
            (open-plugin! plugin user-can-edit?)
            (rx/of (ev/event {::ev/name "start-plugin"
                              ::ev/origin "workspace:try-out"
                              :name (:name plugin)
                              :host (:host plugin)})
                   #(dissoc % ::open-plugin))))))))

(defn- update-plugin-permissions-peek
  [{:keys [plugin-id url]}]
  (when 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 [permissions  (:permissions new-manifest)]
              (when permissions
                (st/emit! (save-plugin-permissions-peek plugin-id permissions)))))
          (fn [_err]
            ;; on error do nothing
            )))))

(defn update-plugins-permissions-peek
  []
  (ptk/reify ::update-plugins-permissions-peek
    ptk/UpdateEvent
    (update [_ state]
      (let [now        (dt/now)

Review comment (suggestion):
I think the origin here should be simply `workspace`, the `try-out` suffix does not indicates anything relevant here I think.

Code after:
                                       (:permissions plugin))
                is-edition-plugin? (or (contains? permissions "content:write")
                                       (contains? permissions "library:write"))]

            (when (or (not close-only-edition-plugins?)
                      is-edition-plugin?)
              (close-plugin! plugin))))))))

(defn delay-open-plugin
  [plugin]
  (ptk/reify ::delay-open-plugin
    ptk/UpdateEvent
    (update [_ state]
      (assoc state ::open-plugin (:plugin-id plugin)))))

(defn check-open-plugin
  []
  (ptk/reify ::check-open-plugin
    ptk/WatchEvent
    (watch [_ state _]
      (let [user-can-edit? (dm/get-in state [:permissions :can-edit])]
        (when-let [pid (::open-plugin state)]
          (let [plugin (preg/get-plugin pid)]
            (open-plugin! plugin user-can-edit?)
            (rx/of (ev/event {::ev/name "start-plugin"
                              ::ev/origin "workspace"
                              :name (:name plugin)
                              :host (:host plugin)})
                   #(dissoc % ::open-plugin))))))))

(defn- update-plugin-permissions-peek
  [{:keys [plugin-id url]}]
  (when 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 [permissions  (:permissions new-manifest)]
              (when permissions
                (st/emit! (save-plugin-permissions-peek plugin-id permissions)))))
          (fn [_err]
            ;; on error do nothing
            )))))

(defn update-plugins-permissions-peek
  []
  (ptk/reify ::update-plugins-permissions-peek
    ptk/UpdateEvent
    (update [_ state]
      (let [now        (dt/now)