diff --git a/backend/src/app/config.clj b/backend/src/app/config.clj index 54f568b18..4824a5d78 100644 --- a/backend/src/app/config.clj +++ b/backend/src/app/config.clj @@ -144,6 +144,8 @@ [:quotes-comments-per-file {:optional true} ::sm/int] [:quotes-snapshots-per-file {:optional true} ::sm/int] [:quotes-snapshots-per-team {:optional true} ::sm/int] + [:quotes-team-access-requests-per-team {:optional true} ::sm/int] + [:quotes-team-access-requests-per-requester {:optional true} ::sm/int] [:auth-data-cookie-domain {:optional true} :string] [:auth-token-cookie-name {:optional true} :string] diff --git a/backend/src/app/rpc/commands/teams_invitations.clj b/backend/src/app/rpc/commands/teams_invitations.clj index d8ae02d1c..f8a0dfbcf 100644 --- a/backend/src/app/rpc/commands/teams_invitations.clj +++ b/backend/src/app/rpc/commands/teams_invitations.clj @@ -532,17 +532,20 @@ team-owner (get-team-owner conn team-id) file (when (some? file-id) - (get-file-for-team-access-request cfg file-id)) + (get-file-for-team-access-request cfg file-id))] - request (upsert-team-access-request conn team-id profile-id)] - - ;; FIXME missing quotes + (-> cfg + (assoc ::quotes/profile-id profile-id) + (assoc ::quotes/team-id team-id) + (quotes/check! {::quotes/id ::quotes/team-access-requests-per-team} + {::quotes/id ::quotes/team-access-requests-per-requester})) (teams/check-profile-muted conn requester) (teams/check-email-bounce conn (:email team-owner) false) (teams/check-email-spam conn (:email team-owner) true) - (let [factory (cond + (let [request (upsert-team-access-request conn team-id profile-id) + factory (cond (and (some? file) (:is-default team) is-viewer) eml/request-file-access-yourpenpot-view @@ -565,9 +568,9 @@ :team-id team-id :file-name (:name file) :file-id file-id - :page-id (:page-id file)})) + :page-id (:page-id file)}) - (with-meta {:request request} - {::audit/props {:request 1}}))) + (with-meta {:request request} + {::audit/props {:request 1}})))) diff --git a/backend/src/app/rpc/quotes.clj b/backend/src/app/rpc/quotes.clj index d52158545..e939dbe2e 100644 --- a/backend/src/app/rpc/quotes.clj +++ b/backend/src/app/rpc/quotes.clj @@ -442,7 +442,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; QUOTE: SNAPSHOTS-PER-FILE +;; QUOTE: SNAPSHOTS-PER-TEAM ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (def ^:private schema:snapshots-per-team @@ -472,6 +472,57 @@ (assoc ::count-sql [sql:get-snapshots-per-team team-id]) (generic-check!))) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; QUOTE: TEAM-ACCESS-REQUESTS-PER-TEAM +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def ^:private schema:team-access-requests-per-team + [:map + [::profile-id ::sm/uuid] + [::team-id ::sm/uuid]]) + +(def ^:private valid-team-access-requests-per-team-quote? + (sm/lazy-validator schema:team-access-requests-per-team)) + +(def ^:private sql:get-team-access-requests-per-team + "SELECT count(*) AS total + FROM team_access_request AS tar + WHERE tar.team_id = ?") + +(defmethod check-quote ::team-access-requests-per-team + [{:keys [::profile-id ::team-id ::target] :as quote}] + (assert (valid-team-access-requests-per-team-quote? quote) "invalid quote parameters") + (-> quote + (assoc ::default (cf/get :quotes-team-access-requests-per-team Integer/MAX_VALUE)) + (assoc ::quote-sql [sql:get-quotes-2 target team-id profile-id profile-id]) + (assoc ::count-sql [sql:get-team-access-requests-per-team team-id]) + (generic-check!))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; QUOTE: TEAM-ACCESS-REQUESTS-PER-REQUESTER +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def ^:private schema:team-access-requests-per-requester + [:map + [::profile-id ::sm/uuid]]) + +(def ^:private valid-team-access-requests-per-requester-quote? + (sm/lazy-validator schema:team-access-requests-per-requester)) + +(def ^:private sql:get-team-access-requests-per-requester + "SELECT count(*) AS total + FROM team_access_request AS tar + WHERE tar.requester_id = ?") + +(defmethod check-quote ::team-access-requests-per-requester + [{:keys [::profile-id ::target] :as quote}] + (assert (valid-team-access-requests-per-requester-quote? quote) "invalid quote parameters") + (-> quote + (assoc ::default (cf/get :quotes-team-access-requests-per-requester Integer/MAX_VALUE)) + (assoc ::quote-sql [sql:get-quotes-1 target profile-id]) + (assoc ::count-sql [sql:get-team-access-requests-per-requester profile-id]) + (generic-check!))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; QUOTE: DEFAULT ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;