-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
[NEW] REST API to use Spotlight #9509
Changes from 5 commits
c8c239e
8ab094a
bf85c6d
39956cd
47e0d05
a5407af
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,28 @@ | ||
/** | ||
This API returns the result of a query of rooms | ||
and users, using Meteor's Spotlight method. | ||
|
||
Method: GET | ||
Route: api/v1/spotlight | ||
Query params: | ||
- query: The term to be searched. | ||
*/ | ||
RocketChat.API.v1.addRoute('spotlight', { authRequired: true }, { | ||
get() { | ||
check(this.queryParams, { | ||
query: String | ||
}); | ||
|
||
const { query } = this.queryParams; | ||
|
||
let result; | ||
Meteor.runAsUser(this.userId, () => | ||
result = Meteor.call('spotlight', query, null, { | ||
rooms: true, | ||
users: true | ||
}) | ||
); | ||
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. @RocketChat/core For some reason, this method ALWAYS returns curl -X GET -H "X-Auth-Token: 6eWs4ECxUITYYoZ_bAYK5OE2srkxAepQqQA1cGGv3jK" -H "X-User-Id: hvzu8z6mHFigiXy6Y" http://localhost:3000/api/v1/spotlight?query=t And I do have a room with the name of 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. The query must be a valid json object. 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. @graywolf336 What do you mean? It works for users... do you have an example of how it should be? 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. Never mind, I thought you was doing something else. Ignore my comment. 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. @rafaelks If you call it via DDP it returns data for rooms? 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. @rodrigok How can I do that? 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. Exactly as you wrote for the server side call, but from you browser (logged in)
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. Per our chat, the API is correct & it's not returning the objects because user already joined the rooms. |
||
|
||
return RocketChat.API.v1.success(result); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* eslint-env mocha */ | ||
/* globals expect */ | ||
|
||
import {getCredentials, api, request, credentials } from '../../data/api-data.js'; | ||
|
||
describe('[Spotlight]', function() { | ||
this.retries(0); | ||
|
||
before(done => getCredentials(done)); | ||
|
||
describe('[/spotlight]', () => { | ||
it('should fail when does not have query param', (done) => { | ||
request.get(api('spotlight')) | ||
.set(credentials) | ||
.expect('Content-Type', 'application/json') | ||
.expect(400) | ||
.expect((res) => { | ||
expect(res.body).to.have.property('success', false); | ||
expect(res.body).to.have.property('error'); | ||
}) | ||
.end(done); | ||
}); | ||
|
||
it('should return objects for a valid query param', (done) => { | ||
request.get(api('spotlight')) | ||
.query({ | ||
query: 'foobar' | ||
}) | ||
.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('users').that.have.lengthOf(0); | ||
expect(res.body).to.have.property('rooms').that.have.lengthOf(0); | ||
}) | ||
.end(done); | ||
}); | ||
}); | ||
}); |
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.
@MarcosSpessatto change to use result from
Meteor.runAsUser
return