From ef06f51d9187f5f6e0e7579044c4eda07815bfaf Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sun, 11 Oct 2026 13:38:01 -0400 Subject: [PATCH] A project you may only look at takes no edit, and greys what would make one It used to take the edit and never save it, so a drawing stayed until the next reload and was gone after. `edit/edit-entry`, the one way a person changes the document, now refuses every edit when you cannot edit, rather than each command checking for itself; renaming the project and regenerating settings, which go around it, check too. The stage only selects, and the drawing tools, swatches, inspector fields, the timeline's edit buttons and the pool's add and upload are greyed out. Selecting, inspecting, playing and the view's own settings stay. Co-Authored-By: Claude Opus 5.5 --- frontend/src/arthur/events/edit.cljs | 14 ++++++++-- frontend/src/arthur/events/project.cljs | 9 ++++--- frontend/src/arthur/subs/ui.cljs | 5 +++- frontend/src/arthur/ui/shell.cljs | 6 ++++- frontend/src/arthur/ui/tools.cljs | 6 ++--- .../test/arthur/events/read_only_test.cljs | 27 +++++++++++++++++++ static/arthur/app.css | 11 ++++++++ 7 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 frontend/test/arthur/events/read_only_test.cljs diff --git a/frontend/src/arthur/events/edit.cljs b/frontend/src/arthur/events/edit.cljs index a900ad4..70f5f27 100644 --- a/frontend/src/arthur/events/edit.cljs +++ b/frontend/src/arthur/events/edit.cljs @@ -46,12 +46,22 @@ (update :project merge {:status "edited · unsaved"})) db))) +(defn read-only? + "Somebody else's project that we may look at and not write." + [db] + (false? (get-in db [:project :can-edit?]))) + (defn edit-entry "Apply `f` to the loaded ENTRY — the document and the blocks, footage and source tracks beside it — and return the new db. For an edit that brings tier-2 - data in with it, which a document edit alone cannot." + data in with it, which a document edit alone cannot. + + NOTHING, IN A PROJECT YOU MAY ONLY LOOK AT. It used to take the edit and then + never save it, so a drawing stayed until the next reload and was gone after. + Here, as the one way a person changes the document, it is one rule rather + than one per command." [db f] - (replace-entry db (recorded f))) + (if (read-only? db) db (replace-entry db (recorded f)))) (defn transport "App-db's copy of what the transport reads off the clip, after the clip was diff --git a/frontend/src/arthur/events/project.cljs b/frontend/src/arthur/events/project.cljs index 860fcc7..c46c848 100644 --- a/frontend/src/arthur/events/project.cljs +++ b/frontend/src/arthur/events/project.cljs @@ -532,7 +532,8 @@ (fn [{:keys [db]} [_ edit]] (let [id (:clip/current db) entry (store/entry id)] - (if (or (get-in db [:project :busy?]) (empty? (:analyses (:clip entry)))) + (if (or (get-in db [:project :busy?]) (empty? (:analyses (:clip entry))) + (edit/read-only? db)) {} (let [plan (regenerate/plan (:clip entry) edit) report (select-keys plan [:features :roles]) @@ -656,8 +657,10 @@ (rf/reg-event-fx ::rename (fn [{:keys [db]} [_ value]] - {:db (assoc-in db [:project :name] (not-empty (str/trim value))) - :dispatch [::save {:auto? true :force? true}]})) + (if (edit/read-only? db) + {} + {:db (assoc-in db [:project :name] (not-empty (str/trim value))) + :dispatch [::save {:auto? true :force? true}]}))) (rf/reg-event-fx ::project-setting diff --git a/frontend/src/arthur/subs/ui.cljs b/frontend/src/arthur/subs/ui.cljs index 25fd988..a80faa1 100644 --- a/frontend/src/arthur/subs/ui.cljs +++ b/frontend/src/arthur/subs/ui.cljs @@ -11,6 +11,7 @@ [arthur.domain.node :as node] [arthur.domain.pick :as pick] [arthur.domain.symbol :as symbol] + [arthur.events.edit :as edit] [arthur.footage.store :as store] [arthur.subs.playback :as playback] [arthur.subs.render :as render] @@ -31,7 +32,9 @@ (rf/reg-sub ::clipboard (fn [db _] (get-in db [:ui :clipboard]))) (rf/reg-sub ::retry (fn [db _] (get-in db [:ui :retry]))) (rf/reg-sub ::tone (fn [db _] (get-in db [:ui :tone]))) -(rf/reg-sub ::tool (fn [db _] (or (get-in db [:ui :tool]) :select))) +(rf/reg-sub ::read-only? (fn [db _] (edit/read-only? db))) +;; Looking is all a read-only project allows, so it is all the stage does. +(rf/reg-sub ::tool (fn [db _] (if (edit/read-only? db) :select (or (get-in db [:ui :tool]) :select)))) (rf/reg-sub ::auto-key? (fn [db _] (boolean (get-in db [:ui :auto-key?])))) (rf/reg-sub ::draft (fn [db _] (get-in db [:ui :draft]))) (rf/reg-sub ::vertex (fn [db _] (get-in db [:ui :vertex]))) diff --git a/frontend/src/arthur/ui/shell.cljs b/frontend/src/arthur/ui/shell.cljs index 20015d7..65c659d 100644 --- a/frontend/src/arthur/ui/shell.cljs +++ b/frontend/src/arthur/ui/shell.cljs @@ -12,6 +12,7 @@ [arthur.events.playback :as pb] [arthur.subs.playback :as playback] [arthur.subs.render :as render] + [arthur.subs.ui :as sub] [arthur.ui.layout :as layout] [arthur.ui.location :as location] [arthur.ui.params :as params] @@ -69,7 +70,10 @@ ;; pane's contents. (let [{:keys [pool params shut] :as state} @(rf/subscribe [::layout/state]) gone? #(contains? shut %)] - [:div.app {:style (layout/vars state)} + ;; `read-only`: somebody else's project. The edits themselves are refused + ;; in `events/edit`; this greys out the controls that would make them. + [:div.app {:style (layout/vars state) + :class (when @(rf/subscribe [::sub/read-only?]) "read-only")} [topbar/view] [shortcuts/sheet] (when-not (gone? :pool) [pool/view]) diff --git a/frontend/src/arthur/ui/tools.cljs b/frontend/src/arthur/ui/tools.cljs index f4823ce..8ee3f02 100644 --- a/frontend/src/arthur/ui/tools.cljs +++ b/frontend/src/arthur/ui/tools.cljs @@ -37,10 +37,10 @@ [:aside.toolbox [:div.tools (doall - (for [{t :tool :keys [key name tip icon]} kit] + (for [{t :tool label :name :keys [key tip icon]} kit] ^{:key t} - [:button {:class (str "tool" (when (= t tool) " on")) - :title (str name " (" (.toUpperCase key) ") — " tip) + [:button {:class (str "tool tool-" (name t) (when (= t tool) " on")) + :title (str label " (" (.toUpperCase key) ") — " tip) :on-click #(rf/dispatch [::ui/set-tool t])} [:svg {:view-box "0 0 18 18" :width 18 :height 18} icon]]))] [palette/grid] diff --git a/frontend/test/arthur/events/read_only_test.cljs b/frontend/test/arthur/events/read_only_test.cljs new file mode 100644 index 0000000..839f0ba --- /dev/null +++ b/frontend/test/arthur/events/read_only_test.cljs @@ -0,0 +1,27 @@ +(ns arthur.events.read-only-test + (:require [cljs.test :refer [deftest is]] + [arthur.domain.clip :as clip] + [arthur.domain.paint :as paint] + [arthur.events.ui :as ui] + [arthur.footage.store :as store] + [arthur.subs.ui :as sub] + [re-frame.core :as rf] + [re-frame.db :as rf-db])) + +(deftest a-project-you-may-only-look-at-takes-no-edit + (let [doc (paint/new-shape (clip/blank) :main :s 0 [0 0 10 0 20 10 10 20 0 20] 1) + id (store/install! {:clip doc :store {}} "read-only") + shape #(get-in (:clip (store/entry (:clip/current @rf-db/app-db))) [:symbols :main :nodes :s])] + (reset! rf-db/app-db {:clip/current id :paint/revision 0 + :project {:can-edit? false} + :ui {:open :main :tool :brush :selection [:node :main :s [:s]] + :selections [[:node :main :s [:s]]]} + :playback {:frame 0}}) + (is (= :select @(rf/subscribe [::sub/tool])) "the stage only selects") + (rf/dispatch-sync [::ui/delete-selected]) + (is (some? (shape)) "Delete deletes nothing") + (is (= 0 (:paint/revision @rf-db/app-db)) "and nothing became unsaved") + (swap! rf-db/app-db #(-> % (assoc-in [:project :can-edit?] true) (update :ui assoc :tool :select :selection [:node :main :s [:s]] + :selections [[:node :main :s [:s]]]))) + (rf/dispatch-sync [::ui/delete-selected]) + (is (nil? (shape)) "an editor's Delete does"))) diff --git a/static/arthur/app.css b/static/arthur/app.css index 682d499..71420ad 100644 --- a/static/arthur/app.css +++ b/static/arthur/app.css @@ -2062,3 +2062,14 @@ button.tl-key.selected { background: var(--pick); box-shadow: 0 0 0 2px var(--pi cursor: ew-resize; touch-action: none; background: linear-gradient(var(--sel), var(--sel)) center / 2px 100% no-repeat; } + +/* -------------------------------------------------------------------------- + read-only — somebody else's project. `events/edit` refuses the edits; this + greys out what would make them, so nothing offers what it cannot do. + Selecting, inspecting, playing and the view's own settings stay. */ +.app.read-only :is( + .toolbox .tool:not(.tool-select), .toolbox > :not(.tools), + .context-controls, .creation-controls, button.auto-key, + .params .inspect :is(input, select, textarea, button), + .pool-foot +) { opacity: .4; pointer-events: none; }