Skip to content
8 changes: 8 additions & 0 deletions forge/routes/api/deviceLive.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,14 @@ module.exports = async function (app) {
updateSettingsForCatalogue('@flowfuse-certified-nodes', cat)
}
}
if (team.getProperty('extraCatalogues', null)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. getProperty('extraCatalogues') is the guard, but the loop reads team.TeamType.properties.extraCatalogues directly. If a team-level override ever exists, the check and the value come from different places. Use one source, e.g. const extra = team.getProperty('extraCatalogues', null) and loop over extra.
  2. Add Array.isArray(extra) and skip entries that are not valid URL strings, so bad stored data can't break the block (or add a character per iteration if it is a string).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this only runs inside the platformNPMEnabled && (certifiedNodes || ffNodes) block, but the UI disables the field based on certifiedNodes only.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this only runs inside the platformNPMEnabled && (certifiedNodes || ffNodes) block, but the UI disables the field based on certifiedNodes only.

Yes, because ffNodes adds a URL to the list, but the override box is to ONLY add more certified nodes catalogues

for (const cat of team.getProperty('extraCatalogues')) {
const catURL = new URL(cat)
if (response.palette.catalogues.indexOf(catURL.toString()) === -1) {
response.palette.catalogues.push(catURL.toString())
}
}
}
} catch (err) {
app.log.error(`Failed to configure platform npm registry for device ${err.toString()}`)
}
Expand Down
8 changes: 8 additions & 0 deletions forge/routes/api/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,14 @@ module.exports = async function (app) {
updateSettingsForCatalogue('@flowfuse-certified-nodes', cat)
}
}
if (team.getProperty('extraCatalogues', null)) {
Comment thread
hardillb marked this conversation as resolved.
Resolved
for (const cat of team.TeamType.properties.extraCatalogues) {
const catURL = new URL(cat)
if (settings.settings.palette.catalogue.indexOf(catURL.toString()) === -1) {
settings.settings.palette.catalogue.push(catURL.toString())
}
}
}
} catch (err) {
app.log.error('Failed to configure platform npm registry for project', err)
}
Expand Down
38 changes: 36 additions & 2 deletions frontend/src/pages/admin/TeamTypes/dialogs/TeamTypeEditDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@
<FormRow v-model="input.properties.features.fileStorageLimit">Persistent File storage limit (Mb)</FormRow>
<FormRow v-model="input.properties.features.contextLimit">Persistent Context storage limit (Mb)</FormRow>
</div>
<FormRow v-model="input.properties.extraCatalogues" :error="errors.extraCatalogues" :disabled="!input.properties.features.certifiedNodes" data-form="extraCatalogues" containerClass="w-full">
Extra Certified Nodes Catalogue URLs, one per line, must be https://
<template #input><textarea v-model="input.properties.extraCatalogues" class="w-full" rows="3" :disabled="!input.properties.features.certifiedNodes" /></template>
</FormRow>
Comment thread
hardillb marked this conversation as resolved.
Resolved
</form>
</template>
<template #actions>
Expand Down Expand Up @@ -336,6 +340,11 @@ export default {
this.input.autoStack.hours[`${hours[d]}`] = true
}
}
if (teamType.properties?.extraCatalogues) {
this.input.properties.extraCatalogues = teamType.properties.extraCatalogues.join('\n')
} else {
this.input.properties.extraCatalogues = ''
}
} else {
this.editDisabled = false
this.input = {
Expand All @@ -359,7 +368,8 @@ export default {
allowDisable: true,
days: [],
hours: []
}
},
extraCatalogues: ''
},
autoStack: {
days: {},
Expand Down Expand Up @@ -422,7 +432,8 @@ export default {
days: {},
hours: {}
},
enableAllFeatures: false
enableAllFeatures: false,
extraCatalogues: ''
}
},
errors: {},
Expand All @@ -440,6 +451,17 @@ export default {
})
},
formValid () {
const extraCataloguesArray = this.input.properties.extraCatalogues.split('\n').filter(cat => cat.trim().length > 0)
for (const cat of extraCataloguesArray) {
try {
const u = new URL(cat)
if (u.protocol !== 'https:') {
return false
}
} catch (err) {
return false
}
}
Comment thread
hardillb marked this conversation as resolved.
Resolved
return (this.input.name)
},
isEditingExisting () {
Expand Down Expand Up @@ -543,6 +565,18 @@ export default {
}
}

opts.properties.extraCatalogues = []
const extraCataloguesArray = this.input.properties.extraCatalogues.split('\n').filter(cat => cat.trim().length > 0)
for (const cat of extraCataloguesArray) {
try {
// eslint-disable-next-line no-unused-vars
const u = new URL(cat)
opts.properties.extraCatalogues.push(cat)
} catch (err) {
// Ignore invalid URL
}
}

if (this.teamType) {
// For edits, we cannot touch the properties
// TODO: what can be edited when in use?
Expand Down
28 changes: 28 additions & 0 deletions test/unit/forge/routes/api/device_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1907,6 +1907,34 @@ describe('Device API', async function () {
`)
})
})
describe('Extra Catalogues from TeamType', function () {
async function setTeamTypeCatalogues (cats) {
const defaultTeamTypeProperties = app.defaultTeamType.properties
defaultTeamTypeProperties.extraCatalogues = cats
app.defaultTeamType.properties = defaultTeamTypeProperties
await app.defaultTeamType.save()
}
Comment on lines +1911 to +1916

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this mutates deaullt team type. Maybe a before (to store original) and an afterEach (to reset it) is needed?

let cats
before(async function () {
const defaultTeamTypeProperties = app.defaultTeamType.properties
cats = defaultTeamTypeProperties.extraCatalogues
})
afterEach(async function () {
const defaultTeamTypeProperties = app.defaultTeamType.properties
defaultTeamTypeProperties.extraCatalogues = cats
app.defaultTeamType.properties = defaultTeamTypeProperties
await app.defaultTeamType.save()
})
it('should include catalogues from TeamType', async function () {
await setTeamTypeCatalogues([
'https://example.com/cat-from-team-type.json'
])
const device = await createDevice({ name: 'CertifiedNodes', type: '', team: TestObjects.ATeam.hashid, as: TestObjects.tokens.alice })
const liveSettings = await getLiveSettings(device)
liveSettings.palette.should.have.property('catalogues')
liveSettings.palette.catalogues.should.containEql('https://example.com/cat-from-team-type.json')
})
})
})

describe('device remote editor (unlicensed)', function () {
Expand Down
103 changes: 103 additions & 0 deletions test/unit/forge/routes/api/project_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,109 @@ describe('Project API', function () {
`)
})
})
describe('Apply TeamType extra Catalogues', function () {
async function setTeamTypeCatalogues (cats) {
const defaultTeamTypeProperties = app.defaultTeamType.properties
defaultTeamTypeProperties.extraCatalogues = cats
app.defaultTeamType.properties = defaultTeamTypeProperties

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same mutation as device tests - should we have before (to capture starting value) and afterEach (to restoire)?

await app.defaultTeamType.save()
}
let cats
before(async function () {
const defaultTeamTypeProperties = app.defaultTeamType.properties
cats = defaultTeamTypeProperties.extraCatalogues
})
afterEach(async function () {
const defaultTeamTypeProperties = app.defaultTeamType.properties
defaultTeamTypeProperties.extraCatalogues = cats
app.defaultTeamType.properties = defaultTeamTypeProperties
await app.defaultTeamType.save()
})
it('Should add extra catalogue to project', async function () {
await setTeamTypeCatalogues([
'https://example.com/team-type-cat.json'
])

const projectName = generateProjectName()
const response = await app.inject({
method: 'POST',
url: '/api/v1/projects',
payload: {
name: projectName,
applicationId: TestObjects.ApplicationA.hashid,
projectType: TestObjects.projectType1.hashid,
template: TestObjects.template1.hashid,
stack: TestObjects.stack1.hashid
},
cookies: { sid: TestObjects.tokens.alice }
})
response.statusCode.should.equal(200)
const result = response.json()

const newProject = await app.db.models.Project.byId(result.id)
const newAccessToken = (await newProject.refreshAuthTokens()).token
const runtimeSettings = (await app.inject({
method: 'GET',
url: `/api/v1/projects/${newProject.id}/settings`,
headers: {
authorization: `Bearer ${newAccessToken}`
}
})).json()

const settings = runtimeSettings.settings
settings.should.have.property('palette')
settings.palette.should.have.property('npmrc')
settings.palette.should.have.property('catalogue')
settings.palette.catalogue.should.containEql('https://example.com/team-type-cat.json')
})
it('Should add extra catalogue to project only if not present', async function () {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sends a duplicate but never asserts it appears. It splices the two entries out and then asserts cat2 is gone, which passes regardless of dedupe. I think we should assert the count of team-type-cat.json is exactly 1.

Noted the device spec has no dedupe test either.

Additionally, I think a test that uses URLs which differ only in form but resolve to the same catalogue (e.g. https://example.com/cat.json and https://EXAMPLE.com/cat.json, or https://example.com and https://example.com/) would be worthwhile. Existing entries are normalised with new URL(...).toString(), but the extra catalogues are compared and pushed as raw strings, so indexOf treats these as different and both end up in the list. Asserting that only one entry remains should fail as it stands.

await setTeamTypeCatalogues([
'https://example.com/team-type-cat.json',
'https://EXAMPLE.com/team-type-cat.json',
'https://example.com/cat2.json'
])

const projectName = generateProjectName()
const response = await app.inject({
method: 'POST',
url: '/api/v1/projects',
payload: {
name: projectName,
applicationId: TestObjects.ApplicationA.hashid,
projectType: TestObjects.projectType1.hashid,
template: TestObjects.template1.hashid,
stack: TestObjects.stack1.hashid
},
cookies: { sid: TestObjects.tokens.alice }
})
response.statusCode.should.equal(200)
const result = response.json()

const newProject = await app.db.models.Project.byId(result.id)
const newAccessToken = (await newProject.refreshAuthTokens()).token
const runtimeSettings = (await app.inject({
method: 'GET',
url: `/api/v1/projects/${newProject.id}/settings`,
headers: {
authorization: `Bearer ${newAccessToken}`
}
})).json()

const settings = runtimeSettings.settings
settings.should.have.property('palette')
settings.palette.should.have.property('npmrc')
settings.palette.should.have.property('catalogue')
settings.palette.catalogue.should.have.length(6)
settings.palette.catalogue.should.containEql('https://example.com/team-type-cat.json')
settings.palette.catalogue.should.containEql('https://example.com/cat2.json')
let index = settings.palette.catalogue.indexOf('https://example.com/team-type-cat.json')
settings.palette.catalogue.splice(index, 1)
index = settings.palette.catalogue.indexOf('https://example.com/cat2.json')
settings.palette.catalogue.splice(index, 1)
settings.palette.catalogue.should.not.containEql('https://example.com/cat2.json')
settings.palette.catalogue.should.have.length(4)
})
})
})

describe('Apply Flow Blueprint', function () {
Expand Down
Loading