diff --git a/api-docs/openapi.json b/api-docs/openapi.json index f19af78f8..0023ed518 100644 --- a/api-docs/openapi.json +++ b/api-docs/openapi.json @@ -3058,7 +3058,7 @@ "Data Registry — Organizations" ], "summary": "Lists registry organizations for Secretariat or overseeing Root users", - "description": "
Related legacy endpoint: GET /org. Data Registry responses use long_name and an authority array; legacy responses use name and authority.active_roles.
User must belong to an organization with SECRETARIAT or ROOT authority. Both ordinary Root users and Root administrators have access.
Secretariat: Retrieves information about all registry organizations.
Root and top-level Root users: Retrieves a flat list containing the requesting organization itself and all direct and indirect descendants, including subordinate Roots and organizations beneath them. Ancestors, sibling branches, and unrelated organizations are excluded. A Root without descendants receives only its own organization.
Results use existing non-Secretariat field filtering and are sorted by short_name. Pagination and totalCount apply only to organizations within the authorized scope. Authorization uses current ROOT authority and reporting relationships.
", + "description": "Related legacy endpoint: GET /org. Data Registry responses use long_name and an authority array; legacy responses use name and authority.active_roles.
User must belong to an organization with SECRETARIAT or ROOT authority. Both ordinary Root users and Root administrators have access.
Secretariat: Retrieves information about all registry organizations.
Root and top-level Root users: Retrieves a flat list containing the requesting organization itself and all direct and indirect descendants, including subordinate Roots and organizations beneath them. Ancestors, sibling branches, and unrelated organizations are excluded. A Root without descendants receives only its own organization.
Root users and administrators can read public conversation messages on their own organization. Descendant records omit the optional conversation field.
Results use existing non-Secretariat field filtering and are sorted by short_name. Pagination and totalCount apply only to organizations within the authorized scope. Authorization uses current ROOT authority and reporting relationships.
", "operationId": "registryOrgAll", "parameters": [ { @@ -3708,7 +3708,7 @@ "Data Registry — Organizations" ], "summary": "Retrieves registry organization information by short name or UUID (same-organization users, overseeing Root users, or Secretariat)", - "description": "Related legacy endpoint: GET /org/{shortname}. Data Registry responses use long_name and an authority array; legacy responses use name and authority.active_roles.
Authenticated users can access their own organization. Ordinary users and administrators in an organization with ROOT authority can also access direct and indirect descendants, including organizations beneath subordinate Roots, using current reporting relationships. Secretariat users can access any organization.
Regular, CNA & Admin Users: Retrieves registry organization record for the specified shortname or UUID if it is the user's organization
Secretariat: Retrieves information about any registry organization
The reports_to, top_level_root, and oversees relationship fields contain organization short names.
The _hierarchy array contains the ancestor path from the top-level Root to the requested organization and that organization's complete subtree. Ancestors include only the child on that path and do not grant access to ancestor organization or user records. Siblings and unrelated branches remain outside Root oversight. Nodes contain UUID, short_name, long_name, authority, and children. ROOT nodes also contain is_top_level_root, and CNA nodes contain is_last_resort. An organization without a parent begins its own tree.
", + "description": "Related legacy endpoint: GET /org/{shortname}. Data Registry responses use long_name and an authority array; legacy responses use name and authority.active_roles.
Authenticated users can access their own organization. Ordinary users and administrators in an organization with ROOT authority can also access direct and indirect descendants, including organizations beneath subordinate Roots, using current reporting relationships. Secretariat users can access any organization.
Regular, CNA & Admin Users: Retrieves registry organization record for the specified shortname or UUID if it is the user's organization
Secretariat: Retrieves information about any registry organization
Root users and administrators can read public conversation messages on their own organization. Descendant records omit the optional conversation field.
The reports_to, top_level_root, and oversees relationship fields contain organization short names.
The _hierarchy array contains the ancestor path from the top-level Root to the requested organization and that organization's complete subtree. Ancestors include only the child on that path and do not grant access to ancestor organization or user records. Siblings and unrelated branches remain outside Root oversight. Nodes contain UUID, short_name, long_name, authority, and children. ROOT nodes also contain is_top_level_root, and CNA nodes contain is_last_resort. An organization without a parent begins its own tree.
", "operationId": "registryOrgSingle", "parameters": [ { diff --git a/src/controller/registry.controller/index.js b/src/controller/registry.controller/index.js index d2ace7007..87cf14563 100644 --- a/src/controller/registry.controller/index.js +++ b/src/controller/registry.controller/index.js @@ -26,6 +26,7 @@ router.get('/registry/org',Secretariat: Retrieves information about all registry organizations.
Root and top-level Root users: Retrieves a flat list containing the requesting organization itself and all direct and indirect descendants, including subordinate Roots and organizations beneath them. Ancestors, sibling branches, and unrelated organizations are excluded. A Root without descendants receives only its own organization.
+Root users and administrators can read public conversation messages on their own organization. Descendant records omit the optional conversation field.
Results use existing non-Secretariat field filtering and are sorted by short_name. Pagination and totalCount apply only to organizations within the authorized scope. Authorization uses current ROOT authority and reporting relationships.
" #swagger.parameters['$ref'] = [ '#/components/parameters/pageQuery', @@ -488,6 +489,7 @@ router.get('/registry/org/:identifier',Regular, CNA & Admin Users: Retrieves registry organization record for the specified shortname or UUID if it is the user's organization
Secretariat: Retrieves information about any registry organization
+Root users and administrators can read public conversation messages on their own organization. Descendant records omit the optional conversation field.
The reports_to, top_level_root, and oversees relationship fields contain organization short names.
The _hierarchy array contains the ancestor path from the top-level Root to the requested organization and that organization's complete subtree. Ancestors include only the child on that path and do not grant access to ancestor organization or user records. Siblings and unrelated branches remain outside Root oversight. Nodes contain UUID, short_name, long_name, authority, and children. ROOT nodes also contain is_top_level_root, and CNA nodes contain is_last_resort. An organization without a parent begins its own tree.
" #swagger.parameters['expand'] = { diff --git a/src/controller/registry.controller/org.registry.controller.js b/src/controller/registry.controller/org.registry.controller.js index 94d06dda7..e78f5265f 100644 --- a/src/controller/registry.controller/org.registry.controller.js +++ b/src/controller/registry.controller/org.registry.controller.js @@ -146,9 +146,13 @@ async function getAllOrgs (req, res, next) { try { returnValue = await repo.getAllOrgs({ ...options }, REGISTRY_FORMAT, isSecretariat, orgUUIDs) - for (let i = 0; i < returnValue.organizations.length; i++) { - const conversation = await conversationRepo.getAllByTargetUUID(returnValue.organizations[i].UUID, isSecretariat) - returnValue.organizations[i].conversation = conversation?.length + for (const org of returnValue.organizations) { + if (!isSecretariat && org.UUID !== hierarchyScope) { + delete org.conversation + continue + } + const conversation = await conversationRepo.getAllByTargetUUID(org.UUID, isSecretariat) + org.conversation = conversation?.length ? (isSecretariat ? conversation : conversation.map(c => _.omit(c, NON_SECRETARIAT_CONVERSATION_FIELDS))) : undefined } @@ -295,12 +299,14 @@ async function getOrg (req, res, next) { isAdminOfRequestedOrg = await userRepo.isAdmin(req.ctx.user, returnValue.short_name, {}) } - // fetch conversation - const conversation = await conversationRepo.getAllByTargetUUID(returnValue.UUID, isSecretariat) - if (isSecretariat) { - returnValue.conversation = conversation?.length ? _.map(conversation, c => _.omit(c, ['__v', '_id', 'previous_conversation_uuid', 'next_conversation_uuid', 'target_uuid'])) : undefined + if (isSecretariat || reason === 'SAME_ORG') { + const conversation = await conversationRepo.getAllByTargetUUID(returnValue.UUID, isSecretariat) + const fieldsToOmit = isSecretariat + ? ['__v', '_id', 'previous_conversation_uuid', 'next_conversation_uuid', 'target_uuid'] + : NON_SECRETARIAT_CONVERSATION_FIELDS + returnValue.conversation = conversation?.length ? conversation.map(c => _.omit(c, fieldsToOmit)) : undefined } else { - returnValue.conversation = conversation?.length ? _.map(conversation, c => _.omit(c, NON_SECRETARIAT_CONVERSATION_FIELDS)) : undefined + delete returnValue.conversation } if (req.ctx.query?.expand === 'users') { diff --git a/test/integration-tests/registry-org/advisoryLocationsTextTest.js b/test/integration-tests/registry-org/advisoryLocationsTextTest.js index 2956b3d21..60e3e57cc 100644 --- a/test/integration-tests/registry-org/advisoryLocationsTextTest.js +++ b/test/integration-tests/registry-org/advisoryLocationsTextTest.js @@ -13,7 +13,8 @@ const shortName = `advisory_text_${randomUUID().slice(0, 8)}` const headers = { ...constants.headers, 'content-type': 'application/json' } describe('Advisory locations text', () => { - context('Migration', () => { + context('Migration', function () { + this.timeout(30000) let db before(async () => { diff --git a/test/integration-tests/registry-org/rootReadAccessTest.js b/test/integration-tests/registry-org/rootReadAccessTest.js index f557a2bde..53d2cedce 100644 --- a/test/integration-tests/registry-org/rootReadAccessTest.js +++ b/test/integration-tests/registry-org/rootReadAccessTest.js @@ -64,6 +64,21 @@ describe('Root oversight registry read access', () => { return response.body } + function expectPublicConversation (org, label) { + expect(org.conversation.map(message => message.body)).to.deep.equal([ + `${label} partner ${runId}`, `${label} public ${runId}` + ]) + const [partnerMessage, secretariatReply] = org.conversation + expect(partnerMessage.author_id).to.equal(users[`${label}Admin`].UUID) + expect(secretariatReply).to.not.have.property('author_id') + expect(secretariatReply).to.not.have.property('author_name') + for (const message of org.conversation) { + for (const field of ['_id', '__v', 'UUID', 'target_uuid', 'visibility', 'previous_conversation_uuid', 'next_conversation_uuid']) { + expect(message).to.not.have.property(field) + } + } + } + async function expectUserList (requestHeaders, labels, extraUsers = []) { const response = await chai.request(app).get('/api/registry/users').set(requestHeaders) expect(response).to.have.status(200) @@ -82,8 +97,8 @@ describe('Root oversight registry read access', () => { before(async function () { this.timeout(fixtureTimeoutMs) - for (const label of ['top', 'root', 'branch', 'cna', 'peer', 'other']) { - const isRoot = label !== 'cna' + for (const label of ['top', 'root', 'branch', 'cna', 'peer', 'other', 'secondCna']) { + const isRoot = !['cna', 'secondCna'].includes(label) const response = await chai.request(app).post('/api/registry/org').set(secretariat).send({ short_name: `read_${label}_${runId}`, long_name: `Root read access ${label}`, @@ -121,10 +136,13 @@ describe('Root oversight registry read access', () => { expect(peerOnly).to.have.status(200) users.peerOnly = peerOnly.body.created createdUsers.push({ shortName: orgs.peer.short_name, username: users.peerOnly.username }) - for (const label of ['root', 'cna']) { + for (const label of ['root', 'cna', 'secondCna']) { + const partnerMessage = await chai.request(app).post(`/api/conversation/target/${orgs[label].UUID}`) + .set(headers(label, true)).send({ body: `${label} partner ${runId}` }) + expect(partnerMessage).to.have.status(200) for (const visibility of ['public', 'private']) { const response = await chai.request(app).post(`/api/conversation/target/${orgs[label].UUID}`) - .set(secretariat).send({ visibility, body: `${visibility} Root list ${runId}` }) + .set(secretariat).send({ visibility, body: `${label} ${visibility} ${runId}` }) expect(response).to.have.status(200) } } @@ -171,6 +189,7 @@ describe('Root oversight registry read access', () => { expect(Object.keys(response.body._userMap)).to.have.members([users.cna.UUID, users.cnaAdmin.UUID]) expect(response.body._userMap[users.cna.UUID].org.short_name).to.equal(orgs.cna.short_name) expect(response.body).to.not.have.property('program_data') + expect(response.body).to.not.have.property('conversation') expect(JSON.stringify(response.body)).to.not.include(users.cna.secret) }) @@ -209,16 +228,40 @@ describe('Root oversight registry read access', () => { await expectUserList(headers('peer', admin), ['peer']) }) - it('applies non-Secretariat conversation filtering to own and descendant list entries', async () => { + it('shows public messages on the Root’s own record and omits descendant conversations', async () => { const payload = await expectOrgList(headers('root', admin), ['root', 'branch', 'cna']) - for (const label of ['root', 'cna']) { - const org = payload.organizations.find(org => org.UUID === orgs[label].UUID) - expect(org.conversation).to.have.lengthOf(1) - expect(org.conversation[0].body).to.equal(`public Root list ${runId}`) - for (const field of ['_id', '__v', 'UUID', 'target_uuid', 'visibility', 'previous_conversation_uuid', 'next_conversation_uuid', 'author_id', 'author_name']) { - expect(org.conversation[0]).to.not.have.property(field) - } + const own = payload.organizations.find(org => org.UUID === orgs.root.UUID) + expectPublicConversation(own, 'root') + const detail = await chai.request(app).get(`/api/registry/org/${orgs.root.short_name}`).set(headers('root', admin)) + expect(detail).to.have.status(200) + expect(detail.body.conversation).to.deep.equal(own.conversation) + for (const org of payload.organizations.filter(org => org.UUID !== own.UUID)) { + expect(org).to.not.have.property('conversation') + } + const direct = await chai.request(app).get(`/api/registry/org/${orgs.cna.UUID}`).set(headers('branch', admin)) + expect(direct).to.have.status(200) + expect(direct.body.UUID).to.equal(orgs.cna.UUID) + expect(direct.body).to.not.have.property('conversation') + }) + + it('keeps each CNA’s public conversation visible only on its own organization reads', async () => { + for (const label of ['cna', 'secondCna']) { + const own = await chai.request(app).get(`/api/registry/org/${orgs[label].UUID}`).set(headers(label, admin)) + expect(own).to.have.status(200) + expectPublicConversation(own.body, label) } + const other = await chai.request(app).get(`/api/registry/org/${orgs.secondCna.short_name}`).set(headers('cna', admin)) + expect(other).to.have.status(403) + const list = await chai.request(app).get('/api/registry/org').set(headers('cna', admin)) + expect(list).to.have.status(403) + }) + + it('delivers the Root’s public reply only to its own organization among the partners in the tree', async () => { + const inbox = await chai.request(app).get('/api/notification').set(headers('root', admin)) + expect(inbox).to.have.status(200) + const bodies = inbox.body.notifications.map(notification => notification.body) + expect(bodies).to.include(`root public ${runId}`) + expect(bodies).to.not.include(`cna public ${runId}`) }) it('retains legacy global user list and write restrictions', async () => { @@ -259,7 +302,7 @@ describe('Root oversight registry read access', () => { }) } - it('paginates and counts own and descendant users together', async () => { + it('paginates and counts organizations and users in the Root subtree', async () => { const paginatedApp = express() paginatedApp.set('query parser', 'extended') paginatedApp.use(middleware.createCtxAndReqUUID) @@ -271,6 +314,15 @@ describe('Root oversight registry read access', () => { paginatedApp.use(middleware.errorHandler) await withHttpServer(paginatedApp, async url => { + const page = await chai.request(url).get('/api/registry/org?page=1').set(headers('top')) + expect(page).to.have.status(200) + expect(page.body.totalCount).to.equal(5) + expect(page.body.nextPage).to.equal(2) + expect(page.body.organizations.map(org => org.UUID)).to.deep.equal([ + orgs.branch.UUID, orgs.cna.UUID, orgs.peer.UUID, orgs.root.UUID + ]) + page.body.organizations.forEach(org => expect(org).to.not.have.property('conversation')) + const returnedUUIDs = [] for (const page of [1, 2, 3]) { const response = await chai.request(url).get(`/api/registry/users?page=${page}`).set(headers('root')) @@ -355,8 +407,11 @@ describe('Root oversight registry read access', () => { await expectReads(headers('cna'), 'branch', 403) const hierarchy = await chai.request(app).get('/api/registry/org-hierarchy').set(headers('cna')) expect(hierarchy).to.have.status(403) - const list = await chai.request(app).get('/api/registry/org').set(headers('cna')) - expect(list).to.have.status(403) + const detail = await chai.request(app).get(`/api/registry/org/${orgs.cna.UUID}`).set(secretariat) + expect(detail).to.have.status(200) + expect(detail.body.conversation.map(message => message.body)).to.deep.equal([ + `cna partner ${runId}`, `cna public ${runId}`, `cna private ${runId}` + ]) for (const admin of [false, true]) { const userList = await chai.request(app).get('/api/registry/users').set(headers('cna', admin)) expect(userList).to.have.status(403) diff --git a/test/unit-tests/middleware/registryReadAccessTest.js b/test/unit-tests/middleware/registryReadAccessTest.js index 3542f36a4..9c38dcecc 100644 --- a/test/unit-tests/middleware/registryReadAccessTest.js +++ b/test/unit-tests/middleware/registryReadAccessTest.js @@ -7,7 +7,7 @@ const BaseOrgModel = require('../../../src/model/baseorg') const { ORG_HIERARCHY, ALL_ORGS } = require('../../../src/controller/registry.controller/org.registry.controller') describe('Registry read authorization', () => { - let req, res, next, orgRepo, find + let req, res, next, orgRepo, conversationRepo, find beforeEach(() => { const organizations = [ @@ -27,6 +27,7 @@ describe('Registry read authorization', () => { getAllOrgs: sinon.stub().resolves({ organizations: [] }), getOrgHierarchy: BaseOrgRepository.prototype.getOrgHierarchy } + conversationRepo = { getAllByTargetUUID: sinon.stub().resolves([]) } req = { ctx: { authenticated: true, @@ -37,7 +38,7 @@ describe('Registry read authorization', () => { query: {}, repositories: { getBaseOrgRepository: () => orgRepo, - getConversationRepository: () => ({ getAllByTargetUUID: sinon.stub().resolves([]) }) + getConversationRepository: () => conversationRepo } } } @@ -138,15 +139,27 @@ describe('Registry read authorization', () => { }) it('passes the authenticated Root UUID and its descendants to the organization list query', async () => { + orgRepo.getAllOrgs.resolves({ organizations: [{ UUID: 'root' }, { UUID: 'child', conversation: [{ body: 'Stored message' }] }] }) await middleware.authorizeRegistryHierarchyRead(req, res, next) await ALL_ORGS(req, res, next) expect(res.status.calledOnceWith(200)).to.equal(true) expect(orgRepo.getAllOrgs.firstCall.args[2]).to.equal(false) expect(orgRepo.getAllOrgs.firstCall.args[3]).to.have.members(['root', 'branch', 'child']) + expect(conversationRepo.getAllByTargetUUID.calledOnceWithExactly('root', false)).to.equal(true) + expect(res.json.firstCall.args[0].organizations[1]).to.deep.equal({ UUID: 'child' }) expect(find.calledOnce).to.equal(true) expect(orgRepo.findOneByShortName.called).to.equal(false) }) + it('skips conversation reads on an organization page containing only descendants', async () => { + orgRepo.getAllOrgs.resolves({ organizations: [{ UUID: 'child' }], currentPage: 2, totalCount: 3 }) + req.ctx.query.page = '2' + await middleware.authorizeRegistryHierarchyRead(req, res, next) + await ALL_ORGS(req, res, next) + expect(res.json.firstCall.args[0]).to.deep.equal({ organizations: [{ UUID: 'child' }], currentPage: 2, totalCount: 3 }) + expect(conversationRepo.getAllByTargetUUID.notCalled).to.equal(true) + }) + it('scopes a Root without descendants to its own organization', async () => { req.ctx.orgUUID = 'sibling' await middleware.authorizeRegistryHierarchyRead(req, res, next) @@ -174,11 +187,16 @@ describe('Registry read authorization', () => { it('preserves the Secretariat organization list without a descendant filter', async () => { orgRepo.findOneByUUID.withArgs('root').resolves({ UUID: 'root', authority: ['SECRETARIAT'] }) + orgRepo.getAllOrgs.resolves({ organizations: [{ UUID: 'child' }] }) + const messages = [{ body: 'Secretariat note', visibility: 'private' }] + conversationRepo.getAllByTargetUUID.resolves(messages) await middleware.authorizeRegistryHierarchyRead(req, res, next) await ALL_ORGS(req, res, next) expect(res.status.calledOnceWith(200)).to.equal(true) expect(orgRepo.getAllOrgs.firstCall.args[2]).to.equal(true) expect(orgRepo.getAllOrgs.firstCall.args[3]).to.equal(undefined) + expect(conversationRepo.getAllByTargetUUID.calledOnceWithExactly('child', true)).to.equal(true) + expect(res.json.firstCall.args[0].organizations[0].conversation).to.deep.equal(messages) expect(find.called).to.equal(false) }) }) diff --git a/test/unit-tests/org/registry/registryOrgGetSingleTest.js b/test/unit-tests/org/registry/registryOrgGetSingleTest.js index b0a188f82..675f4643b 100644 --- a/test/unit-tests/org/registry/registryOrgGetSingleTest.js +++ b/test/unit-tests/org/registry/registryOrgGetSingleTest.js @@ -154,6 +154,15 @@ describe('Testing the GET /registry/org/:identifier endpoint in Registry Org Con expect(json.firstCall.args[0]).to.not.have.property('_relatedOrganizations') }) + it('omits stored conversation data and skips the conversation query for an overseeing Root', async () => { + req.ctx.registryRead = { targetOrg, isSecretariat: false, reason: 'PARENT_ORG' } + orgRepo.getOrg.resolves({ ...targetOrg, conversation: conversations }) + await SINGLE_ORG(req, res, next) + expect(status.calledOnceWithExactly(200)).to.be.true + expect(json.firstCall.args[0]).to.not.have.property('conversation') + expect(conversationRepo.getAllByTargetUUID.notCalled).to.be.true + }) + it('does not query a hierarchy for an organization that does not exist', async () => { orgRepo.getOrg.resolves(null)