THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Browse Source

🔥 Remove a lot of obsolete code

pull/295/head
Andrés Moya 9 months ago
committed by Andrey Antukh
parent
commit
d349e46cd8
  1. 267
      backend/src/uxbox/media_loader.clj
  2. 8
      backend/src/uxbox/services/init.clj
  3. 85
      backend/src/uxbox/services/mutations/colors.clj
  4. 136
      backend/src/uxbox/services/mutations/files.clj
  5. 206
      backend/src/uxbox/services/mutations/icons.clj
  6. 61
      backend/src/uxbox/services/mutations/media.clj
  7. 48
      backend/src/uxbox/services/queries/colors.clj
  8. 28
      backend/src/uxbox/services/queries/files.clj
  9. 148
      backend/src/uxbox/services/queries/icons.clj
  10. 48
      backend/src/uxbox/services/queries/media.clj
  11. 17
      backend/tests/uxbox/tests/helpers.clj
  12. 61
      backend/tests/uxbox/tests/test_services_colors.clj
  13. 101
      backend/tests/uxbox/tests/test_services_files.clj
  14. 180
      backend/tests/uxbox/tests/test_services_icons.clj
  15. 103
      backend/tests/uxbox/tests/test_services_media.clj
  16. 23
      backend/tests/uxbox/tests/test_services_profile.clj
  17. 20
      frontend/resources/locales.json
  18. 5
      frontend/resources/styles/main-default.scss
  19. 360
      frontend/resources/styles/main/layouts/library-page.scss
  20. 2
      frontend/resources/styles/main/layouts/main-layout.scss
  21. 92
      frontend/resources/styles/main/partials/dashboard-bar.scss
  22. 42
      frontend/resources/styles/main/partials/dashboard-sidebar.scss
  23. 50
      frontend/resources/styles/main/partials/sidebar-assets.scss
  24. 141
      frontend/resources/styles/main/partials/workspace-libraries.scss
  25. 226
      frontend/src/uxbox/main/data/colors.cljs
  26. 102
      frontend/src/uxbox/main/data/icons.cljs
  27. 229
      frontend/src/uxbox/main/data/library.cljs
  28. 303
      frontend/src/uxbox/main/data/media.cljs
  29. 7
      frontend/src/uxbox/main/data/workspace.cljs
  30. 2
      frontend/src/uxbox/main/data/workspace/persistence.cljs
  31. 8
      frontend/src/uxbox/main/repo.cljs
  32. 23
      frontend/src/uxbox/main/ui.cljs
  33. 20
      frontend/src/uxbox/main/ui/dashboard.cljs
  34. 391
      frontend/src/uxbox/main/ui/dashboard/library.cljs
  35. 8
      frontend/src/uxbox/main/ui/dashboard/sidebar.cljs
  36. 4
      frontend/src/uxbox/main/ui/shapes/image.cljs
  37. 16
      frontend/src/uxbox/main/ui/workspace/colorpalette.cljs
  38. 8
      frontend/src/uxbox/main/ui/workspace/header.cljs
  39. 8
      frontend/src/uxbox/main/ui/workspace/left_toolbar.cljs
  40. 3
      frontend/src/uxbox/main/ui/workspace/sidebar.cljs
  41. 22
      frontend/src/uxbox/main/ui/workspace/sidebar/assets.cljs
  42. 187
      frontend/src/uxbox/main/ui/workspace/sidebar/libraries.cljs
  43. 64
      sample_media/config.edn

267
backend/src/uxbox/media_loader.clj

@ -40,8 +40,7 @@
;; --- Constants & Helpers
(def ^:const +images-uuid-ns+ #uuid "3642a582-565f-4070-beba-af797ab27a6a")
(def ^:const +icons-uuid-ns+ #uuid "3642a582-565f-4070-beba-af797ab27a6b")
(def ^:const +graphics-uuid-ns+ #uuid "3642a582-565f-4070-beba-af797ab27a6a")
(def ^:const +colors-uuid-ns+ #uuid "3642a582-565f-4070-beba-af797ab27a6c")
(s/def ::id ::us/uuid)
@ -49,16 +48,7 @@
(s/def ::path ::us/string)
(s/def ::regex #(instance? java.util.regex.Pattern %))
;; (s/def ::colors
;; (s/* (s/cat :name ::us/string :color ::us/color)))
;;
;; (s/def ::import-item-media
;; (s/keys :req-un [::name ::path ::regex]))
;;
;; (s/def ::import-item-color
;; (s/keys :req-un [::name ::id ::colors]))
(s/def ::import-images
(s/def ::import-graphics
(s/keys :req-un [::path ::regex]))
(s/def ::import-color
@ -68,225 +58,23 @@
(s/def ::import-library
(s/keys :req-un [::name]
:opt-un [::import-images ::import-colors]))
:opt-un [::import-graphics ::import-colors]))
(defn exit!
([] (exit! 0))
([code]
(System/exit code)))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; Icons Libraries Importer
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; (defn- icon-library-exists?
;; [conn id]
;; (s/assert ::us/uuid id)
;; (let [row (db/get-by-id conn :icon-library id)]
;; (if row true false)))
;;
;; (defn- create-icons-library
;; [conn {:keys [name] :as item}]
;; (let [id (uuid/namespaced +icons-uuid-ns+ name)]
;; (log/info "Creating icons library:" name)
;; (icons/create-library conn {:team-id uuid/zero
;; :id id
;; :name name})))
;;
;; (defn- create-icons-library-if-not-exists
;; [conn {:keys [name] :as item}]
;; (let [id (uuid/namespaced +icons-uuid-ns+ name)]
;; (when-not (icon-library-exists? conn id)
;; (create-icons-library conn item))
;; id))
;;
;; (defn- create-icon
;; [conn library-id icon-id localpath]
;; (s/assert fs/path? localpath)
;; (s/assert ::us/uuid library-id)
;; (s/assert ::us/uuid icon-id)
;; (let [filename (fs/name localpath)
;; extension (second (fs/split-ext filename))
;; data (svg/parse localpath)
;; mdata (select-keys data [:width :height :view-box])]
;;
;; (log/info "Creating or updating icon" filename icon-id)
;; (icons/create-icon conn {:id icon-id
;; :library-id library-id
;; :name (:name data filename)
;; :content (:content data)
;; :metadata mdata})))
;;
;; (defn- icon-exists?
;; [conn id]
;; (s/assert ::us/uuid id)
;; (let [row (db/get-by-id conn :icon id)]
;; (if row true false)))
;;
;; (defn- import-icon-if-not-exists
;; [conn library-id fpath]
;; (s/assert ::us/uuid library-id)
;; (s/assert fs/path? fpath)
;; (let [icon-id (uuid/namespaced +icons-uuid-ns+ (str library-id (fs/name fpath)))]
;; (when-not (icon-exists? conn icon-id)
;; (create-icon conn library-id icon-id fpath))
;; icon-id))
;;
;; (defn- import-icons
;; [conn library-id {:keys [path regex] :as item}]
;; (run! (fn [fpath]
;; (when (re-matches regex (str fpath))
;; (import-icon-if-not-exists conn library-id fpath)))
;; (->> (fs/list-dir path)
;; (filter fs/regular-file?))))
;;
;; (defn- process-icons-library
;; [conn basedir {:keys [path regex] :as item}]
;; (s/assert ::import-item-media item)
;; (let [library-id (create-icons-library-if-not-exists conn item)]
;; (->> (assoc item :path (fs/join basedir path))
;; (import-icons conn library-id))))
;;
;;
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; --- Images Libraries Importer
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; (defn- image-library-exists?
;; [conn id]
;; (s/assert ::us/uuid id)
;; (let [row (db/get-by-id conn :image-library id)]
;; (if row true false)))
;;
;; (defn- create-images-library
;; [conn {:keys [name] :as item}]
;; (let [id (uuid/namespaced +images-uuid-ns+ name)]
;; (log/info "Creating image library:" name)
;; (media/create-library conn {:id id
;; :team-id uuid/zero
;; :name name})))
;;
;; (defn- create-images-library-if-not-exists
;; [conn {:keys [name] :as item}]
;; (let [id (uuid/namespaced +images-uuid-ns+ name)]
;; (when-not (image-library-exists? conn id)
;; (create-images-library conn item)
;; id)))
;;
;; (defn- create-image
;; [conn library-id image-id localpath]
;; (s/assert fs/path? localpath)
;; (s/assert ::us/uuid library-id)
;; (s/assert ::us/uuid image-id)
;; (let [filename (fs/name localpath)
;; extension (second (fs/split-ext filename))
;; file (io/as-file localpath)
;; mtype (case extension
;; ".jpg" "image/jpeg"
;; ".png" "image/png"
;; ".webp" "image/webp")]
;; (log/info "Creating image" filename image-id)
;; (media/create-image conn {:content {:tempfile localpath
;; :filename filename
;; :content-type mtype
;; :size (.length file)}
;; :id image-id
;; :library-id library-id
;; :user uuid/zero
;; :name filename})))
;;
;; (defn- image-exists?
;; [conn id]
;; (s/assert ::us/uuid id)
;; (let [row (db/get-by-id conn :image id)]
;; (if row true false)))
;;
;; (defn- import-image-if-not-exists
;; [conn library-id fpath]
;; (s/assert ::us/uuid library-id)
;; (s/assert fs/path? fpath)
;; (let [image-id (uuid/namespaced +images-uuid-ns+ (str library-id (fs/name fpath)))]
;; (when-not (image-exists? conn image-id)
;; (create-image conn library-id image-id fpath))
;; image-id))
;;
;; (defn- import-images
;; [conn library-id {:keys [path regex] :as item}]
;; (run! (fn [fpath]
;; (when (re-matches regex (str fpath))
;; (import-image-if-not-exists conn library-id fpath)))
;; (->> (fs/list-dir path)
;; (filter fs/regular-file?))))
;;
;; (defn- process-images-library
;; [conn basedir {:keys [path regex] :as item}]
;; (s/assert ::import-item-media item)
;; (let [library-id (create-images-library-if-not-exists conn item)]
;; (->> (assoc item :path (fs/join basedir path))
;; (import-images conn library-id))))
;;
;;
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; Colors Libraries Importer
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; (defn- color-library-exists?
;; [conn id]
;; (s/assert ::us/uuid id)
;; (let [row (db/get-by-id conn :file id)]
;; (if row true false)))
;;
;; (defn- create-colors-library
;; [conn {:keys [name] :as item}]
;; (let [id (uuid/namespaced +colors-uuid-ns+ name)]
;; (log/info "Creating color library:" name)
;; (colors/create-library conn {:id id
;; :team-id uuid/zero
;; :name name})))
;;
;;
;; (defn- create-colors-library-if-not-exists
;; [conn {:keys [name] :as item}]
;; (let [id (uuid/namespaced +colors-uuid-ns+ name)]
;; (when-not (color-library-exists? conn id)
;; (create-colors-library conn item))
;; id))
;;
;; (defn- create-color
;; [conn library-id name content]
;; (s/assert ::us/uuid library-id)
;; (s/assert ::us/color content)
;; (let [color-id (uuid/namespaced +colors-uuid-ns+ (str library-id content))]
;; (log/info "Creating color" color-id "-" name content)
;; (colors/create-color conn {:id color-id
;; :library-id library-id
;; :name name
;; :content content})
;; color-id))
;;
;; (defn- import-colors
;; [conn library-id {:keys [colors] :as item}]
;; (db/delete! conn :color {:library-id library-id})
;; (run! (fn [[name content]]
;; (create-color conn library-id name content))
;; (partition-all 2 colors)))
;;
;; (defn- process-colors-library
;; [conn {:keys [name id colors] :as item}]
;; (us/verify ::import-item-color item)
;; (let [library-id (create-colors-library-if-not-exists conn item)]
;; (import-colors conn library-id item)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Images Importer
;; Graphics Importer
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn- create-image
[conn file-id image-id localpath]
(defn- create-media-object
[conn file-id media-object-id localpath]
(s/assert fs/path? localpath)
(s/assert ::us/uuid file-id)
(s/assert ::us/uuid image-id)
(s/assert ::us/uuid media-object-id)
(let [filename (fs/name localpath)
extension (second (fs/split-ext filename))
file (io/as-file localpath)
@ -295,36 +83,36 @@
".png" "image/png"
".webp" "image/webp"
".svg" "image/svg+xml")]
(log/info "Creating image" filename image-id)
(log/info "Creating image" filename media-object-id)
(media/create-media-object conn {:content {:tempfile localpath
:filename filename
:content-type mtype
:size (.length file)}
:id image-id
:id media-object-id
:file-id file-id
:name filename
:is-local false})))
(defn- image-exists?
(defn- media-object-exists?
[conn id]
(s/assert ::us/uuid id)
(let [row (db/get-by-id conn :media-object id)]
(if row true false)))
(defn- import-image-if-not-exists
(defn- import-media-object-if-not-exists
[conn file-id fpath]
(s/assert ::us/uuid file-id)
(s/assert fs/path? fpath)
(let [image-id (uuid/namespaced +images-uuid-ns+ (str file-id (fs/name fpath)))]
(when-not (image-exists? conn image-id)
(create-image conn file-id image-id fpath))
image-id))
(let [media-object-id (uuid/namespaced +graphics-uuid-ns+ (str file-id (fs/name fpath)))]
(when-not (media-object-exists? conn media-object-id)
(create-media-object conn file-id media-object-id fpath))
media-object-id))
(defn- import-images
[conn file-id {:keys [path regex] :as images}]
(defn- import-graphics
[conn file-id {:keys [path regex] :as graphics}]
(run! (fn [fpath]
(when (re-matches regex (str fpath))
(import-image-if-not-exists conn file-id fpath)))
(import-media-object-if-not-exists conn file-id fpath)))
(->> (fs/list-dir path)
(filter fs/regular-file?))))
@ -371,17 +159,17 @@
:profile-id uuid/zero
:project-id project-id
:name name
:shared? true})
:is-shared true})
(files/create-page conn {:file-id id}))
id))
(defn- process-library
[conn basedir project-id {:keys [name images colors] :as library}]
[conn basedir project-id {:keys [name graphics colors] :as library}]
(us/verify ::import-library library)
(let [library-file-id (create-library-file-if-not-exists conn project-id library)]
(when images
(->> (assoc images :path (fs/join basedir (:path images)))
(import-images conn library-file-id)))
(when graphics
(->> (assoc graphics :path (fs/join basedir (:path graphics)))
(import-graphics conn library-file-id)))
(when colors
(import-colors conn library-file-id colors))))
@ -435,15 +223,6 @@
[]
(mount/stop))
;; (defn- importer
;; [conn basedir data]
;; (let [images (:images data)
;; icons (:icons data)
;; colors (:colors data)]
;; (run! #(process-images-library conn basedir %) images)
;; (run! #(process-icons-library conn basedir %) icons)
;; (run! #(process-colors-library conn %) colors)))
(defn run
[path]
(let [[basedir libraries] (read-file path)]

8
backend/src/uxbox/services/init.clj

@ -14,7 +14,6 @@
(defn- load-query-services
[]
;; (require 'uxbox.services.queries.icons)
(require 'uxbox.services.queries.media)
(require 'uxbox.services.queries.colors)
(require 'uxbox.services.queries.projects)
@ -22,20 +21,17 @@
(require 'uxbox.services.queries.pages)
(require 'uxbox.services.queries.profile)
(require 'uxbox.services.queries.recent-files)
(require 'uxbox.services.queries.viewer)
)
(require 'uxbox.services.queries.viewer))
(defn- load-mutation-services
[]
(require 'uxbox.services.mutations.demo)
;; (require 'uxbox.services.mutations.icons)
(require 'uxbox.services.mutations.media)
(require 'uxbox.services.mutations.colors)
(require 'uxbox.services.mutations.projects)
(require 'uxbox.services.mutations.files)
(require 'uxbox.services.mutations.pages)
(require 'uxbox.services.mutations.profile)
)
(require 'uxbox.services.mutations.profile))
(defstate query-services
:start (load-query-services))

85
backend/src/uxbox/services/mutations/colors.clj

@ -29,91 +29,6 @@
(s/def ::library-id ::us/uuid)
(s/def ::content ::us/string)
;; ;; --- Mutation: Create Library
;;
;; (declare create-library)
;;
;; (s/def ::create-color-library
;; (s/keys :req-un [::profile-id ::team-id ::name]
;; :opt-un [::id]))
;;
;; (sm/defmutation ::create-color-library
;; [{:keys [profile-id team-id] :as params}]
;; (db/with-atomic [conn db/pool]
;; (teams/check-edition-permissions! conn profile-id team-id)
;; (create-library conn params)))
;;
;; (defn create-library
;; [conn {:keys [id team-id name]}]
;; (let [id (or id (uuid/next))]
;; (db/insert! conn :color-library
;; {:id id
;; :team-id team-id
;; :name name})))
;;
;; ;; --- Mutation: Rename Library
;;
;; (declare select-library-for-update)
;; (declare rename-library)
;;
;; (s/def ::rename-color-library
;; (s/keys :req-un [::profile-id ::name ::id]))
;;
;; (sm/defmutation ::rename-color-library
;; [{:keys [id profile-id name] :as params}]
;; (db/with-atomic [conn db/pool]
;; (let [lib (select-library-for-update conn id)]
;; (teams/check-edition-permissions! conn profile-id (:team-id lib))
;; (rename-library conn id name))))
;;
;; (def ^:private sql:select-library-for-update
;; "select l.*
;; from color_library as l
;; where l.id = $1
;; for update")
;;
;; (def ^:private sql:rename-library
;; "update color_library
;; set name = $2
;; where id = $1")
;;
;; (defn- select-library-for-update
;; [conn id]
;; (db/get-by-id conn :color-library id {:for-update true}))
;;
;; (defn- rename-library
;; [conn id name]
;; (db/update! conn :color-library
;; {:name name}
;; {:id id}))
;; ;; --- Delete Library
;;
;; (declare delete-library)
;;
;; (s/def ::delete-color-library
;; (s/keys :req-un [::profile-id ::id]))
;;
;; (sm/defmutation ::delete-color-library
;; [{:keys [id profile-id] :as params}]
;; (db/with-atomic [conn db/pool]
;; (let [lib (select-library-for-update conn id)]
;; (teams/check-edition-permissions! conn profile-id (:team-id lib))
;;
;; ;; Schedule object deletion
;; (tasks/submit! conn {:name "delete-object"
;; :delay cfg/default-deletion-delay
;; :props {:id id :type :color-library}})
;;
;; (db/update! conn :color-library
;; {:deleted-at (dt/now)}
;; {:id id})
;; nil)))
;; --- Mutation: Create Color
(declare select-file-for-update)

136
backend/src/uxbox/services/mutations/files.clj

@ -18,10 +18,7 @@
[uxbox.common.uuid :as uuid]
[uxbox.config :as cfg]
[uxbox.db :as db]
;; [uxbox.images :as images]
;; [uxbox.media :as media]
[uxbox.services.mutations :as sm]
;; [uxbox.services.mutations.images :as imgs]
[uxbox.services.mutations.projects :as proj]
[uxbox.services.queries.files :as files]
[uxbox.tasks :as tasks]
@ -152,136 +149,3 @@
{:id id})
nil)
;; ;; --- Mutations: Create File Image (Upload and create from url)
;;
;; (declare create-file-image)
;;
;; (s/def ::file-id ::us/uuid)
;; (s/def ::image-id ::us/uuid)
;; (s/def ::content ::imgs/upload)
;;
;; (s/def ::add-file-image-from-url
;; (s/keys :req-un [::profile-id ::file-id ::url]
;; :opt-un [::id]))
;;
;; (s/def ::upload-file-image
;; (s/keys :req-un [::profile-id ::file-id ::name ::content]
;; :opt-un [::id]))
;;
;; (sm/defmutation ::add-file-image-from-url
;; [{:keys [profile-id file-id url] :as params}]
;; (db/with-atomic [conn db/pool]
;; (files/check-edition-permissions! conn profile-id file-id)
;; (let [content (images/download-image url)
;; params' (merge params {:content content
;; :name (:filename content)})]
;; (create-file-image conn params'))))
;;
;; (sm/defmutation ::upload-file-image
;; [{:keys [profile-id file-id] :as params}]
;; (db/with-atomic [conn db/pool]
;; (files/check-edition-permissions! conn profile-id file-id)
;; (create-file-image conn params)))
;;
;; (defn- create-file-image
;; [conn {:keys [content file-id name] :as params}]
;; (when-not (imgs/valid-image-types? (:content-type content))
;; (ex/raise :type :validation
;; :code :media-type-not-allowed
;; :hint "Seems like you are uploading an invalid image."))
;;
;; (let [info (images/run {:cmd :info :input {:path (:tempfile content)
;; :mtype (:content-type content)}})
;; path (imgs/persist-image-on-fs content)
;; opts (assoc imgs/thumbnail-options
;; :input {:mtype (:mtype info)
;; :path path})
;; thumb (if-not (= (:mtype info) "image/svg+xml")
;; (imgs/persist-image-thumbnail-on-fs opts)
;; (assoc info
;; :path path
;; :quality 0))]
;;
;; (-> (db/insert! conn :file-image
;; {:file-id file-id
;; :name name
;; :path (str path)
;; :width (:width info)
;; :height (:height info)
;; :mtype (:mtype info)
;; :thumb-path (str (:path thumb))
;; :thumb-width (:width thumb)
;; :thumb-height (:height thumb)
;; :thumb-quality (:quality thumb)
;; :thumb-mtype (:mtype thumb)})
;; (images/resolve-urls :path :uri)
;; (images/resolve-urls :thumb-path :thumb-uri))))
;;
;;
;; ;; --- Mutation: Delete File Image
;;
;; (declare mark-file-image-deleted)
;;
;; (s/def ::delete-file-image
;; (s/keys :req-un [::file-id ::image-id ::profile-id]))
;;
;; (sm/defmutation ::delete-file-image
;; [{:keys [file-id image-id profile-id] :as params}]
;; (db/with-atomic [conn db/pool]
;; (files/check-edition-permissions! conn profile-id file-id)
;;
;; ;; Schedule object deletion
;; (tasks/submit! conn {:name "delete-object"
;; :delay cfg/default-deletion-delay
;; :props {:id image-id :type :file-image}})
;;
;; (mark-file-image-deleted conn params)))
;;
;; (defn mark-file-image-deleted
;; [conn {:keys [image-id] :as params}]
;; (db/update! conn :file-image
;; {:deleted-at (dt/now)}
;; {:id image-id})
;; nil)
;;
;;
;; ;; --- Mutation: Import from collection
;;
;; (declare copy-image)
;; (declare import-image-to-file)
;;
;; (s/def ::import-image-to-file
;; (s/keys :req-un [::image-id ::file-id ::profile-id]))
;;
;; (sm/defmutation ::import-image-to-file
;; [{:keys [image-id file-id profile-id] :as params}]
;; (db/with-atomic [conn db/pool]
;; (files/check-edition-permissions! conn profile-id file-id)
;; (import-image-to-file conn params)))
;;
;; (defn- import-image-to-file
;; [conn {:keys [image-id file-id] :as params}]
;; (let [image (db/get-by-id conn :image image-id)
;; image-path (copy-image (:path image))
;; thumb-path (copy-image (:thumb-path image))]
;;
;; (-> (db/insert! conn :file-image
;; {:file-id file-id
;; :name (:name image)
;; :path (str image-path)
;; :width (:width image)
;; :height (:height image)
;; :mtype (:mtype image)
;; :thumb-path (str thumb-path)
;; :thumb-width (:thumb-width image)
;; :thumb-height (:thumb-height image)
;; :thumb-quality (:thumb-quality image)
;; :thumb-mtype (:thumb-mtype image)})
;; (images/resolve-urls :path :uri)
;; (images/resolve-urls :thumb-path :thumb-uri))))
;;
;; (defn- copy-image
;; [path]
;; (let [image-path (ust/lookup media/media-storage path)]
;; (ust/save! media/media-storage (fs/name image-path) image-path)))

206
backend/src/uxbox/services/mutations/icons.clj

@ -1,206 +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/.
;;
;; This Source Code Form is "Incompatible With Secondary Licenses", as
;; defined by the Mozilla Public License, v. 2.0.
;;
;; Copyright (c) 2019-2020 Andrey Antukh <niwi@niwi.nz>
;; (ns uxbox.services.mutations.icons
;; (:require
;; [clojure.spec.alpha :as s]
;; [uxbox.common.exceptions :as ex]
;; [uxbox.common.spec :as us]
;; [uxbox.common.uuid :as uuid]
;; [uxbox.config :as cfg]
;; [uxbox.db :as db]
;; [uxbox.services.mutations :as sm]
;; [uxbox.services.queries.icons :refer [decode-row]]
;; [uxbox.services.queries.teams :as teams]
;; [uxbox.tasks :as tasks]
;; [uxbox.util.blob :as blob]
;; [uxbox.util.time :as dt]))
;;
;; ;; --- Helpers & Specs
;;
;; (s/def ::height ::us/integer)
;; (s/def ::id ::us/uuid)
;; (s/def ::library-id ::us/uuid)
;; (s/def ::name ::us/string)
;; (s/def ::profile-id ::us/uuid)
;; (s/def ::team-id ::us/uuid)
;; (s/def ::width ::us/integer)
;;
;; (s/def ::view-box
;; (s/and (s/coll-of number?)
;; #(= 4 (count %))
;; vector?))
;;
;; (s/def ::content ::us/string)
;; (s/def ::mimetype ::us/string)
;;
;; (s/def ::metadata
;; (s/keys :opt-un [::width ::height ::view-box ::mimetype]))
;;
;;
;; ;; --- Mutation: Create Library
;;
;; (declare create-library)
;;
;; (s/def ::create-icon-library
;; (s/keys :req-un [::profile-id ::team-id ::name]
;; :opt-un [::id]))
;;
;; (sm/defmutation ::create-icon-library
;; [{:keys [profile-id team-id id name] :as params}]
;; (db/with-atomic [conn db/pool]
;; (teams/check-edition-permissions! conn profile-id team-id)
;; (create-library conn params)))
;;
;; (def ^:private sql:create-library
;; "insert into icon_library (id, team_id, name)
;; values ($1, $2, $3)
;; returning *;")
;;
;; (defn create-library
;; [conn {:keys [team-id id name] :as params}]
;; (let [id (or id (uuid/next))]
;; (db/insert! conn :icon-library
;; {:id id
;; :team-id team-id
;; :name name})))
;;
;;
;; ;; --- Mutation: Rename Library
;;
;; (declare select-library-for-update)
;; (declare rename-library)
;;
;; (s/def ::rename-icon-library
;; (s/keys :req-un [::profile-id ::name ::id]))
;;
;; (sm/defmutation ::rename-icon-library
;; [{:keys [id profile-id name] :as params}]
;; (db/with-atomic [conn db/pool]
;; (let [lib (select-library-for-update conn id)]
;; (teams/check-edition-permissions! conn profile-id (:team-id lib))
;; (rename-library conn id name))))
;;
;; (defn- select-library-for-update
;; [conn id]
;; (db/get-by-id conn :icon-library id {:for-update true}))
;;
;; (defn- rename-library
;; [conn id name]
;; (db/update! conn :icon-library
;; {:name name}
;; {:id id}))
;;
;; ;; --- Mutation: Delete Library
;;
;; (declare delete-library)
;;
;; (s/def ::delete-icon-library
;; (s/keys :req-un [::profile-id ::id]))
;;
;; (sm/defmutation ::delete-icon-library
;; [{:keys [profile-id id] :as params}]
;; (db/with-atomic [conn db/pool]
;; (let [lib (select-library-for-update conn id)]
;; (teams/check-edition-permissions! conn profile-id (:team-id lib))
;;
;; ;; Schedule object deletion
;; (tasks/submit! conn {:name "delete-object"
;; :delay cfg/default-deletion-delay
;; :props {:id id :type :icon-library}})
;;
;; (db/update! conn :icon-library
;; {:deleted-at (dt/now)}
;; {:id id})
;; nil)))
;;
;;
;; ;; --- Mutation: Create Icon (Upload)
;;
;; (declare create-icon)
;;
;; (s/def ::create-icon
;; (s/keys :req-un [::profile-id ::name ::metadata ::content ::library-id]
;; :opt-un [::id]))
;;
;; (sm/defmutation ::create-icon
;; [{:keys [profile-id library-id] :as params}]
;; (db/with-atomic [conn db/pool]
;; (let [lib (select-library-for-update conn library-id)]
;; (teams/check-edition-permissions! conn profile-id (:team-id lib))
;; (create-icon conn params))))
;;
;; (defn create-icon
;; [conn {:keys [id name library-id metadata content]}]
;; (let [id (or id (uuid/next))]
;; (-> (db/insert! conn :icon
;; {:id id
;; :name name
;; :library-id library-id
;; :content content
;; :metadata (blob/encode metadata)})
;; (decode-row))))
;;
;;
;; ;; --- Mutation: Rename Icon
;;
;; (declare select-icon-for-update)
;; (declare rename-icon)
;;
;; (s/def ::rename-icon
;; (s/keys :req-un [::id ::profile-id ::name]))
;;
;; (sm/defmutation ::rename-icon
;; [{:keys [id profile-id name] :as params}]
;; (db/with-atomic [conn db/pool]
;; (let [icon (select-icon-for-update conn id)]
;; (teams/check-edition-permissions! conn profile-id (:team-id icon))
;; (db/update! conn :icon
;; {:name name}
;; {:id id}))))
;;
;; (def ^:private
;; sql:select-icon-for-update
;; "select i.*,
;; lib.team_id as team_id
;; from icon as i
;; inner join icon_library as lib on (lib.id = i.library_id)
;; where i.id = ?
;; for update")
;;
;; (defn- select-icon-for-update
;; [conn id]
;; (let [row (db/exec-one! conn [sql:select-icon-for-update id])]
;; (when-not row
;; (ex/raise :type :not-found))
;; row))
;;
;;
;; ;; --- Mutation: Delete Icon
;;
;; (declare delete-icon)
;;
;; (s/def ::delete-icon
;; (s/keys :req-un [::profile-id ::id]))
;;
;; (sm/defmutation ::delete-icon
;; [{:keys [id profile-id] :as params}]
;; (db/with-atomic [conn db/pool]
;; (let [icn (select-icon-for-update conn id)]
;; (teams/check-edition-permissions! conn profile-id (:team-id icn))
;;
;; ;; Schedule object deletion
;; (tasks/submit! conn {:name "delete-object"
;; :delay cfg/default-deletion-delay
;; :props {:id id :type :icon}})
;;
;; (db/update! conn :icon
;; {:deleted-at (dt/now)}
;; {:id id})
;; nil)))

61
backend/src/uxbox/services/mutations/media.clj

@ -37,67 +37,6 @@
(s/def ::team-id ::us/uuid)
(s/def ::url ::us/url)
;; ;; --- Create Library
;;
;; (declare create-library)
;;
;; (s/def ::create-media-object-library
;; (s/keys :req-un [::profile-id ::team-id ::name]
;; :opt-un [::id]))
;;
;; (sm/defmutation ::create-media-object-library
;; [{:keys [profile-id team-id] :as params}]
;; (db/with-atomic [conn db/pool]
;; (teams/check-edition-permissions! conn profile-id team-id)
;; (create-library conn params)))
;;
;; (defn create-library
;; [conn {:keys [id team-id name]}]
;; (let [id (or id (uuid/next))]
;; (db/insert! conn :media-object-library
;; {:id id
;; :team-id team-id
;; :name name})))
;;
;;
;; ;; --- Rename Library
;;
;; (s/def ::rename-media-object-library
;; (s/keys :req-un [::id ::profile-id ::name]))
;;
;; (sm/defmutation ::rename-media-object-library
;; [{:keys [profile-id id name] :as params}]
;; (db/with-atomic [conn db/pool]
;; (let [lib (select-file-for-update conn id)]
;; (teams/check-edition-permissions! conn profile-id (:team-id lib))
;; (db/update! conn :media-object-library
;; {:name name}
;; {:id id}))))
;;
;;
;; ;; --- Delete Library
;;
;; (declare delete-library)
;;
;; (s/def ::delete-media-object-library
;; (s/keys :req-un [::profile-id ::id]))
;;
;; (sm/defmutation ::delete-media-object-library
;; [{:keys [id profile-id] :as params}]
;; (db/with-atomic [conn db/pool]
;; (let [lib (select-file-for-update conn id)]
;; (teams/check-edition-permissions! conn profile-id (:team-id lib))
;;
;; ;; Schedule object deletion
;; (tasks/submit! conn {:name "delete-object"
;; :delay cfg/default-deletion-delay
;; :props {:id id :type :media-object-library}})
;;
;; (db/update! conn :media-object-library
;; {:deleted-at (dt/now)}
;; {:id id})
;; nil)))
;; --- Create Media object (Upload and create from url)

48
backend/src/uxbox/services/queries/colors.clj

@ -27,55 +27,7 @@
(s/def ::profile-id ::us/uuid)
(s/def ::team-id ::us/uuid)
(s/def ::file-id ::us/uuid)
;; (s/def ::library-id (s/nilable ::us/uuid))
;; ;; --- Query: Colors Libraries
;;
;; (def ^:private sql:libraries
;; "select lib.*,
;; (select count(*) from color where library_id = lib.id) as num_colors
;; from color_library as lib
;; where lib.team_id = ?
;; and lib.deleted_at is null
;; order by lib.created_at desc")
;;
;; (s/def ::color-libraries
;; (s/keys :req-un [::profile-id ::team-id]))
;;
;; (sq/defquery ::color-libraries
;; [{:keys [profile-id team-id]}]
;; (db/with-atomic [conn db/pool]
;; (teams/check-read-permissions! conn profile-id team-id)
;; (db/exec! conn [sql:libraries team-id])))
;;
;;
;; ;; --- Query: Color Library
;;
;; (declare retrieve-library)
;;
;; (s/def ::color-library
;; (s/keys :req-un [::profile-id ::id]))
;;
;; (sq/defquery ::color-library
;; [{:keys [profile-id id]}]
;; (db/with-atomic [conn db/pool]
;; (let [lib (retrieve-library conn id)]
;; (teams/check-read-permissions! conn profile-id (:team-id lib))
;; lib)))
;;
;; (def ^:private sql:single-library
;; "select lib.*,
;; (select count(*) from color where library_id = lib.id) as num_colors
;; from color_library as lib
;; where lib.deleted_at is null
;; and lib.id = ?")
;;
;; (defn- retrieve-library
;; [conn id]
;; (let [row (db/exec-one! conn [sql:single-library id])]
;; (when-not row
;; (ex/raise :type :not-found))
;; row))
;; --- Query: Colors (by file)

28
backend/src/uxbox/services/queries/files.clj

@ -173,6 +173,7 @@
(->> (db/exec! db/pool [sql:shared-files])
(mapv decode-row)))
;; --- Query: File Permissions
(def ^:private sql:file-permissions
@ -220,32 +221,6 @@
(ex/raise :type :validation
:code :not-authorized))))
;; ;; --- Query: Images of the File
;;
;; (declare retrieve-file-images)
;;
;; (s/def ::file-images
;; (s/keys :req-un [::profile-id ::file-id]))
;;
;; (sq/defquery ::file-images
;; [{:keys [profile-id file-id] :as params}]
;; (db/with-atomic [conn db/pool]
;; (check-edition-permissions! conn profile-id file-id)
;; (retrieve-file-images conn params)))
;;
;; (def ^:private sql:file-images
;; "select fi.*
;; from file_image as fi
;; where fi.file_id = ?
;; and fi.deleted_at is null")
;;
;; (defn retrieve-file-images
;; [conn {:keys [file-id] :as params}]
;; (let [sqlv [sql:file-images file-id]
;; xf (comp (map #(media/resolve-urls % :path :uri))
;; (map #(media/resolve-urls % :thumb-path :thumb-uri)))]
;; (->> (db/exec! conn sqlv)
;; (into [] xf))))
;; --- Query: File (By ID)
@ -304,6 +279,7 @@
(check-edition-permissions! conn profile-id id)
(retrieve-file conn id)))
;; --- Helpers
(defn decode-row

148
backend/src/uxbox/services/queries/icons.clj

@ -1,148 +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/.
;; ;;
;; ;; This Source Code Form is "Incompatible With Secondary Licenses", as
;; ;; defined by the Mozilla Public License, v. 2.0.
;; ;;
;; ;; Copyright (c) 2019 Andrey Antukh <niwi@niwi.nz>
;;
;; (ns uxbox.services.queries.icons
;; (:require
;; [clojure.spec.alpha :as s]
;; [uxbox.common.exceptions :as ex]
;; [uxbox.common.spec :as us]
;; [uxbox.common.uuid :as uuid]
;; [uxbox.db :as db]
;; [uxbox.images :as images]
;; [uxbox.media :as media]
;; [uxbox.services.queries :as sq]
;; [uxbox.services.queries.teams :as teams]
;; [uxbox.util.blob :as blob]
;; [uxbox.util.data :as data]))
;;
;; ;; --- Helpers & Specs
;;
;; (s/def ::id ::us/uuid)
;; (s/def ::name ::us/string)
;; (s/def ::profile-id ::us/uuid)
;; (s/def ::library-id ::us/uuid)
;; (s/def ::team-id ::us/uuid)
;;
;; (defn decode-row
;; [{:keys [metadata] :as row}]
;; (when row
;; (cond-> row
;; metadata (assoc :metadata (blob/decode metadata)))))
;;
;; ;; --- Query: Icons Librarys
;;
;; (def ^:private sql:libraries
;; "select lib.*,
;; (select count(*) from icon where library_id = lib.id) as num_icons
;; from icon_library as lib
;; where lib.team_id = ?
;; and lib.deleted_at is null
;; order by lib.created_at desc")
;;
;; (s/def ::icon-libraries
;; (s/keys :req-un [::profile-id ::team-id]))
;;
;; (sq/defquery ::icon-libraries
;; [{:keys [profile-id team-id]}]
;; (db/with-atomic [conn db/pool]
;; (teams/check-read-permissions! conn profile-id team-id)
;; (db/exec! conn [sql:libraries team-id])))
;;
;;
;;
;; ;; --- Query: Icon Library
;;
;; (declare retrieve-library)
;;
;; (s/def ::icon-library
;; (s/keys :req-un [::profile-id ::id]))
;;
;; (sq/defquery ::icon-library
;; [{:keys [profile-id id]}]
;; (db/with-atomic [conn db/pool]
;; (let [lib (retrieve-library conn id)]
;; (teams/check-read-permissions! conn profile-id (:team-id lib))
;; lib)))
;;
;; (def ^:private sql:single-library
;; "select lib.*,
;; (select count(*) from icon where library_id = lib.id) as num_icons
;; from icon_library as lib
;; where lib.deleted_at is null
;; and lib.id = ?")
;;
;; (defn- retrieve-library
;; [conn id]
;; (let [row (db/exec-one! conn [sql:single-library id])]
;; (when-not row
;; (ex/raise :type :not-found))
;; row))
;;
;;
;;
;; ;; --- Query: Icons (by library)
;;
;; (declare retrieve-icons)
;;
;; (s/def ::icons
;; (s/keys :req-un [::profile-id ::library-id]))
;;
;; (sq/defquery ::icons
;; [{:keys [profile-id library-id] :as params}]
;; (db/with-atomic [conn db/pool]
;; (let [lib (retrieve-library conn library-id)]
;; (teams/check-read-permissions! conn profile-id (:team-id lib))
;; (->> (retrieve-icons conn library-id)
;; (mapv decode-row)))))
;;
;; (def ^:private sql:icons
;; "select icon.*
;; from icon as icon
;; inner join icon_library as lib on (lib.id = icon.library_id)
;; where icon.deleted_at is null
;; and icon.library_id = ?
;; order by created_at desc")
;;
;; (defn- retrieve-icons
;; [conn library-id]
;; (db/exec! conn [sql:icons library-id]))
;;
;;
;;
;; ;; --- Query: Icon (by ID)
;;
;; (declare retrieve-icon)
;;
;; (s/def ::id ::us/uuid)
;; (s/def ::icon
;; (s/keys :req-un [::profile-id ::id]))
;;
;; (sq/defquery ::icon
;; [{:keys [profile-id id] :as params}]
;; (db/with-atomic [conn db/pool]
;; (let [icon (retrieve-icon conn id)]
;; (teams/check-read-permissions! conn profile-id (:team-id icon))
;; (decode-row icon))))
;;
;; (def ^:private sql:single-icon
;; "select icon.*,
;; lib.team_id as team_id
;; from icon as icon
;; inner join icon_library as lib on (lib.id = icon.library_id)
;; where icon.deleted_at is null
;; and icon.id = ?
;; order by created_at desc")
;;
;; (defn retrieve-icon
;; [conn id]
;; (let [row (db/exec-one! conn [sql:single-icon id])]
;; (when-not row
;; (ex/raise :type :not-found))
;; row))
;;

48
backend/src/uxbox/services/queries/media.clj

@ -23,54 +23,6 @@
(s/def ::team-id ::us/uuid)
(s/def ::file-id ::us/uuid)
;; ;; --- Query: Media Libraries
;;
;; (def ^:private sql:libraries
;; "select lib.*,
;; (select count(*) from media where library_id = lib.id) as num_media
;; from media_library as lib
;; where lib.team_id = ?
;; and lib.deleted_at is null
;; order by lib.created_at desc")
;;
;; (s/def ::media-libraries
;; (s/keys :req-un [::profile-id ::team-id]))
;;
;; (sq/defquery ::media-libraries
;; [{:keys [profile-id team-id]}]
;; (db/with-atomic [conn db/pool]
;; (teams/check-read-permissions! conn profile-id team-id)
;; (db/exec! conn [sql:libraries team-id])))
;;
;;
;; ;; --- Query: Media Library
;;
;; (declare retrieve-library)
;;
;; (s/def ::media-library
;; (s/keys :req-un [::profile-id ::id]))
;;
;; (sq/defquery ::media-library
;; [{:keys [profile-id id]}]
;; (db/with-atomic [conn db/pool]
;; (let [lib (retrieve-library conn id)]
;; (teams/check-read-permissions! conn profile-id (:team-id lib))
;; lib)))
;;
;; (def ^:private sql:single-library
;; "select lib.*,
;; (select count(*) from media where library_id = lib.id) as num_media
;; from media_library as lib
;; where lib.deleted_at is null
;; and lib.id = ?")
;;
;; (defn- retrieve-library
;; [conn id]
;; (let [row (db/exec-one! conn [sql:single-library id])]
;; (when-not row
;; (ex/raise :type :not-found))
;; row))
;; --- Query: Media objects (by file)

17
backend/tests/uxbox/tests/helpers.clj

@ -120,23 +120,6 @@
:ordering i
:data cp/default-page-data}))
;; (defn create-image-library
;; [conn team-id i]
;; (#'images/create-library conn {:id (mk-uuid "imgcoll" i)
;; :team-id team-id
;; :name (str "image library " i)}))
;;
;; (defn create-icon-library
;; [conn team-id i]
;; (#'icons/create-library conn {:id (mk-uuid "imgcoll" i)
;; :team-id team-id
;; :name (str "icon library " i)}))
;; (defn create-color-library
;; [conn team-id i]
;; (#'colors/create-library conn {:id (mk-uuid "imgcoll" i)
;; :team-id team-id
;; :name (str "color library " i)}))
(defn handle-error
[^Throwable err]
(if (instance? java.util.concurrent.ExecutionException err)

61
backend/tests/uxbox/tests/test_services_colors.clj

@ -22,65 +22,6 @@
(t/use-fixtures :once th/state-init)
(t/use-fixtures :each th/database-reset)
;; (t/deftest color-libraries-crud
;; (let [id (uuid/next)
;; prof (th/create-profile db/pool 2)
;; team-id (:default-team-id prof)
;; proj (th/create-project db/pool (:id prof) team-id 2)]
;;
;; (t/testing "create library file"
;; (let [data {::sm/type :create-file
;; :profile-id (:id prof)
;; :name "sample library"
;; :project-id (:id proj)
;; :id id
;; :is-shared true}
;; out (th/try-on! (sm/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;;
;; (let [result (:result out)]
;; (t/is (= id (:id result)))
;; (t/is (= (:id proj) (:project-id result)))
;; (t/is (= (:name data) (:name result))))))
;;
;; (t/testing "update library file"
;; (let [data {::sm/type :rename-color-library
;; :name "renamed"
;; :profile-id (:id prof)
;; :id id}
;; out (th/try-on! (sm/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;;
;; (let [result (:result out)]
;; (t/is (= "renamed" (get-in result [:name]))))))
;;
;; (t/testing "delete library"
;; (let [data {::sm/type :delete-color-library
;; :profile-id (:id prof)
;; :id id}
;;
;; out (th/try-on! (sm/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;; (t/is (nil? (:result out)))))
;;
;; (t/testing "query libraries after delete"
;; (let [data {::sq/type :color-libraries
;; :profile-id (:id prof)
;; :team-id team-id}
;; out (th/try-on! (sq/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;; (let [result (:result out)]
;; (t/is (= 0 (count result))))))
;; ))
(t/deftest colors-crud
(let [prof (th/create-profile db/pool 1)
team-id (:default-team-id prof)
@ -88,7 +29,7 @@
file (th/create-file db/pool (:id prof) (:id proj) true 1)
color-id (uuid/next)]
(t/testing "upload color to library"
(t/testing "upload color to library file"
(let [data {::sm/type :create-color
:id color-id
:profile-id (:id prof)

101
backend/tests/uxbox/tests/test_services_files.clj

@ -129,105 +129,4 @@
(t/is (= 0 (count result))))))
))
;; (t/deftest file-images-crud
;; (let [prof (th/create-profile db/pool 1)
;; team-id (:default-team-id prof)
;; proj-id (:default-project-id prof)
;; file (th/create-file db/pool (:id prof) proj-id 1)]
;;
;; (t/testing "create file image from url"
;; (let [url "https://raw.githubusercontent.com/uxbox/uxbox/develop/frontend/resources/images/penpot-login.jpg"
;; data {::sm/type :add-file-image-from-url
;; :profile-id (:id prof)
;; :file-id (:id file)
;; :url url}
;; out (th/try-on! (sm/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;;
;; (let [result (:result out)]
;; (t/is (= (:id file) (:file-id result)))
;; (t/is (not (nil? (:name result))))
;; (t/is (= 787 (:width result)))
;; (t/is (= 2000 (:height result)))
;; (t/is (= "image/jpeg" (:mtype result)))
;;
;; (t/is (string? (:path result)))
;; (t/is (string? (:uri result)))
;; (t/is (string? (:thumb-path result)))
;; (t/is (string? (:thumb-uri result))))))
;;
;; (t/testing "upload file image"
;; (let [content {:filename "sample.jpg"
;; :tempfile (th/tempfile "uxbox/tests/_files/sample.jpg")
;; :content-type "image/jpeg"
;; :size 312043}
;; data {::sm/type :upload-file-image
;; :profile-id (:id prof)
;; :file-id (:id file)
;; :name "testfile"
;; :content content}
;;
;; out (th/try-on! (sm/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;;
;; (let [result (:result out)]
;; (t/is (= (:id file) (:file-id result)))
;; (t/is (= (:name data) (:name result)))
;; (t/is (= 800 (:width result)))
;; (t/is (= 800 (:height result)))
;; (t/is (= (:content-type content) (:mtype result)))
;;
;; (t/is (string? (:path result)))
;; (t/is (string? (:uri result)))
;; (t/is (string? (:thumb-path result)))
;; (t/is (string? (:thumb-uri result))))))
;;
;; ;; (t/testing "import from library"
;; ;; (let [lib (th/create-image-library db/pool team-id 1)
;; ;; image-id (uuid/next)
;; ;;
;; ;; content {:filename "sample.jpg"
;; ;; :tempfile (th/tempfile "uxbox/tests/_files/sample.jpg")
;; ;; :content-type "image/jpeg"
;; ;; :size 312043}
;; ;;
;; ;; data {::sm/type :upload-image
;; ;; :id image-id
;; ;; :profile-id (:id prof)
;; ;; :library-id (:id lib)
;; ;; :name "testfile"
;; ;; :content content}
;; ;; out1 (th/try-on! (sm/handle data))]
;; ;;
;; ;; ;; (th/print-result! out1)
;; ;; (t/is (nil? (:error out1)))
;; ;;
;; ;; (let [result (:result out1)]
;; ;; (t/is (= image-id (:id result)))
;; ;; (t/is (= "testfile" (:name result)))
;; ;; (t/is (= "image/jpeg" (:mtype result)))
;; ;; (t/is (= "image/jpeg" (:thumb-mtype result))))
;; ;;
;; ;; (let [data2 {::sm/type :import-image-to-file
;; ;; :image-id image-id
;; ;; :file-id (:id file)
;; ;; :profile-id (:id prof)}
;; ;; out2 (th/try-on! (sm/handle data2))]
;; ;;
;; ;; ;; (th/print-result! out2)
;; ;; (t/is (nil? (:error out2)))
;; ;;
;; ;; (let [result1 (:result out1)
;; ;; result2 (:result out2)]
;; ;; (t/is (not= (:path result2)
;; ;; (:path result1)))
;; ;; (t/is (not= (:thumb-path result2)
;; ;; (:thumb-path result1)))))))
;; ))
;; TODO: delete file image

180
backend/tests/uxbox/tests/test_services_icons.clj

@ -1,180 +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/.
;;
;; This Source Code Form is "Incompatible With Secondary Licenses", as
;; defined by the Mozilla Public License, v. 2.0.
;;
;; Copyright (c) 2020 UXBOX Labs SL
(ns uxbox.tests.test-services-icons
(:require
[clojure.java.io :as io]
[clojure.test :as t]
[datoteka.core :as fs]
[uxbox.common.uuid :as uuid]
[uxbox.db :as db]
[uxbox.services.mutations :as sm]
[uxbox.services.queries :as sq]
[uxbox.tests.helpers :as th]
[uxbox.util.storage :as ust]))
;; (t/use-fixtures :once th/state-init)
;; (t/use-fixtures :each th/database-reset)
;;
;; (t/deftest icon-libraries-crud
;; (let [id (uuid/next)
;; prof (th/create-profile db/pool 2)
;; team-id (:default-team-id prof)]
;;
;; (t/testing "create library"
;; (let [data {::sm/type :create-icon-library
;; :name "sample library"
;; :profile-id (:id prof)
;; :team-id team-id
;; :id id}
;; out (th/try-on! (sm/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;;
;; (let [result (:result out)]
;; (t/is (= id (:id result)))
;; (t/is (= team-id (:team-id result)))
;; (t/is (= (:name data) (:name result))))))
;;
;; (t/testing "rename library"
;; (let [data {::sm/type :rename-icon-library
;; :name "renamed"
;; :profile-id (:id prof)
;; :team-id team-id
;; :id id}
;; out (th/try-on! (sm/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;;
;; (let [result (:result out)]
;; (t/is (= id (:id result)))
;; (t/is (= "renamed" (:name result))))))
;;
;; (t/testing "query libraries"
;; (let [data {::sq/type :icon-libraries
;; :profile-id (:id prof)
;; :team-id team-id}
;; out (th/try-on! (sq/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;;
;; (let [result (:result out)]
;; (t/is (= 1 (count result)))
;; (t/is (= id (get-in result [0 :id])))
;; (t/is (= "renamed" (get-in result [0 :name]))))))
;;
;; (t/testing "delete library"
;; (let [data {::sm/type :delete-icon-library
;; :profile-id (:id prof)
;; :id id}
;;
;; out (th/try-on! (sm/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;; (t/is (nil? (:result out)))))
;;
;; (t/testing "query libraries after delete"
;; (let [data {::sq/type :icon-libraries
;; :profile-id (:id prof)
;; :team-id team-id}
;; out (th/try-on! (sq/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;;
;; (let [result (:result out)]
;; (t/is (= 0 (count result))))))
;; ))
;;
;; (t/deftest icons-crud
;; (let [prof (th/create-profile db/pool 1)
;; team-id (:default-team-id prof)
;; coll (th/create-icon-library db/pool team-id 1)
;; icon-id (uuid/next)]
;;
;; (t/testing "upload icon to library"
;; (let [data {::sm/type :create-icon
;; :id icon-id
;; :profile-id (:id prof)
;; :library-id (:id coll)
;; :name "testfile"
;; :content "<rect></rect>"
;; :metadata {:width 100
;; :height 100
;; :view-box [0 0 100 100]
;; :mimetype "text/svg"}}
;; out (th/try-on! (sm/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;;
;; (let [result (:result out)]
;; (t/is (= (:id data) (:id result)))
;; (t/is (= (:name data) (:name result)))
;; (t/is (= (:content data) (:content result))))))
;;
;; (t/testing "list icons by library"
;; (let [data {::sq/type :icons
;; :profile-id (:id prof)
;; :library-id (:id coll)}
;; out (th/try-on! (sq/handle data))]
;; ;; (th/print-result! out)
;;
;; (t/is (= icon-id (get-in out [:result 0 :id])))
;; (t/is (= "testfile" (get-in out [:result 0 :name])))))
;;
;; (t/testing "single icon"
;; (let [data {::sq/type :icon
;; :profile-id (:id prof)
;; :id icon-id}
;; out (th/try-on! (sq/handle data))]
;; ;; (th/print-result! out)
;;
;; (t/is (= icon-id (get-in out [:result :id])))
;; (t/is (= "testfile" (get-in out [:result :name])))))
;;
;; (t/testing "delete icons"
;; (let [data {::sm/type :delete-icon
;; :profile-id (:id prof)
;; :id icon-id}
;; out (th/try-on! (sm/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;; (t/is (nil? (:result out)))))
;;
;; (t/testing "query icon after delete"
;; (let [data {::sq/type :icon
;; :profile-id (:id prof)
;; :id icon-id}
;; out (th/try-on! (sq/handle data))]
;;
;; ;; (th/print-result! out)
;; (let [error (:error out)]
;; (t/is (th/ex-info? error))
;; (t/is (th/ex-of-type? error :service-error)))
;;
;; (let [error (ex-cause (:error out))]
;; (t/is (th/ex-info? error))
;; (t/is (th/ex-of-type? error :not-found)))))
;;
;; (t/testing "query icons after delete"
;; (let [data {::sq/type :icons
;; :profile-id (:id prof)
;; :library-id (:id coll)}
;; out (th/try-on! (sq/handle data))]
;;
;; ;; (th/print-result! out)
;; (let [result (:result out)]
;; (t/is (= 0 (count result))))))
;; ))

103
backend/tests/uxbox/tests/test_services_media.clj

@ -21,88 +21,6 @@
(t/use-fixtures :once th/state-init)
(t/use-fixtures :each th/database-reset)
;; (t/deftest image-libraries-crud
;; (let [id (uuid/next)
;; prof (th/create-profile db/pool 2)
;; team-id (:default-team-id prof)]
;;
;; (t/testing "create library"
;; (let [data {::sm/type :create-image-library
;; :name "sample library"
;; :profile-id (:id prof)
;; :team-id team-id
;; :id id}
;; out (th/try-on! (sm/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;;
;; (let [result (:result out)]
;; (t/is (= team-id (:team-id result)))
;; (t/is (= (:name data) (:name result))))))
;;
;; (t/testing "rename library"
;; (let [data {::sm/type :rename-image-library
;; :name "renamed"
;; :profile-id (:id prof)
;; :id id}
;; out (th/try-on! (sm/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;;
;; (let [result (:result out)]
;; (t/is (= id (:id result)))
;; (t/is (= "renamed" (:name result))))))
;;
;; (t/testing "query single library"
;; (let [data {::sq/type :image-library
;; :profile-id (:id prof)
;; :id id}
;; out (th/try-on! (sq/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;;
;; (let [result (:result out)]
;; (t/is (= id (:id result)))
;; (t/is (= "renamed" (:name result))))))
;;
;; (t/testing "query libraries"
;; (let [data {::sq/type :image-libraries
;; :team-id team-id
;; :profile-id (:id prof)}
;; out (th/try-on! (sq/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;;
;; (let [result (:result out)]
;; (t/is (= 1 (count result)))
;; (t/is (= id (get-in result [0 :id]))))))
;;
;; (t/testing "delete library"
;; (let [data {::sm/type :delete-image-library
;; :profile-id (:id prof)
;; :id id}
;;
;; out (th/try-on! (sm/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;; (t/is (nil? (:result out)))))
;;
;; (t/testing "query libraries after delete"
;; (let [data {::sq/type :image-libraries
;; :profile-id (:id prof)
;; :team-id team-id}
;; out (th/try-on! (sq/handle data))]
;;
;; ;; (th/print-result! out)
;; (t/is (nil? (:error out)))
;; (t/is (= 0 (count (:result out))))))
;; ))
(t/deftest media-crud
(let [prof (th/create-profile db/pool 1)
team-id (:default-team-id prof)
@ -127,14 +45,12 @@