From c0f746ee34468e8dc1f657798787cb18ddd7626c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Valderrama?= Date: Mon, 16 Nov 2026 15:38:07 +0100 Subject: [PATCH] :bug: Apply the invite policy to pending invitations (#13080) * :bug: Apply the invite policy to pending invitations * :paperclip: Code review --- .../auth-permissions-product-domains.md | 1 + .serena/memories/frontend/core.md | 2 +- .../frontend/dashboard-viewer-subtleties.md | 2 +- .../app/rpc/commands/teams_invitations.clj | 87 ++++++++------ backend/test/backend_tests/rpc_team_test.clj | 106 ++++++++++++++++++ frontend/src/app/main/ui/dashboard/team.cljs | 96 +++++++++------- .../test/frontend_tests/data/team_test.cljs | 17 ++- 7 files changed, 232 insertions(+), 79 deletions(-) diff --git a/.serena/memories/backend/auth-permissions-product-domains.md b/.serena/memories/backend/auth-permissions-product-domains.md index 63907ba28f..5391802b1d 100644 --- a/.serena/memories/backend/auth-permissions-product-domains.md +++ b/.serena/memories/backend/auth-permissions-product-domains.md @@ -32,6 +32,7 @@ - Team/project commands mix DB changes, email, message bus notifications, media/storage cleanup, feature flags, quotas, and audit metadata. Keep mutations transactional when the existing command does so. - Invitation flows validate muted/bounced emails before sending and use tokenized invitation state. Accepting an invitation is tied to the invited member identity, not just possession of a token. - The whole invitation family is team-admin only: creating, updating and deleting invitations, minting the invitation token (`get-team-invitation-token`) and listing the pending ones (`get-team-invitations`, which carries the invited email and the offered role). The token of an invitation that grants the `owner` role is restricted to the team owner, because an admin cannot create nor promote an owner invitation (`cant-promote-to-owner`). This family is the exception to the rule above: it answers `:validation` / `:insufficient-permissions` instead of `:not-found`, so the five commands speak one language. +- With the `:admin-console` flag, the organization `send-invitations` policy (role value plus Nitrate `restrictions-met`, through `cto/allowed?`) gates every invitation command that hands out or manages access: create (and resend, which reuses it), `update-team-invitation-role`, `delete-team-invitation` and `get-team-invitation-token`. Only `get-team-invitations` stays on team admin alone, so a blocked admin still sees the list. The shared helper `check-send-invitations-policy` in `teams_invitations.clj` does a strict Nitrate lookup (fails closed; 404 means no organization) and runs outside a DB transaction, which is why the role and delete commands carry no `::db/transaction`. - Logical deletion is used for many product objects; prefer existing logical-deletion helpers over hard deletes unless the command already performs permanent cleanup. - Bounced/spam-complaint emails can mute/block a profile for login/registration and email sending. Devenv Mailpit is the normal local path for registration/email-flow testing. diff --git a/.serena/memories/frontend/core.md b/.serena/memories/frontend/core.md index 139859bc98..e0e84e4d9f 100644 --- a/.serena/memories/frontend/core.md +++ b/.serena/memories/frontend/core.md @@ -12,7 +12,7 @@ Frontend: CLJS SPA; React/Rumext; Potok; RxJS; okulary refs; SCSS modules; share - `app.render_wasm.*`: frontend bridge to Rust/WASM renderer. - `app.util.*`: DOM, HTTP, i18n, keyboard, codegen, and general frontend utilities. - `frontend/packages/*` and `frontend/text-editor`: JS/TS workspace packages consumed by the app. -- Nitrate subscription/organization UI and flows live under `app.main.data.nitrate` and `app.main.ui.nitrate*`; backend/API behavior is covered by backend memories, and shared permission rules are in `common/src/app/common/types/nitrate_permissions.cljc`. +- Nitrate subscription/organization UI and flows live under `app.main.data.nitrate` and `app.main.ui.nitrate*`; backend/API behavior is covered by backend memories, and shared organization permission rules (`allowed?`, `can-send-invitations?`) are in `common/src/app/common/types/organization.cljc`. - `app.config` external bridges (`external-feature-flag`, `external-session-id`, `external-context-info`, `external-notify-register-success`, `initialize-external-context-info`) delegate to `globalThis` hooks injected by the SaaS host. Never delete `external-feature-flag`, even with zero call sites: it is the seam for future A/B tests. diff --git a/.serena/memories/frontend/dashboard-viewer-subtleties.md b/.serena/memories/frontend/dashboard-viewer-subtleties.md index 14471e7195..5394e81cd8 100644 --- a/.serena/memories/frontend/dashboard-viewer-subtleties.md +++ b/.serena/memories/frontend/dashboard-viewer-subtleties.md @@ -7,7 +7,7 @@ - Dashboard file/project mutations are often optimistic local updates with fire-and-forget RPC watchers. Bulk permanent delete/restore paths use SSE progress and progress notifications. - The import wizard runs the package as a job of the backend: it reads the manifest of the file in the main thread (`app.main.data.imports`, no web worker) and follows the job, so its header paints the milestone of the job (the stage and its counter) instead of the messages the old SSE stream sent; every file of a container reports the same milestone, so `jp/current-milestone-text` writes it once and the rows never repeat it. Before the job exists, the header paints a client-side `:upload` milestone built from the chunked upload (`uploads/upload-blob-chunked` `:on-progress`, chunks done/total), which never comes from the backend; the chunks go one at a time and it writes them as a percentage of the file, not as a counter. Once created and still waiting for a worker, no row says anything: the header says the import waits for a slot while no job of it has started. The bar of the header measures the whole import, never a file: indeterminate while checking, waiting for a slot or rebuilding, because the client cannot know a global index and total of operations. The upload is the exception — the chunked upload knows its chunks, so the bar is determinate while the containers are sent, weighted by their size (`imp/upload-pct` over `:container-size`, the only percentage the client really knows). The export modal follows the same one-job-per-file model, but every file is queued up front (even the ones whose job is created only after the previous one is over) and its queue ends only with a milestone: `:start`/`:retry` do not end it there. Neither modal paints a generic "…ing file…" line on the rows any more: the rows of the import wizard carry only what is not progress — the name, the size, `Ready` once their container finished uploading, and the error text —, and the button that drops a file only shows while the wizard still offers its import step (the confirmation screen). Above the rows, the import wizard paints a stepper (Check/Upload/Import) plus one phase line: `imp/import-step` derives the step from the dialog status and the entries (upload holds while any file is pending, either `:import-ready` or carrying its own `:upload` milestone), so Check covers analyze, Upload covers the chunked client-side upload, and Import covers queue plus job. A file of a version 3 package shows what it occupies inside its container, computed while analyzing (`imp/file-sizes`): its own `files/…` entries plus the storage objects its media and thumbnails reference, whose metadata is the only link to `objects/…`. The container's own size stays in `:container-size` (what the dropped file weighs) and is what the upload bar weighs, never what a row shows. A file the manifest lists but the container holds no entry of has no size at all, and its row then shows no subtitle: what the package weighs never stands in for it. The subtitle is the size alone, with no extension. While analyzing with no failures nothing renders below the phase header — no rows, no spinner (`imp/awaiting-analysis?`); the header text is the only "Checking…" message. Rows appear once the analysis resolves (one per file inside the package), and a failed analysis takes the error-summary path instead. The ready step and its Continue wait for the end of the analysis (`imp/ready-to-import?`, fed with the completion of `imp/analyze`): a ready file is not enough, because the files still to arrive would never be imported. While rebuilding, the phase title counts the files and `imp/imported-count` counts them done with the job's own `:files` counter, so the number moves while a container rebuilds its files one by one. The `:error` of an import entry is user-facing text (the backend hint, or a translated label), never an i18n key: the wizard renders it as-is, it does not translate it again. The link-later step takes the file id from the `:id` of its resolution entry, never from the key of the resolution map: the map comes from the job result, so what a key holds depends on the result schema of the job-def that wrote it, while the wizard indexes its selection by the id of the entry. The legacy SSE import stays in the backend for other clients. - File creation/duplication strips file `:data` before putting file summaries into dashboard state. -- The pending invitations are a team-admin only list (backend `:is-admin` already includes the owner). The dashboard hides the invitations entry from the header tabs and the team-options dropdown for non-admins, `invitations-section-content` keys the section on `:is-admin`, and `fetch-invitations` answers `insufficient-permissions` by emitting `invitations-fetched` with `[]`, so a demoted admin does not keep the cached emails and the header does not paint the invite button from a stale list. The organization `send-invitations` policy only gates inviting and resending, not the list. +- The pending invitations are a team-admin only list (backend `:is-admin` already includes the owner). The dashboard hides the invitations entry from the header tabs and the team-options dropdown for non-admins, `invitations-section-content` keys the section on `:is-admin`, and `fetch-invitations` answers `insufficient-permissions` by emitting `invitations-fetched` with `[]`, so a demoted admin does not keep the cached emails and the header does not paint the invite button from a stale list. The organization `send-invitations` policy (`can-invite?`) does not gate the list, but it gates every action on it: inviting (header and empty-state buttons render disabled with the `dashboard.invite-profile-disabled` tooltip), the role selector (read-only label), row selection (so resend and delete never show) and copy link (`invitation-link-copyable?`). The backend enforces the same rule. ## Viewer diff --git a/backend/src/app/rpc/commands/teams_invitations.clj b/backend/src/app/rpc/commands/teams_invitations.clj index 83d09d3219..e60f8f26c8 100644 --- a/backend/src/app/rpc/commands/teams_invitations.clj +++ b/backend/src/app/rpc/commands/teams_invitations.clj @@ -474,6 +474,31 @@ "The number of invitations can be sent in a single rpc request" 25) +(defn- check-send-invitations-policy + "Raises `:insufficient-permissions` when the organization of the team does + not let the profile send invitations. The policy covers the pending + invitations too: changing their role, deleting them and minting their token + manage the same access that sending one grants. + + Only applies with the `:admin-console` flag. Then it returns the team with + its organization info, so the caller reuses the same Nitrate answer." + [cfg profile-id team-id perms] + (when (contains? cf/flags :admin-console) + (let [team (db/get-by-id cfg :team team-id) + ;; Strict lookup: a failed Nitrate call must not skip the + ;; organization policy by looking like a team without one. + team (nitrate/add-organization-info-to-team-strict cfg team {::rpc/profile-id profile-id}) + organization (:organization team)] + (when (and organization + (not (cto/allowed? :send-invitations + {:organization-perms organization + :profile-id profile-id + :team-perms perms}))) + (ex/raise :type :validation + :code :insufficient-permissions + :hint "Organization policy does not allow you to send invitations")) + team))) + (sv/defmethod ::create-team-invitations "A rpc call that allows to send single or multiple invitations to join the team. @@ -486,12 +511,10 @@ [cfg {:keys [::rpc/profile-id team-id role emails] :as params}] (let [perms (teams/check-invitation-permissions cfg profile-id team-id) profile (db/get-by-id cfg :profile profile-id) - team (db/get-by-id cfg :team team-id) - ;; Strict lookup: a failed Nitrate call must not skip the - ;; organization policy below by looking like a team without one. - team-with-org (when (contains? cf/flags :admin-console) - (nitrate/add-organization-info-to-team-strict cfg team {::rpc/profile-id profile-id})) - organization (:organization team-with-org) + ;; Reuse the organization lookup of the policy check, so every + ;; organization rule below sees the same Nitrate answer. + team (or (check-send-invitations-policy cfg profile-id team-id perms) + (db/get-by-id cfg :team team-id)) ;; Determine which format is being used using-emails-format? (and emails role) ;; Handle both parameter formats @@ -503,16 +526,6 @@ (count emails) (count (:invitations params)))] - (when (and (contains? cf/flags :admin-console) - organization - (not (cto/allowed? :send-invitations - {:organization-perms organization - :profile-id profile-id - :team-perms perms}))) - (ex/raise :type :validation - :code :insufficient-permissions - :hint "Organization policy does not allow you to send invitations")) - ;; Don't allow promote to owner to admin users. (when (and (not (:is-owner perms)) (or (= role :owner) @@ -536,10 +549,7 @@ ;; Check if the current profile is allowed to send emails (teams/check-profile-muted cfg profile) - (let [;; Reuse the strict organization lookup made for the policy - ;; check above, so every rule sees the same Nitrate answer. - team (or team-with-org team) - ;; NOTE: Is important pass RPC method params down to the + (let [;; NOTE: Is important pass RPC method params down to the ;; `create-team-invitations` because it uses the implicit ;; RPC properties from params for fill necessary data on ;; emiting an entry to the audit-log @@ -647,6 +657,9 @@ :code :cant-promote-to-owner :hint "only the team owner can get an owner invitation token")) + ;; Handing out the link invites as much as sending the email does. + (check-send-invitations-policy cfg profile-id team-id perms) + (let [member (profile/get-profile-by-email pool (:email-to invit)) token (create-invitation-token cfg {:team-id (:team-id invit) ;; The inviter is the creator of @@ -678,17 +691,20 @@ (sv/defmethod ::update-team-invitation-role {::doc/added "1.17" ::doc/module :teams - ::sm/params schema:update-team-invitation-role - ::db/transaction true} - [{:keys [::db/conn]} {:keys [::rpc/profile-id team-id email role] :as params}] - (let [perms (teams/check-invitation-permissions conn profile-id team-id)] + ::sm/params schema:update-team-invitation-role} + [cfg {:keys [::rpc/profile-id team-id email role] :as params}] + (let [perms (teams/check-invitation-permissions cfg profile-id team-id)] ;; Don't allow promote to owner to admin users. (when (and (not (:is-owner perms)) (= role :owner)) (ex/raise :type :validation :code :cant-promote-to-owner)) - (db/update! conn :team-invitation + ;; Checked outside a transaction: it may call Nitrate over HTTP, and the + ;; update below is a single statement. + (check-send-invitations-policy cfg profile-id team-id perms) + + (db/update! cfg :team-invitation {:role (name role) :updated-at (ct/now)} {:team-id team-id :email-to (profile/clean-email email)}) @@ -703,16 +719,19 @@ (sv/defmethod ::delete-team-invitation {::doc/added "1.17" - ::sm/params schema:delete-team-invition - ::db/transaction true} - [{:keys [::db/conn]} {:keys [::rpc/profile-id team-id email] :as params}] - (teams/check-invitation-permissions conn profile-id team-id) + ::sm/params schema:delete-team-invition} + [cfg {:keys [::rpc/profile-id team-id email] :as params}] + (let [perms (teams/check-invitation-permissions cfg profile-id team-id)] - (let [invitation (db/delete! conn :team-invitation - {:team-id team-id - :email-to (profile/clean-email email)} - {::db/return-keys true})] - (rph/wrap nil {::audit/props {:invitation-id (:id invitation)}}))) + ;; Checked outside a transaction: it may call Nitrate over HTTP, and the + ;; delete below is a single statement. + (check-send-invitations-policy cfg profile-id team-id perms) + + (let [invitation (db/delete! cfg :team-invitation + {:team-id team-id + :email-to (profile/clean-email email)} + {::db/return-keys true})] + (rph/wrap nil {::audit/props {:invitation-id (:id invitation)}})))) ;; --- Mutation: Request Team Invitation diff --git a/backend/test/backend_tests/rpc_team_test.clj b/backend/test/backend_tests/rpc_team_test.clj index 6e4dd6fd4a..a59d2759da 100644 --- a/backend/test/backend_tests/rpc_team_test.clj +++ b/backend/test/backend_tests/rpc_team_test.clj @@ -1093,6 +1093,112 @@ (t/is (nil? (:result out))) (t/is (nil? res))))) +;; The organization `send-invitations` policy covers the pending invitations +;; too: changing their role, deleting them and getting their link manage the +;; same access that sending one grants. + +(def ^:private pending-invitation-email "pending@example.com") + +(defn- reset-pending-invitation + "Leaves one pending `editor` invitation in the team, whatever the previous + scenario did to it." + [team-id] + (db/delete! th/*pool* :team-invitation + {:team-id team-id :email-to pending-invitation-email}) + (db/insert! th/*pool* :team-invitation + {:team-id team-id + :email-to pending-invitation-email + :role "editor" + :valid-until (ct/in-future "48h")})) + +(defn- get-pending-invitation-role + [team-id] + (:role (db/get* th/*pool* :team-invitation + {:team-id team-id :email-to pending-invitation-email}))) + +(defn- organization-with-policy + "A team organization lookup that answers with an organization whose + `send-invitations` value and attribute restriction answer are the given + ones." + [owner-id send-invitations restrictions-met] + (fn [_params] + {:organization {:id (uuid/random) + :name "Acme" + :slug "acme" + :owner-id owner-id + :avatar-bg-url "https://example.com/avatar.svg" + :permissions {:send-invitations send-invitations} + :restrictions-met {:send-invitations restrictions-met}} + :is-your-penpot false})) + +(defn- organization-lookup-failure + [status] + (fn [_params] + (throw (ex-info "nitrate error" {:type :nitrate-http-error + :status status})))) + +(defn- check-follows-send-invitations-policy + "Runs the invitation `command` (a params map without profile, team and + email) under each organization policy and checks who may go through." + [command] + (let [owner (th/create-profile* 440 {:is-active true}) + admin (th/create-profile* 441 {:is-active true}) + team (th/create-team* 440 {:profile-id (:id owner)}) + _ (th/create-team-role* {:team-id (:id team) + :profile-id (:id admin) + :role :admin}) + team-id (:id team) + + execute + (fn [profile get-team-organization] + (reset-pending-invitation team-id) + (with-redefs [cf/flags (conj cf/flags :admin-console) + nitrate/call (fn [_cfg method params] + (case method + :get-team-organization (get-team-organization params) + nil))] + (th/command! (assoc command + ::rpc/profile-id (:id profile) + :team-id team-id + :email pending-invitation-email))))] + + (t/testing "an admin is denied when only team owners may invite" + (let [out (execute admin (organization-with-policy (:id owner) "owners" true))] + (t/is (= :insufficient-permissions (th/ex-code (:error out)))) + (t/is (= "editor" (get-pending-invitation-role team-id))))) + + (t/testing "an admin is denied when an attribute restriction leaves them out" + (let [out (execute admin (organization-with-policy (:id owner) "ownersAndAdmins" false))] + (t/is (= :insufficient-permissions (th/ex-code (:error out)))) + (t/is (= "editor" (get-pending-invitation-role team-id))))) + + (t/testing "a failed organization lookup denies the admin" + (let [out (execute admin (organization-lookup-failure 403))] + (t/is (= :nitrate-http-error (th/ex-type (:error out)))) + (t/is (= "editor" (get-pending-invitation-role team-id))))) + + (t/testing "a team owner is allowed when only team owners may invite" + (t/is (th/success? (execute owner (organization-with-policy (:id owner) "owners" true))))) + + (t/testing "an admin is allowed when the policy and the restriction include them" + (t/is (th/success? (execute admin (organization-with-policy (:id owner) "ownersAndAdmins" true))))) + + (t/testing "an admin is allowed in a team without organization" + (t/is (th/success? (execute admin (organization-lookup-failure 404))))))) + +(t/deftest update-team-invitation-role-follows-send-invitations-policy + (check-follows-send-invitations-policy + {::th/type :update-team-invitation-role + :role :admin})) + +(t/deftest delete-team-invitation-follows-send-invitations-policy + (check-follows-send-invitations-policy + {::th/type :delete-team-invitation})) + +(t/deftest get-team-invitation-token-follows-send-invitations-policy + (check-follows-send-invitations-policy + {::th/type :get-team-invitation-token})) + (t/deftest get-owned-teams (let [profile1 (th/create-profile* 1 {:is-active true}) diff --git a/frontend/src/app/main/ui/dashboard/team.cljs b/frontend/src/app/main/ui/dashboard/team.cljs index 43aa9994e3..53aad60ced 100644 --- a/frontend/src/app/main/ui/dashboard/team.cljs +++ b/frontend/src/app/main/ui/dashboard/team.cljs @@ -665,7 +665,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (mf/defc invitation-role-selector* - [{:keys [role status on-change]}] + [{:keys [role status on-change can-invite]}] (let [show? (mf/use-state false) label (cond (= role :owner) (tr "labels.owner") @@ -686,7 +686,7 @@ (on-change role event))))] [:* - (if (= status :pending) + (if (and ^boolean can-invite (= status :pending)) [:button {:class (stl/css :rol-selector :has-priv) :type "button" :aria-haspopup "listbox" @@ -714,15 +714,17 @@ (tr "labels.viewer")]]]])) (defn invitation-link-copyable? - "The link of an owner invitation can only be copied by the team owner: an - admin cannot create nor promote an owner invitation, so the backend does - not mint its token for them." - [is-owner? role] - (or (not= :owner role) is-owner?)) + "The link of an invitation invites as much as sending it, so it needs the + organization invite policy (`can-invite?`). The link of an owner invitation + can only be copied by the team owner: an admin cannot create nor promote an + owner invitation, so the backend does not mint its token for them." + [can-invite? is-owner? role] + (and can-invite? + (or (not= :owner role) is-owner?))) (mf/defc invitation-actions* {::mf/private true} - [{:keys [invitation team-id is-owner?]}] + [{:keys [invitation team-id is-owner? can-invite]}] (let [email (:email invitation) copied* (mf/use-state false) copied? (deref copied*) @@ -768,7 +770,7 @@ (-> (dtm/copy-invitation-link params) (with-meta {::ev/origin :team}))))))] - (when (invitation-link-copyable? is-owner? (:role invitation)) + (when (invitation-link-copyable? can-invite is-owner? (:role invitation)) [:> icon-button* {:variant "ghost" :aria-label (tr "labels.copy-invitation-link") :on-click on-copy @@ -777,7 +779,7 @@ (mf/defc invitation-row* {::mf/wrap [mf/memo] ::mf/private true} - [{:keys [invitation team-id selected on-select-change is-owner?]}] + [{:keys [invitation team-id selected on-select-change is-owner? can-invite]}] (let [expired? (:expired invitation) email (:email invitation) @@ -811,24 +813,29 @@ [:div {:class (stl/css :table-row :table-row-invitations)} [:div {:class (stl/css :table-field :field-email)} - [:div {:class (stl/css :input-wrapper)} - [:label - [:span {:class (stl/css-case :input-checkbox true - :global/checked (is-selected? email))} - deprecated-icon/status-tick] + ;; Selecting an invitation only leads to resending or deleting it, and + ;; both need the organization invite policy. + (if ^boolean can-invite + [:div {:class (stl/css :input-wrapper)} + [:label + [:span {:class (stl/css-case :input-checkbox true + :global/checked (is-selected? email))} + deprecated-icon/status-tick] - [:input {:type "checkbox" - :id (dm/str "email-" email) - :data-attr email - :value email - :checked (is-selected? email) - :on-change on-change}] - email]]] + [:input {:type "checkbox" + :id (dm/str "email-" email) + :data-attr email + :value email + :checked (is-selected? email) + :on-change on-change}] + email]] + [:div email])] [:div {:class (stl/css :table-field :field-roles)} [:> invitation-role-selector* {:role role :status status + :can-invite can-invite :on-change on-change-role}]] [:div {:class (stl/css :table-field :field-status)} @@ -838,11 +845,12 @@ [:> invitation-actions* {:invitation invitation :team-id team-id - :is-owner? is-owner?}]]])) + :is-owner? is-owner? + :can-invite can-invite}]]])) (mf/defc empty-invitation-table* {::mf/private true} - [{:keys [team]}] + [{:keys [team can-invite]}] (let [route (mf/deref refs/route) invite-email (-> route :query-params :invite-email) @@ -855,11 +863,21 @@ [:div {:class (stl/css :empty-invitations)} [:div (tr "labels.no-invitations")] [:div (tr "labels.no-invitations-gather-people")] - [:> button* {:variant "primary" - :class (stl/css :btn-empty-invitations) - :on-click on-invite-member - :data-testid "invite-member"} - (tr "dashboard.invite-profile")]])) + ;; Same as the header button: disabled with its reason when the + ;; organization invite policy leaves the profile out. + (let [invite-button (mf/html + [:> button* {:variant "primary" + :class (stl/css :btn-empty-invitations) + :on-click on-invite-member + :disabled (not can-invite) + :data-testid "invite-member"} + (tr "dashboard.invite-profile")])] + (if ^boolean can-invite + invite-button + [:> tooltip* {:content (tr "dashboard.invite-profile-disabled") + :id "empty-invite-member-disabled-tooltip" + :tab-index 0} + invite-button]))])) (mf/defc invitation-modal {::mf/register modal/components @@ -1224,18 +1242,17 @@ (tr "dashboard.invitations.no-permission")]] [:* - (when (> (count @selected) 0) + ;; Managing the pending invitations (role, resend, delete, link) + ;; needs the organization invite policy; the list only needs admin. + (when (and can-invite? (> (count @selected) 0)) [:div {:class (stl/css :invitations-actions)} [:div (tr "team.invitations-selected" (i18n/c (count @selected)))] - ;; Resending goes through the invite command, so it needs the - ;; organization invite policy; deleting only needs team admin. - (when can-invite? - [:div - [:> button* {:variant "secondary" - :type "button" - :on-click on-resend} - (tr "labels.resend-invitation")]]) + [:div + [:> button* {:variant "secondary" + :type "button" + :on-click on-resend} + (tr "labels.resend-invitation")]] [:> icon-button* {:on-click on-delete :variant "destructive" :aria-label (tr "labels.delete-invitation") @@ -1261,13 +1278,14 @@ "arrow-down") :on-click on-order-by-status}]]] (if (empty? @invitations) - [:> empty-invitation-table* {:team team}] + [:> empty-invitation-table* {:team team :can-invite can-invite?}] [:div {:class (stl/css :table-rows)} (for [invitation @invitations] [:> invitation-row* {:key (:email invitation) :invitation invitation :is-owner? is-owner? + :can-invite can-invite? :team-id team-id :selected selected :on-select-change on-select-change}])])])])) diff --git a/frontend/test/frontend_tests/data/team_test.cljs b/frontend/test/frontend_tests/data/team_test.cljs index 87ef76be68..d05041c0db 100644 --- a/frontend/test/frontend_tests/data/team_test.cljs +++ b/frontend/test/frontend_tests/data/team_test.cljs @@ -162,7 +162,16 @@ (t/deftest owner-invitation-link-is-copyable-only-by-the-team-owner ;; An admin cannot create nor promote an owner invitation, so the backend ;; does not mint its token for them: the action is not offered either. - (t/is (true? (dtui/invitation-link-copyable? true :owner))) - (t/is (false? (dtui/invitation-link-copyable? false :owner))) - (t/is (true? (dtui/invitation-link-copyable? false :editor))) - (t/is (true? (dtui/invitation-link-copyable? false :viewer)))) + (t/is (true? (dtui/invitation-link-copyable? true true :owner))) + (t/is (false? (dtui/invitation-link-copyable? true false :owner))) + (t/is (true? (dtui/invitation-link-copyable? true false :editor))) + (t/is (true? (dtui/invitation-link-copyable? true false :viewer)))) + +(t/deftest invitation-link-is-not-copyable-without-the-invite-policy + ;; The link invites as much as sending the invitation does, so a profile + ;; that the organization invite policy leaves out cannot copy it, not even + ;; the team owner. + (t/is (false? (dtui/invitation-link-copyable? false true :owner))) + (t/is (false? (dtui/invitation-link-copyable? false true :editor))) + (t/is (false? (dtui/invitation-link-copyable? false false :editor))) + (t/is (false? (dtui/invitation-link-copyable? false false :viewer))))