-
Notifications
You must be signed in to change notification settings - Fork 13.5k
feat(api): migrate users.getPreferences to OpenAPI pattern #38325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 9 commits
01a8720
e5674dc
4396c0a
5664ef8
9bde0f1
e21b72c
e49b8d7
3098aaa
c5fbfcc
1da067c
0b372c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@rocket.chat/meteor': patch | ||
| --- | ||
|
|
||
| Migrated users.getPreferences to OpenAPI pattern with AJV validation | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,4 +17,4 @@ | |
| "tmid", | ||
| "tshow" | ||
| ] | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. .vscode settings is out of the scoop for this PR could you fix this |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| import { MeteorError, Team, api, Calendar } from '@rocket.chat/core-services'; | ||
|
|
||
| import type { IExportOperation, ILoginToken, IPersonalAccessToken, IUser, UserStatus } from '@rocket.chat/core-typings'; | ||
| import { Users, Subscriptions, Sessions } from '@rocket.chat/models'; | ||
| import { | ||
|
|
||
|
|
||
| isUserCreateParamsPOST, | ||
| isUserSetActiveStatusParamsPOST, | ||
| isUserDeactivateIdleParamsPOST, | ||
|
|
@@ -171,9 +174,9 @@ API.v1.addRoute( | |
| const twoFactorOptions = !userData.typedPassword | ||
| ? null | ||
| : { | ||
| twoFactorCode: userData.typedPassword, | ||
| twoFactorMethod: 'password', | ||
| }; | ||
| twoFactorCode: userData.typedPassword, | ||
| twoFactorMethod: 'password', | ||
| }; | ||
|
|
||
| await executeSaveUserProfile.call(this, this.user, userData, this.bodyParams.customFields, twoFactorOptions); | ||
|
|
||
|
|
@@ -536,10 +539,10 @@ API.v1.addRoute( | |
| const limit = | ||
| count !== 0 | ||
| ? [ | ||
| { | ||
| $limit: count, | ||
| }, | ||
| ] | ||
| { | ||
| $limit: count, | ||
| }, | ||
| ] | ||
| : []; | ||
|
|
||
| const result = await Users.col | ||
|
|
@@ -752,6 +755,21 @@ API.v1.addRoute( | |
| }, | ||
| ); | ||
|
|
||
| const UserPreferencesResponseSchema = { | ||
| type: 'object', | ||
| properties: { | ||
| preferences: { | ||
| type: 'object', | ||
| additionalProperties: true, | ||
| }, | ||
| success: { type: 'boolean', enum: [true] }, | ||
| }, | ||
| required: ['preferences', 'success'], | ||
| additionalProperties: false, | ||
| }; | ||
|
|
||
| const isUserPreferencesResponse = ajv.compile(UserPreferencesResponseSchema); | ||
|
|
||
| const usersEndpoints = API.v1 | ||
| .post( | ||
| 'users.createToken', | ||
|
|
@@ -877,26 +895,32 @@ const usersEndpoints = API.v1 | |
|
|
||
| return API.v1.success({ suggestions }); | ||
| }, | ||
| ); | ||
|
|
||
| API.v1.addRoute( | ||
| 'users.getPreferences', | ||
| { authRequired: true }, | ||
| { | ||
| async get() { | ||
| ) | ||
| .get( | ||
| 'users.getPreferences', | ||
| { | ||
| authRequired: true, | ||
| response: { | ||
| 400: validateBadRequestErrorResponse, | ||
| 401: validateUnauthorizedErrorResponse, | ||
| 200: isUserPreferencesResponse, | ||
| }, | ||
| }, | ||
| async function action() { | ||
| const user = await Users.findOneById(this.userId); | ||
|
|
||
| if (user?.settings) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||
| const { preferences = {} } = user?.settings; | ||
| preferences.language = user?.language; | ||
| const { preferences = {} } = user.settings; | ||
| preferences.language = user.language; | ||
|
|
||
| return API.v1.success({ | ||
| preferences, | ||
| }); | ||
| return API.v1.success({ preferences }); | ||
| } | ||
| return API.v1.failure(i18n.t('Accounts_Default_User_Preferences_not_available').toUpperCase()); | ||
|
|
||
| throw new Meteor.Error('error-preferences-not-found', i18n.t('Accounts_Default_User_Preferences_not_available').toUpperCase()); | ||
| }, | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| ); | ||
| ); | ||
|
|
||
| export type UsersEndpoints = ExtractRoutesFromAPI<typeof usersEndpoints>; | ||
|
|
||
| API.v1.addRoute( | ||
| 'users.forgotPassword', | ||
|
|
@@ -1554,9 +1578,7 @@ settings.watch<number>('Rate_Limiter_Limit_RegisterUser', (value) => { | |
| API.v1.updateRateLimiterDictionaryForRoute(userRegisterRoute, value); | ||
| }); | ||
|
|
||
| type UsersEndpoints = ExtractRoutesFromAPI<typeof usersEndpoints>; | ||
|
|
||
| declare module '@rocket.chat/rest-typings' { | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface | ||
| interface Endpoints extends UsersEndpoints {} | ||
|
Comment on lines
-1558
to
-1562
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this's was right, you could return it as it's |
||
| interface Endpoints extends UsersEndpoints { } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to remove the users.getPreferences from the rest-typings
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its my mistake I removed it on my machine but totally forgot to git add it before committing :) |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we use minor instead of patch anymore for this project