🎉 Edit assets

This commit is contained in:
Andrés Moya 2020-07-30 14:52:58 +02:00
parent af2c49dd16
commit d40f27e18c
10 changed files with 364 additions and 63 deletions

View file

@ -449,7 +449,7 @@
[path]
(let [[basedir libraries] (read-file path)]
(db/with-atomic [conn db/pool]
(let [project-id (create-project-if-not-exists conn {:name "Media loader"})]
(let [project-id (create-project-if-not-exists conn {:name "System libraries"})]
(run! #(process-library conn basedir project-id %) libraries)))))
(defn -main

View file

@ -161,9 +161,10 @@
(def ^:private sql:select-color-for-update
"select c.*,
lib.team_id as team_id
p.team_id as team_id
from color as c
inner join color_library as lib on (lib.id = c.library_id)
inner join file as f on f.id = c.file_id
inner join project as p on p.id = f.project_id
where c.id = ?
for update of c")
@ -175,6 +176,26 @@
row))
;; --- Mutation: Update Color
(s/def ::update-color
(s/keys :req-un [::profile-id ::id ::content]))
(sm/defmutation ::update-color
[{:keys [profile-id id content] :as params}]
(db/with-atomic [conn db/pool]
(let [clr (select-color-for-update conn id)
;; IMPORTANT: if the previous name was equal to the hex content,
;; we must rename it in addition to changing the value.
new-name (if (= (:name clr) (:content clr))
content
(:name clr))]
(teams/check-edition-permissions! conn profile-id (:team-id clr))
(db/update! conn :color
{:name new-name
:content content}
{:id id}))))
;; --- Delete Color
(declare delete-color)

View file

@ -71,7 +71,8 @@
(defn check-edition-permissions!
[conn profile-id team-id]
(let [row (db/exec-one! conn [sql:team-permissions profile-id team-id])]
(when-not (or (:can-edit row)
(when-not (or (= team-id uuid/zero)
(:can-edit row)
(:is-admin row)
(:is-owner row))
(ex/raise :type :validation

View file

@ -30,7 +30,8 @@
(defn check-edition-permissions!
[conn profile-id team-id]
(let [row (db/exec-one! conn [sql:team-permissions profile-id team-id])]
(when-not (or (:can-edit row)
(when-not (or (= team-id uuid/zero) ;; We can write global-project owned items
(:can-edit row)
(:is-admin row)
(:is-owner row))
(ex/raise :type :validation
@ -39,10 +40,9 @@
(defn check-read-permissions!
[conn profile-id team-id]
(let [row (db/exec-one! conn [sql:team-permissions profile-id team-id])]
(when-not (or (:can-edit row)
(when-not (or (= team-id uuid/zero) ;; We can read global-project owned items
(:can-edit row)
(:is-admin row)
(:is-owner row)
;; We can read global-project owned items
(= team-id #uuid "00000000-0000-0000-0000-000000000000"))
(:is-owner row))
(ex/raise :type :validation
:code :not-authorized))))