Skip to content

Commit

Permalink
fix: Allow users to fetch the packageValue of settings on `/setting…
Browse files Browse the repository at this point in the history
…s` endpoint (#34864)
  • Loading branch information
KevLehman authored Jan 14, 2025
1 parent 88be133 commit 1f54b73
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/friendly-kings-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/rest-typings": patch
---

Allows users to fetch the `packageValue` of settings when calling `/settings` endpoint via `includeDefaults` query param.
9 changes: 8 additions & 1 deletion apps/meteor/app/api/server/v1/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
isSettingsUpdatePropsActions,
isSettingsUpdatePropsColor,
isSettingsPublicWithPaginationProps,
isSettingsGetParams,
} from '@rocket.chat/rest-typings';
import { Meteor } from 'meteor/meteor';
import type { FindOptions } from 'mongodb';
Expand Down Expand Up @@ -131,9 +132,10 @@ API.v1.addRoute(

API.v1.addRoute(
'settings',
{ authRequired: true },
{ authRequired: true, validateParams: isSettingsGetParams },
{
async get() {
const { includeDefaults } = this.queryParams;
const { offset, count } = await getPaginationItems(this.queryParams);
const { sort, fields, query } = await this.parseJsonQuery();

Expand All @@ -147,6 +149,11 @@ API.v1.addRoute(

ourQuery = Object.assign({}, query, ourQuery);

// Note: change this when `fields` gets removed
if (includeDefaults) {
fields.packageValue = 1;
}

const { settings, totalCount: total } = await fetchSettings(ourQuery, sort, offset, count, fields);

return API.v1.success({
Expand Down
14 changes: 14 additions & 0 deletions apps/meteor/tests/end-to-end/api/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ describe('[Settings]', () => {
})
.end(done);
});
it('should return the default values of the settings when includeDefaults is true', async () => {
return request
.get(api('settings'))
.query({ includeDefaults: true })
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('settings');
expect(res.body).to.have.property('count');
expect(res.body.settings[0]).to.have.property('packageValue');
});
});
});

describe('[/settings/:_id]', () => {
Expand Down
32 changes: 31 additions & 1 deletion packages/rest-typings/src/v1/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,36 @@ const SettingsPublicWithPaginationSchema = {

export const isSettingsPublicWithPaginationProps = ajv.compile<SettingsPublicWithPaginationProps>(SettingsPublicWithPaginationSchema);

type SettingsGetParams = PaginatedRequest<{ includeDefaults?: boolean; query?: string }>;

const SettingsGetSchema = {
type: 'object',
properties: {
includeDefaults: {
type: 'boolean',
},
count: {
type: 'number',
},
offset: {
type: 'number',
},
sort: {
type: 'string',
},
fields: {
type: 'string',
},
query: {
type: 'string',
},
},
required: [],
additionalProperties: false,
};

export const isSettingsGetParams = ajv.compile<SettingsGetParams>(SettingsGetSchema);

export type SettingsEndpoints = {
'/v1/settings.public': {
GET: (params: SettingsPublicWithPaginationProps) => PaginatedResult & {
Expand All @@ -75,7 +105,7 @@ export type SettingsEndpoints = {
};

'/v1/settings': {
GET: () => {
GET: (params: SettingsGetParams) => {
settings: ISetting[];
};
};
Expand Down

0 comments on commit 1f54b73

Please sign in to comment.