-
Notifications
You must be signed in to change notification settings - Fork 13.5k
chore: migrate ldap endpoints to new API pattern #38883
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
Merged
ggazzo
merged 6 commits into
RocketChat:develop
from
smirk-dev:refactor/migrate-ldap-api-chained-pattern
Feb 25, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7fcf5fe
refactor: migrate ldap endpoints to new chained API pattern
smirk-dev bdda045
fix: address CodeRabbit review comments
smirk-dev 4f7f8af
fix: export isLdapTestSearch from rest-typings
smirk-dev 1cd0b4e
Update .changeset/refactor-ldap-api-chained-pattern.md
smirk-dev 24b5ea0
Update .changeset/refactor-ldap-api-chained-pattern.md
smirk-dev 9214827
Merge branch 'develop' into refactor/migrate-ldap-api-chained-pattern
smirk-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@rocket.chat/meteor': minor | ||
| --- | ||
|
|
||
| Migrates `ldap.testConnection` and `ldap.testSearch` REST API endpoints from legacy `addRoute` pattern to the new chained `.post()` API pattern with typed response schemas and AJV body validation (replacing Meteor `check()`). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,62 +1,86 @@ | ||
| import { LDAP } from '@rocket.chat/core-services'; | ||
| import { Match, check } from 'meteor/check'; | ||
| import { ajv, isLdapTestSearch, validateUnauthorizedErrorResponse, validateForbiddenErrorResponse } from '@rocket.chat/rest-typings'; | ||
|
|
||
| import { SystemLogger } from '../../../../server/lib/logger/system'; | ||
| import { settings } from '../../../settings/server'; | ||
| import { API } from '../api'; | ||
|
|
||
| API.v1.addRoute( | ||
| const messageResponseSchema = { | ||
| type: 'object' as const, | ||
| properties: { | ||
| message: { type: 'string' as const }, | ||
| success: { | ||
| type: 'boolean' as const, | ||
| enum: [true] as const, | ||
| }, | ||
| }, | ||
| required: ['message', 'success'] as const, | ||
| additionalProperties: false, | ||
| }; | ||
|
|
||
| API.v1.post( | ||
| 'ldap.testConnection', | ||
| { authRequired: true, permissionsRequired: ['test-admin-options'] }, | ||
| { | ||
| async post() { | ||
| if (!this.userId) { | ||
| throw new Error('error-invalid-user'); | ||
| } | ||
|
|
||
| if (settings.get<boolean>('LDAP_Enable') !== true) { | ||
| throw new Error('LDAP_disabled'); | ||
| } | ||
|
|
||
| try { | ||
| await LDAP.testConnection(); | ||
| } catch (err) { | ||
| SystemLogger.error({ err }); | ||
| throw new Error('Connection_failed'); | ||
| } | ||
|
|
||
| return API.v1.success({ | ||
| message: 'LDAP_Connection_successful' as const, | ||
| }); | ||
| authRequired: true, | ||
| permissionsRequired: ['test-admin-options'], | ||
| response: { | ||
| 200: ajv.compile<{ message: string; success: true }>(messageResponseSchema), | ||
| 401: validateUnauthorizedErrorResponse, | ||
| 403: validateForbiddenErrorResponse, | ||
| }, | ||
| }, | ||
| async function action() { | ||
| if (!this.userId) { | ||
| throw new Error('error-invalid-user'); | ||
| } | ||
|
|
||
| if (settings.get<boolean>('LDAP_Enable') !== true) { | ||
| throw new Error('LDAP_disabled'); | ||
| } | ||
|
|
||
| try { | ||
| await LDAP.testConnection(); | ||
| } catch (err) { | ||
| SystemLogger.error({ err }); | ||
| throw new Error('Connection_failed'); | ||
| } | ||
|
|
||
| return API.v1.success({ | ||
| message: 'LDAP_Connection_successful' as const, | ||
| }); | ||
| }, | ||
| ); | ||
|
|
||
| API.v1.addRoute( | ||
| API.v1.post( | ||
| 'ldap.testSearch', | ||
| { authRequired: true, permissionsRequired: ['test-admin-options'] }, | ||
| { | ||
| async post() { | ||
| check( | ||
| this.bodyParams, | ||
| Match.ObjectIncluding({ | ||
| username: String, | ||
| }), | ||
| ); | ||
|
|
||
| if (!this.userId) { | ||
| throw new Error('error-invalid-user'); | ||
| } | ||
|
|
||
| if (settings.get('LDAP_Enable') !== true) { | ||
| throw new Error('LDAP_disabled'); | ||
| } | ||
| authRequired: true, | ||
| permissionsRequired: ['test-admin-options'], | ||
| body: isLdapTestSearch, | ||
| response: { | ||
| 200: ajv.compile<{ message: string; success: true }>(messageResponseSchema), | ||
| 401: validateUnauthorizedErrorResponse, | ||
| 403: validateForbiddenErrorResponse, | ||
| }, | ||
| }, | ||
| async function action() { | ||
| if (!this.userId) { | ||
| throw new Error('error-invalid-user'); | ||
| } | ||
|
|
||
| if (settings.get<boolean>('LDAP_Enable') !== true) { | ||
| throw new Error('LDAP_disabled'); | ||
| } | ||
|
|
||
| try { | ||
| await LDAP.testSearch(this.bodyParams.username); | ||
| } catch (err) { | ||
| SystemLogger.error({ err }); | ||
| throw new Error('LDAP_search_failed'); | ||
| } | ||
|
|
||
| return API.v1.success({ | ||
| message: 'LDAP_User_Found' as const, | ||
| }); | ||
| }, | ||
| return API.v1.success({ | ||
| message: 'LDAP_User_Found' as const, | ||
| }); | ||
| }, | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.