From 7f27e0326dc76618fb128f62fee801bb64e85050 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 27 Jan 2026 10:30:58 +0100 Subject: [PATCH] :sparkles: Reuse basic team and profile schemas on nitrate --- backend/src/app/rpc/management/nitrate.clj | 50 ++++++---------------- common/src/app/common/types/team.cljc | 7 +++ 2 files changed, 21 insertions(+), 36 deletions(-) diff --git a/backend/src/app/rpc/management/nitrate.clj b/backend/src/app/rpc/management/nitrate.clj index 86ef1db999..3f1ff0c6ab 100644 --- a/backend/src/app/rpc/management/nitrate.clj +++ b/backend/src/app/rpc/management/nitrate.clj @@ -5,13 +5,12 @@ ;; Copyright (c) KALEIDOS INC (ns app.rpc.management.nitrate - "Internal Nitrate HTTP API. - Provides authenticated access to organization management and token validation endpoints. - All requests must include a valid shared key token in the `x-shared-key` header, and - a cookie `auth-token` with the user token. - They will return `401 Unauthorized` if the shared key or user token are invalid." + "Internal Nitrate HTTP RPC API. Provides authenticated access to + organization management and token validation endpoints." (:require [app.common.schema :as sm] + [app.common.types.profile :refer [schema:profile]] + [app.common.types.team :refer [schema:team]] [app.common.uuid :as uuid] [app.config :as cf] [app.db :as db] @@ -23,22 +22,13 @@ [app.util.services :as sv])) ;; ---- API: authenticate -(def ^:private schema:profile - [:map - [:id ::sm/uuid] - [:name :string] - [:email :string] - [:photo-url :string]]) (sv/defmethod ::authenticate - "Authenticate an user - @api GET /authenticate - @returns - 200 OK: Returns the authenticated user." - {::doc/added "2.12" + "Authenticate the current user" + {::doc/added "2.14" ::sm/result schema:profile} [cfg {:keys [::rpc/profile-id] :as params}] - (let [profile (profile/get-profile cfg profile-id)] + (let [profile (profile/get-profile cfg profile-id)] {:id (get profile :id) :name (get profile :fullname) :email (get profile :email) @@ -51,24 +41,16 @@ FROM team AS t JOIN team_profile_rel AS tpr ON t.id = tpr.team_id WHERE tpr.profile_id = ? - AND tpr.is_owner = 't' - AND t.is_default = 'f' - AND t.deleted_at is null;") - -(def ^:private schema:team - [:map - [:id ::sm/uuid] - [:name :string]]) + AND tpr.is_owner IS TRUE + AND t.is_default IS FALSE + AND t.deleted_at IS NULL;") (def ^:private schema:get-teams-result [:vector schema:team]) (sv/defmethod ::get-teams - "List teams for which current user is owner. - @api GET /get-teams - @returns - 200 OK: Returns the list of teams for the user." - {::doc/added "2.12" + "List teams for which current user is owner" + {::doc/added "2.14" ::sm/result schema:get-teams-result} [cfg {:keys [::rpc/profile-id]}] (when (contains? cf/flags :nitrate) @@ -83,13 +65,9 @@ [:id ::sm/uuid] [:organization-id ::sm/text]]) - (sv/defmethod ::notify-team-change - "Notify to Penpot a team change from nitrate - @api POST /notify-team-change - @returns - 200 OK" - {::doc/added "2.12" + "Notify to Penpot a team change from nitrate" + {::doc/added "2.14" ::sm/params schema:notify-team-change ::rpc/auth false} [cfg {:keys [id organization-id organization-name]}] diff --git a/common/src/app/common/types/team.cljc b/common/src/app/common/types/team.cljc index f8fe889c4f..3ff2fd0184 100644 --- a/common/src/app/common/types/team.cljc +++ b/common/src/app/common/types/team.cljc @@ -19,3 +19,10 @@ (def schema:role [::sm/one-of {:title "TeamRole"} valid-roles]) + +;; FIXME: specify more fields +(def schema:team + [:map + [:id ::sm/uuid] + [:name :string]]) +