Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api-docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3058,7 +3058,7 @@
"Data Registry — Organizations"
],
"summary": "Lists registry organizations for Secretariat or overseeing Root users",
"description": " <p><b>Related legacy endpoint:</b> <a href='#/Legacy%20%E2%80%94%20Organizations/orgAll'>GET /org</a>. Data Registry responses use long_name and an authority array; legacy responses use name and authority.active_roles.</p> <h2>Access Control</h2> <p>User must belong to an organization with SECRETARIAT or ROOT authority. Both ordinary Root users and Root administrators have access.</p> <h2>Expected Behavior</h2> <p><b>Secretariat:</b> Retrieves information about all registry organizations.</p> <p><b>Root and top-level Root users:</b> 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.</p> <p>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.</p>",
"description": " <p><b>Related legacy endpoint:</b> <a href='#/Legacy%20%E2%80%94%20Organizations/orgAll'>GET /org</a>. Data Registry responses use long_name and an authority array; legacy responses use name and authority.active_roles.</p> <h2>Access Control</h2> <p>User must belong to an organization with SECRETARIAT or ROOT authority. Both ordinary Root users and Root administrators have access.</p> <h2>Expected Behavior</h2> <p><b>Secretariat:</b> Retrieves information about all registry organizations.</p> <p><b>Root and top-level Root users:</b> 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.</p> <p>Root users and administrators can read public conversation messages on their own organization. Descendant records omit the optional conversation field.</p> <p>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.</p>",
"operationId": "registryOrgAll",
"parameters": [
{
Expand Down Expand Up @@ -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": " <p><b>Related legacy endpoint:</b> <a href='#/Legacy%20%E2%80%94%20Organizations/orgSingle'>GET /org/{shortname}</a>. Data Registry responses use long_name and an authority array; legacy responses use name and authority.active_roles.</p> <h2>Access Control</h2> <p>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.</p> <h2>Expected Behavior</h2> <p><b>Regular, CNA & Admin Users:</b> Retrieves registry organization record for the specified shortname or UUID if it is the user's organization</p> <p><b>Secretariat:</b> Retrieves information about any registry organization</p> <p>The reports_to, top_level_root, and oversees relationship fields contain organization short names.</p> <p>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.</p>",
"description": " <p><b>Related legacy endpoint:</b> <a href='#/Legacy%20%E2%80%94%20Organizations/orgSingle'>GET /org/{shortname}</a>. Data Registry responses use long_name and an authority array; legacy responses use name and authority.active_roles.</p> <h2>Access Control</h2> <p>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.</p> <h2>Expected Behavior</h2> <p><b>Regular, CNA & Admin Users:</b> Retrieves registry organization record for the specified shortname or UUID if it is the user's organization</p> <p><b>Secretariat:</b> Retrieves information about any registry organization</p> <p>Root users and administrators can read public conversation messages on their own organization. Descendant records omit the optional conversation field.</p> <p>The reports_to, top_level_root, and oversees relationship fields contain organization short names.</p> <p>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.</p>",
"operationId": "registryOrgSingle",
"parameters": [
{
Expand Down
2 changes: 2 additions & 0 deletions src/controller/registry.controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ router.get('/registry/org',
<h2>Expected Behavior</h2>
<p><b>Secretariat:</b> Retrieves information about all registry organizations.</p>
<p><b>Root and top-level Root users:</b> 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.</p>
<p>Root users and administrators can read public conversation messages on their own organization. Descendant records omit the optional conversation field.</p>
<p>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.</p>"
#swagger.parameters['$ref'] = [
'#/components/parameters/pageQuery',
Expand Down Expand Up @@ -488,6 +489,7 @@ router.get('/registry/org/:identifier',
<h2>Expected Behavior</h2>
<p><b>Regular, CNA & Admin Users:</b> Retrieves registry organization record for the specified shortname or UUID if it is the user's organization</p>
<p><b>Secretariat:</b> Retrieves information about any registry organization</p>
<p>Root users and administrators can read public conversation messages on their own organization. Descendant records omit the optional conversation field.</p>
<p>The reports_to, top_level_root, and oversees relationship fields contain organization short names.</p>
<p>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.</p>"
#swagger.parameters['expand'] = {
Expand Down
22 changes: 14 additions & 8 deletions src/controller/registry.controller/org.registry.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
85 changes: 70 additions & 15 deletions test/integration-tests/registry-org/rootReadAccessTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}`,
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
})

Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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)
Expand All @@ -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'))
Expand Down Expand Up @@ -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)
Expand Down
Loading
Loading