Skip to content

Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.

fix(glossary): refuse an inactive member with 403 glossary_forbidden, not the 404

Guido Boyke6fa510fb4006
diff --git a/.github/workflows/guards.yml b/.github/workflows/guards.yml
index fabf818..2cdc993 100644
--- a/.github/workflows/guards.yml
+++ b/.github/workflows/guards.yml
@@ -219,6 +219,7 @@ jobs:
spec/models/no_inline_embedding_columns_guard_spec.rb
spec/models/personal_access_token/all_organisations_spec.rb
spec/models/personal_access_token/reach_spec.rb
+ spec/models/personal_access_token/deactivated_member_spec.rb
spec/models/prompt_persona_spec.rb
spec/models/smart_folders/operator_literal_guard_spec.rb
spec/models/smart_folders/date_presets_spec.rb
diff --git a/CLAUDE.md b/CLAUDE.md
index 3f2c3a7..3cba9e4 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -952,7 +952,10 @@ grouped by the compared form with the spelling last heard, `count` the sum of `r
the same reason and text). Unlike the people directory, a token limited to some projects is
answered: every term, the heard forms of its projects only, and a form without a project only for
a token that reaches every project. An organisation outside the token, a foreign, a missing and a
-malformed one answer the same 404 (MCP `not_found`, also for a malformed id); `project_id` puts the
+malformed one answer the same 404 (MCP `not_found`, also for a malformed id); a member deactivated in
+an organisation the token names gets the 403 of the missing right instead (the reach still leaves that
+organisation out, `PersonalAccessToken#deactivated_member_of?` only words the refusal), a removed
+membership the 404; `project_id` puts the
forms of its project first, outside the organisation or the token the same 404. `people` and
`speakers` only with the people right (`PersonPolicy`), named as the directory names them to the
reader; whom it does not list counts in `count` alone. No meeting, place or corrector in the
diff --git a/app/controllers/api/v1/terms_controller.rb b/app/controllers/api/v1/terms_controller.rb
index 626428f..0ed2539 100644
--- a/app/controllers/api/v1/terms_controller.rb
+++ b/app/controllers/api/v1/terms_controller.rb
@@ -11,7 +11,8 @@ module Api
# malformed id answer the same 404. A token limited to some projects gets every term,
# but the heard forms of its projects only.
# * Rights (E2): the glossary right of the token's owner (GlossaryPolicy, an active
- # membership), 403 with the reason glossary_forbidden without it. A read token suffices.
+ # membership), 403 with the reason glossary_forbidden without it, also for a member
+ # deactivated in an organisation the token names. A read token suffices.
# * project_id (E5): that project's heard forms first; outside the organisation or the
# token the same 404, never ignored.
# * Paging: 50 terms by default, at most 100, with the total; a value outside is a 400.
@@ -27,7 +28,7 @@ module Api
# The reach, then the organisation's tenant, then the glossary right, the order of the
# people directory: an organisation outside the token tells nothing about itself.
def index
- lookup = Glossary::Lookup.for_token(reach: current_token.reach, viewer: current_user,
+ lookup = Glossary::Lookup.for_token(token: current_token, viewer: current_user,
organisation_id: params[:organisation_id])
raise ActiveRecord::RecordNotFound if lookup.nil?
diff --git a/app/models/CLAUDE.md b/app/models/CLAUDE.md
index 5258a05..cfe2b33 100644
--- a/app/models/CLAUDE.md
+++ b/app/models/CLAUDE.md
@@ -234,7 +234,9 @@ Verzeichnis-Layout nicht ablesbar — diese Karte gruppiert sie:
* **AI/Billing**: `ai_credential`, `ai_usage`, `system_setting`, `personal_access_token{,_organisation,_project}`
(`personal_access_token/reach.rb` = der Token-Vertrag als Wertobjekt, gegen `#accessible_project?` gepinnt;
welche Organisationen ein Token erreicht, beantwortet NUR `#organisation_scopes`, auch für
- `all_organisations`, nie die Verknüpfungszeilen selbst),
+ `all_organisations`, nie die Verknüpfungszeilen selbst; `#deactivated_member_of?` (K4c) öffnet nichts,
+ es sagt einer Tür nur, dass eine genannte Organisation wegen deaktivierter Mitgliedschaft fehlt, damit
+ das Glossar sie als fehlendes Recht ablehnt, 403 statt 404),
`content_embedding` (Sidecar-Vektor je Record je Raum), `embedding_space` (ein von der Org
GEHALTENER Vektorraum: Tripel + verschlüsselter Credential-Snapshot; welcher davon die Suche
bedient, sagt `organisations.active_embedding_space_id`),
diff --git a/app/models/personal_access_token.rb b/app/models/personal_access_token.rb
index d8def64..2322a6e 100644
--- a/app/models/personal_access_token.rb
+++ b/app/models/personal_access_token.rb
@@ -176,6 +176,23 @@ class PersonalAccessToken < ApplicationRecord
link && OrganisationScope.new(organisation_id: link.organisation_id, all_projects: link.all_projects?)
end
+ # Whether this token names the organisation (a link, or with all_organisations
+ # every organisation of its owner) while the owner's membership there is
+ # deactivated. Such an organisation is outside the reach (#organisation_scopes
+ # counts ACTIVE memberships only) and stays so: this opens nothing. It only lets
+ # a door refuse it as the missing right of an inactive member instead of
+ # answering "not found", for an organisation the holder knows anyway (K4c, the
+ # glossary's 403). A removed membership is no inactive membership: false.
+ # Tenant-free, like #organisation_scope_for.
+ def deactivated_member_of?(organisation_id)
+ return false if organisation_id.blank?
+
+ inactive = Membership.inactive.where(user_id: user_id, organisation_id: organisation_id)
+ return inactive.exists? if all_organisations?
+
+ personal_access_token_organisations.where(organisation_id: inactive.select(:organisation_id)).exists?
+ end
+
# The project ids linked to this token within one organisation (the
# selected-projects mode). Tenant-free, like #organisation_scopes.
def linked_project_ids(organisation_id)
diff --git a/app/services/CLAUDE.md b/app/services/CLAUDE.md
index 0c6eb69..2466af9 100644
--- a/app/services/CLAUDE.md
+++ b/app/services/CLAUDE.md
@@ -212,7 +212,8 @@ Verzeichnis-Übersicht (Auswahl):
`lookup.rb` (`Glossary::Lookup`, K4c, 06.11.2026), das EINE Lesen des Glossars einer Organisation
für `GET /api/v1/organisations/:id/terms` und das MCP-Werkzeug `get_glossary`: Recht
(`#allowed?`, von `#read` noch einmal gefragt: `Refused`), `.for_token` (eine Organisation in
- Reichweite, ihre Projekte als Grenze der gehörten Formen; nil für außerhalb, fehlend, kaputt), nur
+ Reichweite, ihre Projekte als Grenze der gehörten Formen; nil für außerhalb, fehlend, kaputt;
+ `Refused` für ein deaktiviertes Mitglied einer Organisation, die der Token nennt), nur
Wirksames (bestätigte Begriffe, `TermCorrection.effective`), `project_id` nach vorn (`NotFound`
außerhalb), Sprecher nur mit dem Personenrecht über `People::Directory#entry_for_participant`,
Seiten (`InvalidArgument`). Setzt den Mandanten selbst. Eine neue Regel dieser Antwort gehört
diff --git a/app/services/glossary/lookup.rb b/app/services/glossary/lookup.rb
index a4ed989..b75f5b2 100644
--- a/app/services/glossary/lookup.rb
+++ b/app/services/glossary/lookup.rb
@@ -10,7 +10,9 @@
module Glossary
# * Rights (E2): GlossaryPolicy.view_allowed? (#allowed?, asked again by #read
# before anything is read), which asks for an ACTIVE membership. The rows
- # come through the policy scope as well, so nothing is read without it.
+ # come through the policy scope as well, so nothing is read without it. A
+ # member deactivated in an organisation the token names is refused the same
+ # way, by .for_token, though the reach no longer counts that organisation.
# * What works (E3): confirmed terms only, and at them only the heard forms
# TermCorrection.effective names (confirmed at a confirmed term). A confirmed
# term without one comes with an empty heard list.
@@ -56,11 +58,22 @@ module Glossary
# The lookup a Personal Access Token may open, or nil (E4): an organisation
# the token reaches, with the token's projects as the limit of the heard
# forms (PersonalAccessToken::Reach, nil = every project). An organisation
- # outside the token (an inactive membership included), a missing one and a
- # malformed id all answer nil, so a caller tells none of them apart.
- def self.for_token(reach:, viewer:, organisation_id:)
+ # outside the token, a missing one and a malformed id all answer nil, so a
+ # caller tells none of them apart. One case is asked only when the reach says
+ # no: an organisation the token names where its owner's membership is
+ # deactivated is Refused, the missing right of an inactive member (E2: the
+ # right asks for an active membership), not "not found". Nothing is read
+ # there (PersonalAccessToken#deactivated_member_of?).
+ def self.for_token(token:, viewer:, organisation_id:)
id = Lalabase::Uuid.dashed(organisation_id)
- return nil if id.nil? || !reach.organisation?(id)
+ return nil if id.nil?
+
+ reach = token.reach
+ unless reach.organisation?(id)
+ raise Refused if token.deactivated_member_of?(id)
+
+ return nil
+ end
organisation = Organisation.find_by(id: id)
new(viewer: viewer, organisation: organisation, project_ids: reach.project_ids_for(id)) if organisation
diff --git a/app/services/lalabase/CLAUDE.md b/app/services/lalabase/CLAUDE.md
index 46f4214..6450d94 100644
--- a/app/services/lalabase/CLAUDE.md
+++ b/app/services/lalabase/CLAUDE.md
@@ -46,7 +46,8 @@ Codebase-Verständnis.
`GET /api/v1/organisations/:id/terms`. `scope_mode :token`; `Glossary::Lookup.for_token` is its
gate: an organisation outside the token, a foreign, a missing and a malformed id are all
`not_found`, as REST's one 404 (not `invalid_input` like the people twins: one reader, one
- reading of the id). Then the tenant, the glossary right (`refused`, reason `glossary_forbidden`,
+ reading of the id); a member deactivated in an organisation the token names is `refused`
+ (`glossary_forbidden`), REST's 403. Then the tenant, the glossary right (`refused`, the same reason,
REST's text) and `authorize!`. `project_id` is its own argument (it reorders, it does not narrow),
so `project_filter?` stays false; an unknown argument is `invalid_input`. The bounds of `page` and
`per_page` are the reader's, not the schema's (no `minimum`/`maximum`): the SDK would refuse a value
diff --git a/app/services/lalabase/tools/get_glossary.rb b/app/services/lalabase/tools/get_glossary.rb
index b741b9b..88030c9 100644
--- a/app/services/lalabase/tools/get_glossary.rb
+++ b/app/services/lalabase/tools/get_glossary.rb
@@ -9,9 +9,10 @@ module Lalabase
#
# Token-scoped: the glossary is the organisation's, not a project's, so no project gate runs.
# Glossary::Lookup.for_token is the gate: an organisation outside the token, a foreign, a
- # missing and a malformed id all answer not_found, as REST answers its one 404 (E4); the
- # call then runs under that organisation's tenant, asks the glossary right (refused with the
- # reason glossary_forbidden, REST's 403) and marks authorize! for the D7 tripwire. A malformed
+ # missing and a malformed id all answer not_found, as REST answers its one 404 (E4); a member
+ # deactivated in an organisation the token names is refused (glossary_forbidden, REST's 403).
+ # The call then runs under that organisation's tenant, asks the glossary right (refused with
+ # the same reason) and marks authorize! for the D7 tripwire. A malformed
# id is no invalid_input here, unlike the people twins: the two doors of one reader read one
# id the same way (the reason of get_meeting, R9). project_id is the tool's own argument: it
# reorders, it does not narrow, so it is not the dispatcher's filter (project_filter? false).
@@ -79,18 +80,21 @@ module Lalabase
end
def self.execute(args:, context:)
- return Result.new(error: 'token context missing') unless token_wide?(context)
+ return Result.new(error: 'token context missing') unless token_wide?(context) && context.token
args = symbolized(args)
unknown = args.keys - ARGUMENTS
return Result.invalid_input("unknown arguments: #{unknown.join(', ')}") if unknown.any?
return Result.invalid_input('organisation_id is required') if args[:organisation_id].to_s.strip.empty?
- lookup = Glossary::Lookup.for_token(reach: context.reach, viewer: context.actor,
+ lookup = Glossary::Lookup.for_token(token: context.token, viewer: context.actor,
organisation_id: args[:organisation_id])
return Result.new(error: ORGANISATION_NOT_REACHABLE, code: :not_found) if lookup.nil?
ActsAsTenant.with_tenant(lookup.organisation) { read(lookup, args, context) }
+ rescue Glossary::Lookup::Refused
+ # A member deactivated in an organisation the token names (Glossary::Lookup.for_token).
+ refused
end
def self.read(lookup, args, context)
diff --git a/spec/contracts/mcp_contract_recorder.rb b/spec/contracts/mcp_contract_recorder.rb
index 4d111eb..deb2634 100644
--- a/spec/contracts/mcp_contract_recorder.rb
+++ b/spec/contracts/mcp_contract_recorder.rb
@@ -386,6 +386,8 @@ module McpContract
# Dora may read the glossary, not the people directory: nobody named.
'ok_without_people_right' => with_glossary_right_for_dora { tool_call(:dora, 'get_glossary', organisation_id: nordlicht) },
'refused' => tool_call(:dora, 'get_glossary', organisation_id: nordlicht),
+ # Carla's membership is deactivated; her token still names Nordlicht: the missing right, not "not found".
+ 'refused_deactivated' => tool_call(:deactivated, 'get_glossary', organisation_id: nordlicht),
# Anna is no member there: outside the token, like a missing organisation.
'not_found' => tool_call(:read, 'get_glossary', organisation_id: id(:other_organisation)),
'not_found_malformed' => tool_call(:read, 'get_glossary', organisation_id: 'oops'),
@@ -754,6 +756,7 @@ module McpContract
'ok_project_token' => rest_get(:limited, path),
'ok_without_people_right' => with_glossary_right_for_dora { rest_get(:dora, path) },
'forbidden' => rest_get(:dora, path),
+ 'forbidden_deactivated' => rest_get(:deactivated, path),
'not_found' => rest_get(:read, "/api/v1/organisations/#{id(:other_organisation)}/terms"),
'not_found_malformed' => rest_get(:read, '/api/v1/organisations/oops/terms'),
'not_found_project' => rest_get(:read, "#{path}?project_id=#{id(:foreign_project)}"),
diff --git a/spec/models/personal_access_token/deactivated_member_spec.rb b/spec/models/personal_access_token/deactivated_member_spec.rb
new file mode 100644
index 0000000..ecede3b
--- /dev/null
+++ b/spec/models/personal_access_token/deactivated_member_spec.rb
@@ -0,0 +1,98 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+# What: PersonalAccessToken#deactivated_member_of?, whether a token names an organisation (a
+# link, or with all_organisations every organisation of its owner) while the owner's
+# membership there is deactivated (K4c).
+# Why: such an organisation is outside the reach (#organisation_scopes counts ACTIVE memberships
+# only) and stays so: the predicate opens nothing. It only lets a door refuse it as the missing
+# right of an inactive member (the glossary's 403) instead of answering "not found", for an
+# organisation the holder knows anyway. A removed membership and an organisation the token does
+# not name are no inactive membership of the token: they stay "not found".
+RSpec.describe PersonalAccessToken, :ci_guard, type: :model do
+ let(:user) { create(:user) }
+ let(:org_a) { create(:organisation) }
+ let(:org_b) { create(:organisation) }
+
+ def member(org, active: true)
+ ActsAsTenant.with_tenant(org) { create(:membership, user: user, organisation: org, active: active) }
+ end
+
+ def membership(org)
+ ActsAsTenant.with_tenant(org) { Membership.find_by!(user: user, organisation: org) }
+ end
+
+ # A fresh instance, as the next request would load it: #reach is memoised per instance.
+ def reloaded(token)
+ described_class.find(token.id)
+ end
+
+ before do
+ Prosopite.pause do
+ member(org_a)
+ member(org_b)
+ end
+ end
+
+ context 'with organisation links' do
+ let(:token) { create(:personal_access_token, user: user, organisations: [org_a]) }
+
+ it 'is false while the membership is active, when the token reaches the organisation' do
+ expect(token.deactivated_member_of?(org_a.id)).to be false
+ expect(token.reach.organisation?(org_a.id)).to be true
+ end
+
+ it 'is true once the membership of a named organisation is deactivated, which the reach leaves out' do
+ token
+ ActsAsTenant.with_tenant(org_a) { membership(org_a).update!(active: false) }
+
+ expect(reloaded(token).deactivated_member_of?(org_a.id)).to be true
+ expect(reloaded(token).reach.organisation?(org_a.id)).to be false
+ end
+
+ it 'is true for a token limited to some projects of that organisation as well' do
+ project = ActsAsTenant.with_tenant(org_a) { create(:project, organisation: org_a) }
+ limited = create(:personal_access_token, user: user, organisations: [org_a], project_scopes: { org_a => [project] })
+ ActsAsTenant.with_tenant(org_a) { membership(org_a).update!(active: false) }
+
+ expect(reloaded(limited).deactivated_member_of?(org_a.id)).to be true
+ end
+
+ it 'is false for an organisation the token does not name, deactivated or not' do
+ token
+ ActsAsTenant.with_tenant(org_b) { membership(org_b).update!(active: false) }
+
+ expect(reloaded(token).deactivated_member_of?(org_b.id)).to be false
+ end
+
+ it 'is false once the membership is removed: no membership, nothing inactive' do
+ token
+ Prosopite.pause { ActsAsTenant.with_tenant(org_a) { membership(org_a).destroy! } }
+
+ expect(reloaded(token).deactivated_member_of?(org_a.id)).to be false
+ end
+ end
+
+ context 'with all_organisations' do
+ let(:token) { create(:personal_access_token, :all_organisations, user: user) }
+
+ it 'is true for every organisation where the owner is a deactivated member, false elsewhere' do
+ token
+ ActsAsTenant.with_tenant(org_b) { membership(org_b).update!(active: false) }
+ foreign = create(:organisation)
+
+ expect(reloaded(token).deactivated_member_of?(org_b.id)).to be true
+ expect(reloaded(token).deactivated_member_of?(org_a.id)).to be false
+ expect(reloaded(token).deactivated_member_of?(foreign.id)).to be false
+ end
+ end
+
+ it 'is false for a blank or missing id' do
+ token = create(:personal_access_token, user: user, organisations: [org_a])
+
+ expect(token.deactivated_member_of?(nil)).to be false
+ expect(token.deactivated_member_of?('')).to be false
+ expect(token.deactivated_member_of?(SecureRandom.uuid)).to be false
+ end
+end
diff --git a/spec/requests/api/glossary_parity_spec.rb b/spec/requests/api/glossary_parity_spec.rb
index f026729..eab4c68 100644
--- a/spec/requests/api/glossary_parity_spec.rb
+++ b/spec/requests/api/glossary_parity_spec.rb
@@ -141,6 +141,17 @@ RSpec.describe 'Glossary on REST and MCP', :ci_guard, type: :request do
expect(result.dig('content', 0, 'text')).to eq(body['message'])
end
+ it 'refuses a deactivated member on both with the reason glossary_forbidden and one text' do
+ deactivated = token
+ ActsAsTenant.with_tenant(organisation) { Membership.find_by!(user: anna, organisation: organisation).update!(active: false) }
+ status, body = rest(with: deactivated)
+ result = mcp(with: deactivated)
+
+ expect([status, body['reason']]).to eq([403, 'glossary_forbidden'])
+ expect(result['_meta']).to eq('lalabase/code' => 'refused', 'lalabase/reason' => 'glossary_forbidden')
+ expect(result.dig('content', 0, 'text')).to eq(body['message'])
+ end
+
it 'answers an organisation outside the token and a project outside it as not found on both' do
outside_status, = rest(organisation_id: other_organisation.id)
outside = mcp(organisation_id: other_organisation.id)
diff --git a/spec/requests/api/mcp_glossary_spec.rb b/spec/requests/api/mcp_glossary_spec.rb
index 4e65dbe..35a48f7 100644
--- a/spec/requests/api/mcp_glossary_spec.rb
+++ b/spec/requests/api/mcp_glossary_spec.rb
@@ -190,11 +190,22 @@ RSpec.describe 'MCP get_glossary', :ci_guard, type: :request do
.to all(eq([{ 'lalabase/code' => 'not_found' }, 'Organisation not found or not accessible.']))
end
- it 'answers a deactivated member like an organisation outside the token' do
+ it 'refuses a deactivated member with the reason glossary_forbidden, as REST answers 403' do
deactivated = token
ActsAsTenant.with_tenant(organisation) { Membership.find_by!(user: anna, organisation: organisation).update!(active: false) }
- expect(refusal(glossary(with: deactivated)).first).to eq('lalabase/code' => 'not_found')
+ expect(refusal(glossary(with: deactivated)))
+ .to eq([{ 'lalabase/code' => 'refused', 'lalabase/reason' => 'glossary_forbidden' },
+ 'You may not read the glossary of this organisation.'])
+ end
+
+ it 'answers a removed membership like an organisation outside the token: not_found' do
+ removed = token
+ Prosopite.pause do
+ ActsAsTenant.with_tenant(organisation) { Membership.find_by!(user: anna, organisation: organisation).destroy! }
+ end
+
+ expect(refusal(glossary(with: removed)).first).to eq('lalabase/code' => 'not_found')
end
it 'answers a project_id outside the organisation, outside the token, missing or malformed alike: not_found' do
diff --git a/spec/requests/api/v1/terms_spec.rb b/spec/requests/api/v1/terms_spec.rb
index 9f0f4b7..4bdbd6a 100644
--- a/spec/requests/api/v1/terms_spec.rb
+++ b/spec/requests/api/v1/terms_spec.rb
@@ -176,11 +176,33 @@ RSpec.describe 'API V1 glossary terms', :ci_guard, type: :request do
expect(terms(with: token(owner: nobody), per_page: 101)).to have_http_status(:forbidden)
end
- it 'answers a deactivated member like an organisation outside the token: the token reaches active memberships only' do
+ # The token keeps its link when the membership is deactivated, and stops reaching the
+ # organisation (PersonalAccessToken#organisation_scopes); the right asks for an active
+ # membership (E2), so the inactive member is refused, not told "not found".
+ it 'refuses a deactivated member with 403 glossary_forbidden, through the same token as before' do
deactivated = token
ActsAsTenant.with_tenant(organisation) { Membership.find_by!(user: anna, organisation: organisation).update!(active: false) }
- expect(terms(with: deactivated)).to have_http_status(:not_found)
+ expect(terms(with: deactivated)).to have_http_status(:forbidden)
+ expect(body).to eq(forbidden_body('You may not read the glossary of this organisation.'))
+ end
+
+ it 'answers a removed membership like an organisation outside the token: the same 404' do
+ removed = token
+ Prosopite.pause do
+ ActsAsTenant.with_tenant(organisation) { Membership.find_by!(user: anna, organisation: organisation).destroy! }
+ end
+
+ expect(terms(with: removed)).to have_http_status(:not_found)
+ expect(body).to eq(not_found_body)
+ end
+
+ it 'answers a deactivated membership in an organisation the token does not name with the same 404' do
+ ActsAsTenant.with_tenant(other_organisation) do
+ Membership.find_by!(user: anna, organisation: other_organisation).update!(active: false)
+ end
+
+ expect(terms(organisation_id: other_organisation.id)).to have_http_status(:not_found)
expect(body).to eq(not_found_body)
end
diff --git a/spec/services/glossary/lookup_spec.rb b/spec/services/glossary/lookup_spec.rb
index da6955a..54321f6 100644
--- a/spec/services/glossary/lookup_spec.rb
+++ b/spec/services/glossary/lookup_spec.rb
@@ -100,12 +100,13 @@ RSpec.describe Glossary::Lookup, :ci_guard do
create(:personal_access_token, user: user, organisations: organisations, project_scopes: project_scopes)
end
- def for_token(reach, organisation_id = organisation.id)
- described_class.for_token(reach: reach, viewer: reader, organisation_id: organisation_id)
+ # A fresh instance, as the next request would load it: the reach is memoised per instance.
+ def for_token(pat, organisation_id = organisation.id)
+ described_class.for_token(token: PersonalAccessToken.find(pat.id), viewer: reader, organisation_id: organisation_id)
end
it 'opens an organisation the token reaches in every project, with no project limit' do
- found = for_token(token.reach)
+ found = for_token(token)
expect(found.organisation).to eq(organisation)
expect(found.read[:data].pluck(:term)).to eq(%w[Lalabase Nordlicht])
@@ -113,7 +114,7 @@ RSpec.describe Glossary::Lookup, :ci_guard do
end
it 'opens an organisation the token reaches in some projects, with those projects as the limit (E4)' do
- found = for_token(token(project_scopes: { organisation => [project] }).reach)
+ found = for_token(token(project_scopes: { organisation => [project] }))
expect(found.read[:data].pluck(:term)).to eq(%w[Lalabase Nordlicht])
expect(forms(found.read).pluck(:form)).to eq(['Lala Bass', 'lala bus'])
@@ -125,27 +126,46 @@ RSpec.describe Glossary::Lookup, :ci_guard do
create(:permission, role: role, category: 'glossary', action: 'view_glossary', allowed: true)
create(:membership, user: reader, organisation: other_organisation, role: role)
end
- reach = token.reach
+ pat = token
- expect(for_token(reach, other_organisation.id)).to be_nil
- expect(for_token(reach, SecureRandom.uuid)).to be_nil
- expect(for_token(reach, 'oops')).to be_nil
- expect(for_token(reach, '')).to be_nil
- expect(for_token(reach, nil)).to be_nil
+ expect(for_token(pat, other_organisation.id)).to be_nil
+ expect(for_token(pat, SecureRandom.uuid)).to be_nil
+ expect(for_token(pat, 'oops')).to be_nil
+ expect(for_token(pat, '')).to be_nil
+ expect(for_token(pat, nil)).to be_nil
end
- it 'answers nil once the membership is deactivated: the token reaches only active memberships' do
+ # The reach counts active memberships only, and the right asks for one (E2): an inactive member
+ # of an organisation the token names is refused as without the right, not told "not found".
+ it 'refuses a deactivated member of an organisation the token names, before it reads a term' do
pat = token
Membership.find_by!(user: reader, organisation: organisation).update!(active: false)
- expect(for_token(PersonalAccessToken.find(pat.id).reach)).to be_nil
+ statements = capture_sql { expect { for_token(pat) }.to raise_error(described_class::Refused) }
+ expect(statements.grep(/glossary_terms|term_corrections/)).to be_empty
+ end
+
+ it 'answers nil for a deactivated membership in an organisation the token does not name' do
+ ActsAsTenant.with_tenant(other_organisation) do
+ create(:membership, user: reader, organisation: other_organisation, role: create(:role, organisation: other_organisation),
+ active: false)
+ end
+
+ expect(for_token(token, other_organisation.id)).to be_nil
+ end
+
+ it 'answers nil once the membership is removed: no membership is no inactive member' do
+ pat = token
+ Prosopite.pause { Membership.find_by!(user: reader, organisation: organisation).destroy! }
+
+ expect(for_token(pat)).to be_nil
end
it 'reads an id in the spelling the uuid column takes, upper case or without dashes' do
- reach = token.reach
+ pat = token
- expect(for_token(reach, organisation.id.upcase).organisation).to eq(organisation)
- expect(for_token(reach, organisation.id.delete('-')).organisation).to eq(organisation)
+ expect(for_token(pat, organisation.id.upcase).organisation).to eq(organisation)
+ expect(for_token(pat, organisation.id.delete('-')).organisation).to eq(organisation)
end
end