diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn index bd1a5d82c..5201014d5 100644 --- a/.clj-kondo/config.edn +++ b/.clj-kondo/config.edn @@ -1,10 +1,17 @@ {:lint-as {potok.core/reify clojure.core/reify promesa.core/let clojure.core/let app.db/with-atomic clojure.core/with-open} + :output + {:exclude-files ["data_readers.clj"]} + :linters {:unsorted-required-namespaces {:level :warning} + :unresolved-namespace + {:level :warning + :exclude [data_readers]} + :single-key-in {:level :warning} @@ -16,6 +23,7 @@ :unresolved-symbol {:exclude ['(app.services.mutations/defmutation) '(app.services.queries/defquery) + '(app.util.dispatcher/defservice) '(mount.core/defstate) ]}}} diff --git a/backend/src/app/cli/fixtures.clj b/backend/src/app/cli/fixtures.clj index 5e5c9f07f..9c1997581 100644 --- a/backend/src/app/cli/fixtures.clj +++ b/backend/src/app/cli/fixtures.clj @@ -10,17 +10,16 @@ (ns app.cli.fixtures "A initial fixtures." (:require - [clojure.tools.logging :as log] - [mount.core :as mount] - [buddy.hashers :as hashers] - [app.common.data :as d] [app.common.pages :as cp] [app.common.uuid :as uuid] [app.config :as cfg] [app.db :as db] [app.migrations] [app.services.mutations.profile :as profile] - [app.util.blob :as blob])) + [app.util.blob :as blob] + [buddy.hashers :as hashers] + [clojure.tools.logging :as log] + [mount.core :as mount])) (defn- mk-uuid [prefix & args] diff --git a/backend/src/app/cli/media_loader.clj b/backend/src/app/cli/media_loader.clj index e038f4eb4..946fd8880 100644 --- a/backend/src/app/cli/media_loader.clj +++ b/backend/src/app/cli/media_loader.clj @@ -5,27 +5,27 @@ ;; This Source Code Form is "Incompatible With Secondary Licenses", as ;; defined by the Mozilla Public License, v. 2.0. ;; -;; Copyright (c) 2016-2020 Andrey Antukh +;; Copyright (c) 2020 UXBOX Labs SL (ns app.cli.media-loader "Media libraries importer (command line helper)." - (:require - [clojure.tools.logging :as log] - [clojure.spec.alpha :as s] - [clojure.java.io :as io] - [mount.core :as mount] - [datoteka.core :as fs] - [app.config] + #_(:require [app.common.spec :as us] - [app.db :as db] - [app.media] - [app.media-storage] - [app.migrations] [app.common.uuid :as uuid] - [app.services.mutations.projects :as projects] + [app.config] + [app.db :as db] + [app.media-storage] + [app.media] + [app.migrations] [app.services.mutations.files :as files] - [app.services.mutations.media :as media]) - (:import + [app.services.mutations.media :as media] + [app.services.mutations.projects :as projects] + [clojure.java.io :as io] + [clojure.spec.alpha :as s] + [clojure.tools.logging :as log] + [datoteka.core :as fs] + [mount.core :as mount]) + #_(:import java.io.PushbackReader)) ;; --- Constants & Helpers diff --git a/backend/src/app/config.clj b/backend/src/app/config.clj index 9a6802d06..a590eb551 100644 --- a/backend/src/app/config.clj +++ b/backend/src/app/config.clj @@ -10,14 +10,12 @@ (ns app.config "A configuration management." (:require + [app.common.spec :as us] + [app.util.time :as dt] [clojure.spec.alpha :as s] - [clojure.tools.logging :as log] [cuerdas.core :as str] [environ.core :refer [env]] - [mount.core :refer [defstate]] - [app.common.exceptions :as ex] - [app.common.spec :as us] - [app.util.time :as dt])) + [mount.core :refer [defstate]])) (def defaults {:http-server-port 6060 diff --git a/backend/src/app/db.clj b/backend/src/app/db.clj index 74b41e858..a40318a99 100644 --- a/backend/src/app/db.clj +++ b/backend/src/app/db.clj @@ -13,19 +13,15 @@ [app.common.geom.point :as gpt] [app.config :as cfg] [app.metrics :as mtx] - [app.util.data :as data] [app.util.time :as dt] [app.util.transit :as t] [clojure.data.json :as json] [clojure.spec.alpha :as s] [clojure.string :as str] - [clojure.tools.logging :as log] - [lambdaisland.uri :refer [uri]] [mount.core :as mount :refer [defstate]] [next.jdbc :as jdbc] [next.jdbc.date-time :as jdbc-dt] [next.jdbc.optional :as jdbc-opt] - [next.jdbc.result-set :as jdbc-rs] [next.jdbc.sql :as jdbc-sql] [next.jdbc.sql.builder :as jdbc-bld]) (:import @@ -34,8 +30,8 @@ com.zaxxer.hikari.metrics.prometheus.PrometheusMetricsTrackerFactory java.sql.Connection java.sql.Savepoint - org.postgresql.jdbc.PgArray org.postgresql.geometric.PGpoint + org.postgresql.jdbc.PgArray org.postgresql.util.PGInterval org.postgresql.util.PGobject)) @@ -83,6 +79,8 @@ (jdbc-dt/read-as-instant) (HikariDataSource. dsc))) +(declare pool) + (defstate pool :start (create-pool cfg/config) :stop (.close pool)) diff --git a/backend/src/app/emails.clj b/backend/src/app/emails.clj index 5d471add0..d6408b8e4 100644 --- a/backend/src/app/emails.clj +++ b/backend/src/app/emails.clj @@ -10,14 +10,11 @@ (ns app.emails "Main api for send emails." (:require - [clojure.spec.alpha :as s] - [promesa.core :as p] - [app.config :as cfg] - [app.common.exceptions :as ex] [app.common.spec :as us] - [app.db :as db] + [app.config :as cfg] [app.tasks :as tasks] - [app.util.emails :as emails])) + [app.util.emails :as emails] + [clojure.spec.alpha :as s])) ;; --- Defaults diff --git a/backend/src/app/http.clj b/backend/src/app/http.clj index eed57f905..c263304bc 100644 --- a/backend/src/app/http.clj +++ b/backend/src/app/http.clj @@ -9,23 +9,21 @@ (ns app.http (:require - [clojure.tools.logging :as log] - [mount.core :as mount :refer [defstate]] - [reitit.ring :as rring] - [ring.adapter.jetty9 :as jetty] [app.config :as cfg] [app.http.auth :as auth] [app.http.auth.gitlab :as gitlab] [app.http.auth.google :as google] [app.http.auth.ldap :as ldap] - [app.http.debug :as debug] [app.http.errors :as errors] [app.http.handlers :as handlers] [app.http.middleware :as middleware] [app.http.session :as session] [app.http.ws :as ws] [app.metrics :as mtx] - [app.services.notifications :as usn])) + [clojure.tools.logging :as log] + [mount.core :as mount :refer [defstate]] + [reitit.ring :as rring] + [ring.adapter.jetty9 :as jetty])) (defn- create-router [] diff --git a/backend/src/app/http/auth.clj b/backend/src/app/http/auth.clj index a4113ef84..cf7f8ce73 100644 --- a/backend/src/app/http/auth.clj +++ b/backend/src/app/http/auth.clj @@ -9,20 +9,18 @@ (ns app.http.auth (:require - [app.common.exceptions :as ex] - [app.common.uuid :as uuid] [app.http.session :as session] [app.services.mutations :as sm])) (defn login-handler [req] - (let [data (:body-params req) - uagent (get-in req [:headers "user-agent"])] - (let [profile (sm/handle (assoc data ::sm/type :login)) - id (session/create (:id profile) uagent)] - {:status 200 - :cookies (session/cookies id) - :body profile}))) + (let [data (:body-params req) + uagent (get-in req [:headers "user-agent"]) + profile (sm/handle (assoc data ::sm/type :login)) + id (session/create (:id profile) uagent)] + {:status 200 + :cookies (session/cookies id) + :body profile})) (defn logout-handler [req] diff --git a/backend/src/app/http/auth/gitlab.clj b/backend/src/app/http/auth/gitlab.clj index dade85309..fd3ebcc3e 100644 --- a/backend/src/app/http/auth/gitlab.clj +++ b/backend/src/app/http/auth/gitlab.clj @@ -11,7 +11,6 @@ (:require [app.common.exceptions :as ex] [app.config :as cfg] - [app.db :as db] [app.http.session :as session] [app.services.mutations :as sm] [app.services.tokens :as tokens] @@ -21,7 +20,6 @@ [clojure.tools.logging :as log] [lambdaisland.uri :as uri])) - (def default-base-gitlab-uri "https://gitlab.com") (def scope "read_user") @@ -100,7 +98,7 @@ nil)))) (defn auth - [req] + [_req] (let [token (tokens/generate {:iss :gitlab-oauth :exp (dt/in-future "15m")}) @@ -119,7 +117,7 @@ (defn callback [req] (let [token (get-in req [:params :state]) - tdata (tokens/verify token {:iss :gitlab-oauth}) + _ (tokens/verify token {:iss :gitlab-oauth}) info (some-> (get-in req [:params :code]) (get-access-token) (get-user-info))] diff --git a/backend/src/app/http/auth/google.clj b/backend/src/app/http/auth/google.clj index 97b24a1b9..33fba3179 100644 --- a/backend/src/app/http/auth/google.clj +++ b/backend/src/app/http/auth/google.clj @@ -11,7 +11,6 @@ (:require [app.common.exceptions :as ex] [app.config :as cfg] - [app.db :as db] [app.http.session :as session] [app.services.mutations :as sm] [app.services.tokens :as tokens] @@ -84,9 +83,8 @@ nil)))) (defn auth - [req] - (let [token (tokens/generate {:iss :google-oauth - :exp (dt/in-future "15m")}) + [_req] + (let [token (tokens/generate {:iss :google-oauth :exp (dt/in-future "15m")}) params {:scope scope :access_type "offline" :include_granted_scopes true @@ -104,7 +102,7 @@ (defn callback [req] (let [token (get-in req [:params :state]) - tdata (tokens/verify token {:iss :google-oauth}) + _ (tokens/verify token {:iss :google-oauth}) info (some-> (get-in req [:params :code]) (get-access-token) (get-user-info))] diff --git a/backend/src/app/http/auth/ldap.clj b/backend/src/app/http/auth/ldap.clj index 1018eb44f..1dc61b0d4 100644 --- a/backend/src/app/http/auth/ldap.clj +++ b/backend/src/app/http/auth/ldap.clj @@ -1,18 +1,29 @@ +;; 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 app.http.auth.ldap (:require - [clj-ldap.client :as client] - [clojure.set :as set] - [mount.core :refer [defstate]] - [app.common.exceptions :as ex] - [app.config :as cfg] - [app.services.mutations :as sm] - [app.http.session :as session] - [clojure.tools.logging :as log])) - + [app.common.exceptions :as ex] + [app.config :as cfg] + [app.http.session :as session] + [app.services.mutations :as sm] + [clj-ldap.client :as client] + [clojure.set :as set] + [clojure.string] + [clojure.tools.logging :as log] + [mount.core :refer [defstate]])) (defn replace-several [s & {:as replacements}] (reduce-kv clojure.string/replace s replacements)) +(declare *ldap-pool) + (defstate *ldap-pool :start (delay (try diff --git a/backend/src/app/http/debug.clj b/backend/src/app/http/debug.clj deleted file mode 100644 index e0df75670..000000000 --- a/backend/src/app/http/debug.clj +++ /dev/null @@ -1,24 +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/. -;; -;; Copyright (c) 2019 Andrey Antukh - -(ns app.http.debug - "Debug related handlers." - (:require - [clojure.tools.logging :as log] - [promesa.core :as p] - [app.http.errors :as errors] - [app.http.session :as session] - [app.common.uuid :as uuid])) - -(defn emails-list - [req] - {:status 200 - :body "Hello world\n"}) - -(defn email - [req] - {:status 200 - :body "Hello world\n"}) diff --git a/backend/src/app/http/errors.clj b/backend/src/app/http/errors.clj index d723b28c6..36754f8c8 100644 --- a/backend/src/app/http/errors.clj +++ b/backend/src/app/http/errors.clj @@ -2,23 +2,24 @@ ;; 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/. ;; -;; Copyright (c) 2016-2019 Andrey Antukh +;; 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 app.http.errors "A errors handling for the http server." (:require [clojure.tools.logging :as log] - [cuerdas.core :as str] - [app.metrics :as mtx] - [io.aviso.exception :as e])) + [cuerdas.core :as str])) (defmulti handle-exception - (fn [err & rest] + (fn [err & _rest] (:type (ex-data err)))) (defmethod handle-exception :authorization - [err req] + [err _] {:status 403 :body (ex-data err)}) @@ -38,13 +39,13 @@ :body response}))) (defmethod handle-exception :ratelimit - [err req] + [_ _] {:status 429 :headers {"retry-after" 1000} :body ""}) (defmethod handle-exception :not-found - [err req] + [err _] (let [response (ex-data err)] {:status 404 :body response})) @@ -54,7 +55,7 @@ (handle-exception (.getCause ^Throwable err) req)) (defmethod handle-exception :parse - [err req] + [err _] {:status 400 :body {:type :parse :message (ex-message err)}}) diff --git a/backend/src/app/http/handlers.clj b/backend/src/app/http/handlers.clj index f859b7a36..3d3855175 100644 --- a/backend/src/app/http/handlers.clj +++ b/backend/src/app/http/handlers.clj @@ -9,9 +9,6 @@ (ns app.http.handlers (:require - [app.common.exceptions :as ex] - [app.emails :as emails] - [app.http.session :as session] [app.services.init] [app.services.mutations :as sm] [app.services.queries :as sq])) diff --git a/backend/src/app/http/middleware.clj b/backend/src/app/http/middleware.clj index ab02d9675..e2fafae1a 100644 --- a/backend/src/app/http/middleware.clj +++ b/backend/src/app/http/middleware.clj @@ -5,20 +5,19 @@ ;; 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 +;; Copyright (c) 2020 UXBOX Labs SL (ns app.http.middleware (:require - [clojure.tools.logging :as log] + [app.common.exceptions :as ex] + [app.config :as cfg] + [app.metrics :as mtx] + [app.util.transit :as t] [ring.middleware.cookies :refer [wrap-cookies]] [ring.middleware.keyword-params :refer [wrap-keyword-params]] [ring.middleware.multipart-params :refer [wrap-multipart-params]] [ring.middleware.params :refer [wrap-params]] - [ring.middleware.resource :refer [wrap-resource]] - [app.metrics :as mtx] - [app.common.exceptions :as ex] - [app.config :as cfg] - [app.util.transit :as t])) + [ring.middleware.resource :refer [wrap-resource]])) (defn- wrap-parse-request-body [handler] @@ -126,13 +125,13 @@ (def development-cors {:name ::development-cors - :compile (fn [& args] + :compile (fn [& _args] (when *assert* wrap-development-cors))}) (def development-resources {:name ::development-resources - :compile (fn [& args] + :compile (fn [& _args] (when *assert* #(wrap-resource % "public")))}) diff --git a/backend/src/app/http/ws.clj b/backend/src/app/http/ws.clj index c47077694..0f54a0d23 100644 --- a/backend/src/app/http/ws.clj +++ b/backend/src/app/http/ws.clj @@ -10,16 +10,14 @@ (ns app.http.ws "Web Socket handlers" (:require - [clojure.spec.alpha :as s] - [clojure.tools.logging :as log] - [ring.adapter.jetty9 :as jetty] - [ring.middleware.cookies :refer [wrap-cookies]] - [ring.middleware.keyword-params :refer [wrap-keyword-params]] - [ring.middleware.params :refer [wrap-params]] [app.common.spec :as us] [app.db :as db] [app.http.session :refer [wrap-session]] - [app.services.notifications :as nf])) + [app.services.notifications :as nf] + [clojure.spec.alpha :as s] + [ring.middleware.cookies :refer [wrap-cookies]] + [ring.middleware.keyword-params :refer [wrap-keyword-params]] + [ring.middleware.params :refer [wrap-params]])) (s/def ::file-id ::us/uuid) (s/def ::session-id ::us/uuid) diff --git a/backend/src/app/main.clj b/backend/src/app/main.clj index 454cc68bf..a782b9118 100644 --- a/backend/src/app/main.clj +++ b/backend/src/app/main.clj @@ -25,7 +25,7 @@ ;; --- Entry point (defn run - [params] + [_params] (require 'app.config 'app.srepl.server 'app.migrations @@ -37,5 +37,5 @@ (defn -main - [& args] + [& _args] (run {})) diff --git a/backend/src/app/media.clj b/backend/src/app/media.clj index dd8002e71..51b7186d3 100644 --- a/backend/src/app/media.clj +++ b/backend/src/app/media.clj @@ -10,14 +10,11 @@ (ns app.media "Media postprocessing." (:require - [app.common.data :as d] [app.common.exceptions :as ex] [app.common.media :as cm] [app.common.spec :as us] [app.config :as cfg] - [app.media-storage :as mst] [app.util.http :as http] - [app.util.storage :as ust] [clojure.core.async :as a] [clojure.java.io :as io] [clojure.spec.alpha :as s] @@ -25,11 +22,12 @@ [mount.core :refer [defstate]]) (:import java.io.ByteArrayInputStream - java.io.InputStream java.util.concurrent.Semaphore org.im4java.core.ConvertCmd - org.im4java.core.Info - org.im4java.core.IMOperation)) + org.im4java.core.IMOperation + org.im4java.core.Info)) + +(declare semaphore) (defstate semaphore :start (Semaphore. (:image-process-max-threads cfg/config 1))) @@ -73,7 +71,7 @@ ;; http://www.imagemagick.org/Usage/thumbnails/ (defn- generic-process - [{:keys [input format quality operation] :as params}] + [{:keys [input format operation] :as params}] (let [{:keys [path mtype]} input format (or (cm/mtype->format mtype) format) ext (cm/format->extension format) diff --git a/backend/src/app/media_storage.clj b/backend/src/app/media_storage.clj index 3accc3026..df763c999 100644 --- a/backend/src/app/media_storage.clj +++ b/backend/src/app/media_storage.clj @@ -5,24 +5,25 @@ ;; This Source Code Form is "Incompatible With Secondary Licenses", as ;; defined by the Mozilla Public License, v. 2.0. ;; -;; Copyright (c) 2017-2020 Andrey Antukh +;; Copyright (c) 2020 UXBOX Labs SL (ns app.media-storage "A media storage impl for app." (:require - [mount.core :refer [defstate]] - [clojure.java.io :as io] - [cuerdas.core :as str] - [datoteka.core :as fs] + [app.config :refer [config]] [app.util.storage :as ust] - [app.config :refer [config]])) + [mount.core :refer [defstate]])) ;; --- State +(declare assets-storage) + (defstate assets-storage :start (ust/create {:base-path (:assets-directory config) :base-uri (:assets-uri config)})) +(declare media-storage) + (defstate media-storage :start (ust/create {:base-path (:media-directory config) :base-uri (:media-uri config) diff --git a/backend/src/app/metrics.clj b/backend/src/app/metrics.clj index 39d08970c..4f9a30ad2 100644 --- a/backend/src/app/metrics.clj +++ b/backend/src/app/metrics.clj @@ -8,9 +8,6 @@ ;; Copyright (c) 2020 UXBOX Labs SL (ns app.metrics - (:require - [clojure.tools.logging :as log] - [cuerdas.core :as str]) (:import io.prometheus.client.CollectorRegistry io.prometheus.client.Counter @@ -172,7 +169,7 @@ (assoc mdata ::summary-original original))))))) (defn dump - [& args] + [& _args] (let [samples (.metricFamilySamples ^CollectorRegistry registry) writer (StringWriter.)] (TextFormat/write004 writer samples) diff --git a/backend/src/app/migrations.clj b/backend/src/app/migrations.clj index 6c9ebdba2..94d3aaa3a 100644 --- a/backend/src/app/migrations.clj +++ b/backend/src/app/migrations.clj @@ -9,11 +9,10 @@ (ns app.migrations (:require - [mount.core :as mount :refer [defstate]] [app.db :as db] - [app.config :as cfg] [app.migrations.migration-0023 :as mg0023] - [app.util.migrations :as mg])) + [app.util.migrations :as mg] + [mount.core :as mount :refer [defstate]])) (def +migrations+ {:name "uxbox-main" diff --git a/backend/src/app/redis.clj b/backend/src/app/redis.clj index 39345e5a1..3edb30047 100644 --- a/backend/src/app/redis.clj +++ b/backend/src/app/redis.clj @@ -7,13 +7,9 @@ (ns app.redis (:refer-clojure :exclude [run!]) (:require - [clojure.tools.logging :as log] - [lambdaisland.uri :refer [uri]] - [mount.core :as mount :refer [defstate]] - [app.common.exceptions :as ex] [app.config :as cfg] - [app.util.data :as data] - [app.util.redis :as redis]) + [app.util.redis :as redis] + [mount.core :as mount :refer [defstate]]) (:import java.lang.AutoCloseable)) @@ -24,10 +20,14 @@ (let [uri (:redis-uri config "redis://redis/0")] (redis/client uri))) +(declare client) + (defstate client :start (create-client cfg/config) :stop (.close ^AutoCloseable client)) +(declare conn) + (defstate conn :start (redis/connect client) :stop (.close ^AutoCloseable conn)) diff --git a/backend/src/app/services/middleware.clj b/backend/src/app/services/middleware.clj index 098020b75..916d791a6 100644 --- a/backend/src/app/services/middleware.clj +++ b/backend/src/app/services/middleware.clj @@ -10,13 +10,11 @@ (ns app.services.middleware "Common middleware for services." (:require - [clojure.tools.logging :as log] - [clojure.spec.alpha :as s] - [cuerdas.core :as str] - [expound.alpha :as expound] [app.common.exceptions :as ex] [app.common.spec :as us] - [app.metrics :as mtx])) + [app.metrics :as mtx] + [clojure.spec.alpha :as s] + [cuerdas.core :as str])) (defn wrap-spec [handler] @@ -45,7 +43,7 @@ (defn- get-prefix [nsname] - (let [[a b c] (str/split nsname ".")] + (let [[_ _ c] (str/split nsname ".")] c)) (defn wrap-metrics diff --git a/backend/src/app/services/mutations/comments.clj b/backend/src/app/services/mutations/comments.clj index 5838ab7c5..b30f51081 100644 --- a/backend/src/app/services/mutations/comments.clj +++ b/backend/src/app/services/mutations/comments.clj @@ -9,21 +9,15 @@ (ns app.services.mutations.comments (:require - [clojure.spec.alpha :as s] [app.common.exceptions :as ex] [app.common.spec :as us] - [app.common.uuid :as uuid] - [app.config :as cfg] [app.db :as db] [app.services.mutations :as sm] - [app.services.queries.projects :as proj] - [app.services.queries.files :as files] [app.services.queries.comments :as comments] - [app.tasks :as tasks] + [app.services.queries.files :as files] [app.util.blob :as blob] - [app.util.storage :as ust] - [app.util.transit :as t] - [app.util.time :as dt])) + [app.util.time :as dt] + [clojure.spec.alpha :as s])) ;; --- Mutation: Create Comment Thread @@ -66,14 +60,16 @@ :created-at now :modified-at now :seqn seqn - :position (db/pgpoint position)}) - ;; Create a comment entry - comment (db/insert! conn :comment - {:thread-id (:id thread) - :owner-id profile-id - :created-at now - :modified-at now - :content content})] + :position (db/pgpoint position)})] + + + ;; Create a comment entry + (db/insert! conn :comment + {:thread-id (:id thread) + :owner-id profile-id + :created-at now + :modified-at now + :content content}) ;; Make the current thread as read. (upsert-comment-thread-status! conn profile-id (:id thread)) diff --git a/backend/src/app/services/mutations/demo.clj b/backend/src/app/services/mutations/demo.clj index 839deae81..95471c13f 100644 --- a/backend/src/app/services/mutations/demo.clj +++ b/backend/src/app/services/mutations/demo.clj @@ -10,17 +10,14 @@ (ns app.services.mutations.demo "A demo specific mutations." (:require - [clojure.spec.alpha :as s] - [buddy.core.codecs :as bc] - [buddy.core.nonce :as bn] - [app.common.exceptions :as ex] + [app.common.uuid :as uuid] [app.config :as cfg] [app.db :as db] [app.services.mutations :as sm] [app.services.mutations.profile :as profile] [app.tasks :as tasks] - [app.common.uuid :as uuid] - [app.util.time :as tm])) + [buddy.core.codecs :as bc] + [buddy.core.nonce :as bn])) (sm/defmutation ::create-demo-profile [_] diff --git a/backend/src/app/services/mutations/files.clj b/backend/src/app/services/mutations/files.clj index 38d971c0e..ff1d24396 100644 --- a/backend/src/app/services/mutations/files.clj +++ b/backend/src/app/services/mutations/files.clj @@ -9,9 +9,6 @@ (ns app.services.mutations.files (:require - [clojure.spec.alpha :as s] - [datoteka.core :as fs] - [promesa.core :as p] [app.common.exceptions :as ex] [app.common.pages :as cp] [app.common.pages-migrations :as pmg] @@ -21,13 +18,13 @@ [app.db :as db] [app.redis :as redis] [app.services.mutations :as sm] - [app.services.queries.projects :as proj] [app.services.queries.files :as files] + [app.services.queries.projects :as proj] [app.tasks :as tasks] [app.util.blob :as blob] - [app.util.storage :as ust] + [app.util.time :as dt] [app.util.transit :as t] - [app.util.time :as dt])) + [clojure.spec.alpha :as s])) ;; --- Helpers & Specs @@ -62,7 +59,7 @@ :can-edit true})) (defn create-file - [conn {:keys [id profile-id name project-id is-shared] + [conn {:keys [id name project-id is-shared] :or {is-shared false} :as params}] (let [id (or id (uuid/next)) @@ -286,7 +283,7 @@ (assoc :changes (blob/encode changes) :session-id sid)) - chng (insert-change conn file) + _ (insert-change conn file) msg {:type :file-change :profile-id (:profile-id params) :file-id (:id file) @@ -319,7 +316,7 @@ :data (:data file)} {:id (:id file)}) - (retrieve-lagged-changes conn chng params))) + (retrieve-lagged-changes conn params))) (defn- insert-change [conn {:keys [revn data changes session-id] :as file}] @@ -343,7 +340,7 @@ order by s.created_at asc") (defn- retrieve-lagged-changes - [conn snapshot params] + [conn params] (->> (db/exec! conn [sql:lagged-changes (:id params) (:revn params)]) (mapv files/decode-row))) diff --git a/backend/src/app/services/mutations/media.clj b/backend/src/app/services/mutations/media.clj index 3dd65fb9b..e50e7a500 100644 --- a/backend/src/app/services/mutations/media.clj +++ b/backend/src/app/services/mutations/media.clj @@ -9,21 +9,18 @@ (ns app.services.mutations.media (:require - [clojure.spec.alpha :as s] - [datoteka.core :as fs] - [app.common.media :as cm] [app.common.exceptions :as ex] + [app.common.media :as cm] [app.common.spec :as us] [app.common.uuid :as uuid] - [app.config :as cfg] [app.db :as db] [app.media :as media] + [app.media-storage :as mst] [app.services.mutations :as sm] [app.services.queries.teams :as teams] - [app.tasks :as tasks] - [app.media-storage :as mst] [app.util.storage :as ust] - [app.util.time :as dt])) + [clojure.spec.alpha :as s] + [datoteka.core :as fs])) (def thumbnail-options {:width 100 diff --git a/backend/src/app/services/mutations/profile.clj b/backend/src/app/services/mutations/profile.clj index a2f587cac..2585ba811 100644 --- a/backend/src/app/services/mutations/profile.clj +++ b/backend/src/app/services/mutations/profile.clj @@ -10,24 +10,20 @@ (ns app.services.mutations.profile (:require [app.common.exceptions :as ex] - [app.common.media :as cm] [app.common.spec :as us] [app.common.uuid :as uuid] [app.config :as cfg] [app.db :as db] [app.emails :as emails] - [app.media :as media] - [app.media-storage :as mst] [app.http.session :as session] + [app.media :as media] [app.services.mutations :as sm] [app.services.mutations.projects :as projects] [app.services.mutations.teams :as teams] + [app.services.mutations.verify-token :refer [process-token]] [app.services.queries.profile :as profile] [app.services.tokens :as tokens] - [app.services.mutations.verify-token :refer [process-token]] [app.tasks :as tasks] - [app.util.blob :as blob] - [app.util.storage :as ust] [app.util.time :as dt] [buddy.hashers :as hashers] [clojure.spec.alpha :as s] @@ -361,7 +357,7 @@ (sm/defmutation ::request-profile-recovery [{:keys [email] :as params}] - (letfn [(create-recovery-token [conn {:keys [id] :as profile}] + (letfn [(create-recovery-token [{:keys [id] :as profile}] (let [token (tokens/generate {:iss :password-recovery :exp (dt/in-future "15m") @@ -377,7 +373,7 @@ (db/with-atomic [conn db/pool] (some->> email (profile/retrieve-profile-data-by-email conn) - (create-recovery-token conn) + (create-recovery-token) (send-email-notification conn)) nil))) @@ -390,7 +386,7 @@ (sm/defmutation ::recover-profile [{:keys [token password]}] - (letfn [(validate-token [conn token] + (letfn [(validate-token [token] (let [tdata (tokens/verify token {:iss :password-recovery})] (:profile-id tdata))) @@ -399,7 +395,7 @@ (db/update! conn :profile {:password pwd} {:id profile-id})))] (db/with-atomic [conn db/pool] - (->> (validate-token conn token) + (->> (validate-token token) (update-password conn)) nil))) diff --git a/backend/src/app/services/mutations/projects.clj b/backend/src/app/services/mutations/projects.clj index bb36b8977..211da4300 100644 --- a/backend/src/app/services/mutations/projects.clj +++ b/backend/src/app/services/mutations/projects.clj @@ -5,12 +5,10 @@ ;; 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 +;; Copyright (c) 2020 UXBOX Labs SL (ns app.services.mutations.projects (:require - [clojure.spec.alpha :as s] - [app.common.exceptions :as ex] [app.common.spec :as us] [app.common.uuid :as uuid] [app.config :as cfg] @@ -18,7 +16,7 @@ [app.services.mutations :as sm] [app.services.queries.projects :as proj] [app.tasks :as tasks] - [app.util.blob :as blob])) + [clojure.spec.alpha :as s])) ;; --- Helpers & Specs @@ -48,7 +46,7 @@ (assoc proj :is-pinned true)))) (defn create-project - [conn {:keys [id profile-id team-id name default?] :as params}] + [conn {:keys [id team-id name default?] :as params}] (let [id (or id (uuid/next)) default? (if (boolean? default?) default? false)] (db/insert! conn :project @@ -107,11 +105,10 @@ (sm/defmutation ::rename-project [{:keys [id profile-id name] :as params}] (db/with-atomic [conn db/pool] - (let [project (db/get-by-id conn :project id {:for-update true})] - (proj/check-edition-permissions! conn profile-id id) - (db/update! conn :project - {:name name} - {:id id})))) + (proj/check-edition-permissions! conn profile-id id) + (db/update! conn :project + {:name name} + {:id id}))) ;; --- Mutation: Delete Project @@ -139,6 +136,6 @@ returning id") (defn mark-project-deleted - [conn {:keys [id profile-id] :as params}] + [conn {:keys [id] :as params}] (db/exec! conn [sql:mark-project-deleted id]) nil) diff --git a/backend/src/app/services/mutations/teams.clj b/backend/src/app/services/mutations/teams.clj index 305b70275..a7ecdf09c 100644 --- a/backend/src/app/services/mutations/teams.clj +++ b/backend/src/app/services/mutations/teams.clj @@ -20,9 +20,9 @@ [app.media-storage :as mst] [app.services.mutations :as sm] [app.services.mutations.projects :as projects] + [app.services.queries.profile :as profile] [app.services.queries.teams :as teams] [app.services.tokens :as tokens] - [app.services.queries.profile :as profile] [app.tasks :as tasks] [app.util.storage :as ust] [app.util.time :as dt] @@ -58,7 +58,7 @@ team))) (defn create-team - [conn {:keys [id profile-id name default?] :as params}] + [conn {:keys [id name default?] :as params}] (let [id (or id (uuid/next)) default? (if (boolean? default?) default? false)] (db/insert! conn :team @@ -268,7 +268,7 @@ (assoc team :photo (str photo))))) (defn upload-photo - [conn {:keys [file profile-id]}] + [_conn {:keys [file]}] (let [prefix (-> (bn/random-bytes 8) (bc/bytes->b64u) (bc/bytes->str)) diff --git a/backend/src/app/services/mutations/verify_token.clj b/backend/src/app/services/mutations/verify_token.clj index 638a04879..87dda705a 100644 --- a/backend/src/app/services/mutations/verify_token.clj +++ b/backend/src/app/services/mutations/verify_token.clj @@ -10,28 +10,16 @@ (ns app.services.mutations.verify-token (:require [app.common.exceptions :as ex] - [app.common.media :as cm] [app.common.spec :as us] - [app.common.uuid :as uuid] - [app.config :as cfg] [app.db :as db] - [app.emails :as emails] [app.http.session :as session] - [app.media :as media] - [app.media-storage :as mst] [app.services.mutations :as sm] [app.services.mutations.teams :as teams] [app.services.queries.profile :as profile] [app.services.tokens :as tokens] - [app.tasks :as tasks] - [app.util.blob :as blob] - [app.util.storage :as ust] - [app.util.time :as dt] - [buddy.hashers :as hashers] - [clojure.spec.alpha :as s] - [cuerdas.core :as str])) + [clojure.spec.alpha :as s])) -(defmulti process-token (fn [conn params claims] (:iss claims))) +(defmulti process-token (fn [_ _ claims] (:iss claims))) (s/def ::verify-token (s/keys :req-un [::token] @@ -44,18 +32,17 @@ (process-token conn params claims)))) (defmethod process-token :change-email - [conn params {:keys [profile-id email] :as claims}] - (let [profile (db/get-by-id conn :profile profile-id {:for-update true})] - (when (profile/retrieve-profile-data-by-email conn email) - (ex/raise :type :validation - :code :email-already-exists)) - (db/update! conn :profile - {:email email} - {:id profile-id}) - claims)) + [conn _params {:keys [profile-id email] :as claims}] + (when (profile/retrieve-profile-data-by-email conn email) + (ex/raise :type :validation + :code :email-already-exists)) + (db/update! conn :profile + {:email email} + {:id profile-id}) + claims) (defmethod process-token :verify-email - [conn params {:keys [profile-id] :as claims}] + [conn _params {:keys [profile-id] :as claims}] (let [profile (db/get-by-id conn :profile profile-id {:for-update true})] (when (:is-active profile) (ex/raise :type :validation @@ -71,7 +58,7 @@ claims)) (defmethod process-token :auth - [conn params {:keys [profile-id] :as claims}] + [conn _params {:keys [profile-id] :as claims}] (let [profile (profile/retrieve-profile conn profile-id)] (assoc claims :profile profile))) @@ -137,7 +124,7 @@ ;; --- Default (defmethod process-token :default - [conn params claims] + [_ _ _] (ex/raise :type :validation :code :invalid-token)) diff --git a/backend/src/app/services/mutations/viewer.clj b/backend/src/app/services/mutations/viewer.clj index 71d189260..82ebb17b1 100644 --- a/backend/src/app/services/mutations/viewer.clj +++ b/backend/src/app/services/mutations/viewer.clj @@ -9,10 +9,7 @@ (ns app.services.mutations.viewer (:require - [app.common.exceptions :as ex] - [app.common.pages :as cp] [app.common.spec :as us] - [app.config :as cfg] [app.db :as db] [app.services.mutations :as sm] [app.services.queries.files :as files] diff --git a/backend/src/app/services/notifications.clj b/backend/src/app/services/notifications.clj index 3f837c982..4c2d18e23 100644 --- a/backend/src/app/services/notifications.clj +++ b/backend/src/app/services/notifications.clj @@ -10,17 +10,13 @@ (ns app.services.notifications "A websocket based notifications mechanism." (:require - [app.common.exceptions :as ex] - [app.common.uuid :as uuid] [app.db :as db] [app.metrics :as mtx] [app.redis :as redis] [app.util.async :as aa] - [app.util.time :as dt] [app.util.transit :as t] [clojure.core.async :as a] [clojure.tools.logging :as log] - [promesa.core :as p] [ring.adapter.jetty9 :as jetty])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -40,7 +36,7 @@ :help "A total number of messages handled by the notifications service."})) (defn websocket - [{:keys [file-id team-id profile-id] :as params}] + [{:keys [file-id team-id] :as params}] (let [in (a/chan 32) out (a/chan 32)] {:on-connect @@ -62,18 +58,18 @@ (a/close! sub)))) :on-error - (fn [conn e] + (fn [_conn _e] (a/close! out) (a/close! in)) :on-close - (fn [conn status-code reason] + (fn [_conn _status _reason] (metrics-active-connections :dec) (a/close! out) (a/close! in)) :on-text - (fn [ws message] + (fn [_ws message] (metrics-message-counter :inc) (let [message (t/decode-str message)] (a/>!! in message))) @@ -165,8 +161,7 @@ (defn- update-presence [file-id session-id profile-id] (aa/thread-try - (let [now (dt/now) - sql [sql:update-presence file-id session-id profile-id]] + (let [sql [sql:update-presence file-id session-id profile-id]] (db/exec-one! db/pool sql)))) (defn- delete-presence @@ -177,13 +172,13 @@ :session-id session-id}))) (defmulti handle-message - (fn [ws message] (:type message))) + (fn [_ message] (:type message))) ;; TODO: check permissions for join a file-id channel (probably using ;; single use token for avoid explicit database query). (defmethod handle-message :connect - [{:keys [file-id profile-id session-id output] :as ws} message] + [{:keys [file-id profile-id session-id] :as ws} _message] (log/debugf "profile '%s' is connected to file '%s'" profile-id file-id) (aa/go-try (aa/> (db/exec! conn [sql:comment-threads profile-id file-id]) (into [] (map decode-row)))) diff --git a/backend/src/app/services/queries/files.clj b/backend/src/app/services/queries/files.clj index 8047e37d9..73dddf076 100644 --- a/backend/src/app/services/queries/files.clj +++ b/backend/src/app/services/queries/files.clj @@ -5,20 +5,18 @@ ;; 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 +;; Copyright (c) 2020 UXBOX Labs SL (ns app.services.queries.files (:require - [clojure.spec.alpha :as s] - [promesa.core :as p] - [app.common.pages-migrations :as pmg] [app.common.exceptions :as ex] + [app.common.pages-migrations :as pmg] [app.common.spec :as us] [app.db :as db] - [app.media :as media] [app.services.queries :as sq] [app.services.queries.projects :as projects] - [app.util.blob :as blob])) + [app.util.blob :as blob] + [clojure.spec.alpha :as s])) (declare decode-row) (declare decode-row-xf) diff --git a/backend/src/app/services/queries/projects.clj b/backend/src/app/services/queries/projects.clj index 892a122b5..1b3b36997 100644 --- a/backend/src/app/services/queries/projects.clj +++ b/backend/src/app/services/queries/projects.clj @@ -9,12 +9,12 @@ (ns app.services.queries.projects (:require - [clojure.spec.alpha :as s] - [app.common.spec :as us] [app.common.exceptions :as ex] + [app.common.spec :as us] [app.db :as db] [app.services.queries :as sq] - [app.services.queries.teams :as teams])) + [app.services.queries.teams :as teams] + [clojure.spec.alpha :as s])) ;; --- Check Project Permissions diff --git a/backend/src/app/services/queries/recent_files.clj b/backend/src/app/services/queries/recent_files.clj index 159bd3025..e52fd9ee9 100644 --- a/backend/src/app/services/queries/recent_files.clj +++ b/backend/src/app/services/queries/recent_files.clj @@ -5,18 +5,16 @@ ;; 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 +;; Copyright (c) 2020 UXBOX Labs SL (ns app.services.queries.recent-files (:require - [clojure.spec.alpha :as s] - [promesa.core :as p] - [app.db :as db] [app.common.spec :as us] + [app.db :as db] [app.services.queries :as sq] + [app.services.queries.files :refer [decode-row-xf]] [app.services.queries.teams :as teams] - [app.services.queries.projects :as projects :refer [retrieve-projects]] - [app.services.queries.files :refer [decode-row-xf]])) + [clojure.spec.alpha :as s])) (def sql:recent-files "with recent_files as ( diff --git a/backend/src/app/services/queries/teams.clj b/backend/src/app/services/queries/teams.clj index e5191bca3..e3fc6b85b 100644 --- a/backend/src/app/services/queries/teams.clj +++ b/backend/src/app/services/queries/teams.clj @@ -5,18 +5,16 @@ ;; This Source Code Form is "Incompatible With Secondary Licenses", as ;; defined by the Mozilla Public License, v. 2.0. ;; -;; Copyright (c) 2020 Andrey Antukh +;; Copyright (c) 2020 UXBOX Labs SL (ns app.services.queries.teams (:require - [clojure.spec.alpha :as s] [app.common.exceptions :as ex] [app.common.spec :as us] - [app.common.uuid :as uuid] [app.db :as db] [app.services.queries :as sq] [app.services.queries.profile :as profile] - [app.util.blob :as blob])) + [clojure.spec.alpha :as s])) ;; --- Team Edition Permissions diff --git a/backend/src/app/services/tokens.clj b/backend/src/app/services/tokens.clj index 4c57a3da0..fe0967156 100644 --- a/backend/src/app/services/tokens.clj +++ b/backend/src/app/services/tokens.clj @@ -10,16 +10,11 @@ (ns app.services.tokens (:require [app.common.exceptions :as ex] - [app.common.spec :as us] [app.config :as cfg] - [app.db :as db] [app.util.time :as dt] [app.util.transit :as t] - [buddy.core.codecs :as bc] [buddy.core.kdf :as bk] - [buddy.core.nonce :as bn] [buddy.sign.jwe :as jwe] - [clojure.spec.alpha :as s] [clojure.tools.logging :as log])) (defn- derive-tokens-secret diff --git a/backend/src/app/srepl/main.clj b/backend/src/app/srepl/main.clj index 5227aba17..94f10626c 100644 --- a/backend/src/app/srepl/main.clj +++ b/backend/src/app/srepl/main.clj @@ -1,5 +1,6 @@ (ns app.srepl.main "A main namespace for server repl." + #_:clj-kondo/ignore (:require [clojure.pprint :refer [pprint]] [app.db :as db])) diff --git a/backend/src/app/srepl/server.clj b/backend/src/app/srepl/server.clj index 52a69538f..51d23050f 100644 --- a/backend/src/app/srepl/server.clj +++ b/backend/src/app/srepl/server.clj @@ -1,10 +1,18 @@ +;; 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 app.srepl.server "Server Repl." (:require - [clojure.pprint :refer [pprint]] - [clojure.main :as cm] - [clojure.core.server :as ccs] [app.srepl.main] + [clojure.core.server :as ccs] + [clojure.main :as cm] [mount.core :as mount :refer [defstate]])) (defn- repl-init diff --git a/backend/src/app/tasks.clj b/backend/src/app/tasks.clj index 02b0164d4..c074358e2 100644 --- a/backend/src/app/tasks.clj +++ b/backend/src/app/tasks.clj @@ -11,7 +11,6 @@ (:require [app.common.spec :as us] [app.common.uuid :as uuid] - [app.config :as cfg] [app.db :as db] [app.metrics :as mtx] [app.util.time :as dt] diff --git a/backend/src/app/worker.clj b/backend/src/app/worker.clj index b3bd38016..5ee7d9d18 100644 --- a/backend/src/app/worker.clj +++ b/backend/src/app/worker.clj @@ -68,8 +68,7 @@ ]) (defstate executor - :start (thread-pool {:idle-timeout 10000 - :min-threads 0 + :start (thread-pool {:min-threads 0 :max-threads 256}) :stop (stop! executor)) @@ -381,7 +380,7 @@ (defn thread-pool ([] (thread-pool {})) ([{:keys [min-threads max-threads name] - :or {min-threads 0 max-threads 128 idle-timeout 60000}}] + :or {min-threads 0 max-threads 128}}] (let [executor (QueuedThreadPool. max-threads min-threads)] (.setName executor (or name "default-tp")) (.start executor)