-
Notifications
You must be signed in to change notification settings - Fork 11.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] Add new API endpoints #8947
Merged
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4b7a13f
Add subscriptions.get and rooms.get APIs
rodrigok 0c1b318
Add support to 2FA in API
rodrigok b43975d
Add API service.configurations
rodrigok db7ae97
Add API settings.public
rodrigok 4a92810
Add API DELETE push.token/:token
rodrigok 677b9fc
Add API rooms.upload/:rid
rodrigok 75a4a62
Add chat.search, chat.sendMessage, POST push.token, fix DELETE push.t…
graywolf336 06ddcc2
Improve API login endpoint to be compatible with DDP
rodrigok 87a0047
Merge remote-tracking branch 'origin/develop' into improvements/mobil…
rodrigok a705572
Add tests for new API login options
rodrigok 7b6e93e
Add tests for new APIs
rodrigok 004bb4a
Merge branch 'develop' into improvements/mobile-api
rodrigok 5bd2cb3
Remove expiration of API tokens to keep old behavior
rodrigok 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 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
This file contains 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
This file contains 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,22 @@ | ||
/* globals Push */ | ||
|
||
RocketChat.API.v1.addRoute('push.token/:token', { authRequired: true }, { | ||
delete() { | ||
const affectedRecords = Push.appCollection.remove({ | ||
$or: [{ | ||
apn: this.urlParams._id | ||
}, { | ||
gcm: this.urlParams._id | ||
}], | ||
userId: this.userId | ||
}); | ||
|
||
if (affectedRecords === 0) { | ||
return { | ||
statusCode: 404 | ||
}; | ||
} | ||
|
||
return RocketChat.API.v1.success(); | ||
} | ||
}); |
This file contains 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,91 @@ | ||
RocketChat.API.v1.addRoute('rooms.get', { authRequired: true }, { | ||
get: { | ||
//This is defined as such only to provide an example of how the routes can be defined :X | ||
action() { | ||
let updatedAt; | ||
|
||
if (typeof this.queryParams.updatedAt === 'string') { | ||
try { | ||
updatedAt = new Date(this.queryParams.updatedAt); | ||
|
||
if (updatedAt.toString() === 'Invalid Date') { | ||
return RocketChat.API.v1.failure('Invalid date for `updatedAt`'); | ||
} | ||
} catch (error) { | ||
return RocketChat.API.v1.failure('Invalid date for `updatedAt`'); | ||
} | ||
} | ||
|
||
return Meteor.runAsUser(this.userId, () => { | ||
return RocketChat.API.v1.success(Meteor.call('rooms/get', updatedAt)); | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
RocketChat.API.v1.addRoute('rooms.upload/:rid', { authRequired: true }, { | ||
post() { | ||
const room = Meteor.call('canAccessRoom', this.urlParams.rid, this.userId); | ||
|
||
if (!room) { | ||
return RocketChat.API.v1.unauthorized(); | ||
} | ||
|
||
const Busboy = Npm.require('busboy'); | ||
const busboy = new Busboy({ headers: this.request.headers }); | ||
const files = []; | ||
const fields = {}; | ||
|
||
Meteor.wrapAsync((callback) => { | ||
busboy.on('file', (fieldname, file, filename, encoding, mimetype) => { | ||
if (fieldname !== 'file') { | ||
return files.push(new Meteor.Error('invalid-field')); | ||
} | ||
|
||
const fileDate = []; | ||
file.on('data', data => fileDate.push(data)); | ||
|
||
file.on('end', () => { | ||
files.push({ fieldname, file, filename, encoding, mimetype, fileBuffer: Buffer.concat(fileDate) }); | ||
}); | ||
}); | ||
|
||
busboy.on('field', (fieldname, value) => fields[fieldname] = value); | ||
|
||
busboy.on('finish', Meteor.bindEnvironment(() => callback())); | ||
|
||
this.request.pipe(busboy); | ||
})(); | ||
|
||
if (files.length === 0) { | ||
return RocketChat.API.v1.failure('File required'); | ||
} | ||
|
||
if (files.length > 1) { | ||
return RocketChat.API.v1.failure('Just 1 file is allowed'); | ||
} | ||
|
||
const file = files[0]; | ||
|
||
const fileStore = FileUpload.getStore('Uploads'); | ||
|
||
const details = { | ||
name: file.filename, | ||
size: file.fileBuffer.length, | ||
type: file.mimetype, | ||
rid: this.urlParams.rid | ||
}; | ||
|
||
Meteor.runAsUser(this.userId, () => { | ||
const uploadedFile = Meteor.wrapAsync(fileStore.insert.bind(fileStore))(details, file.fileBuffer); | ||
|
||
uploadedFile.description = fields.description; | ||
|
||
delete fields.description; | ||
|
||
RocketChat.API.v1.success(Meteor.call('sendFileMessage', this.urlParams.rid, null, uploadedFile, fields)); | ||
}); | ||
|
||
return RocketChat.API.v1.success(); | ||
} | ||
}); |
This file contains 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
This file contains 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,24 @@ | ||
RocketChat.API.v1.addRoute('subscriptions.get', { authRequired: 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. Would be to hard to have the same response format for calls with and without the updatedAt filter? 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. Nope, not at all...aka check now. ;) |
||
get: { | ||
//This is defined as such only to provide an example of how the routes can be defined :X | ||
action() { | ||
let updatedAt; | ||
|
||
if (typeof this.queryParams.updatedAt === 'string') { | ||
try { | ||
updatedAt = new Date(this.queryParams.updatedAt); | ||
|
||
if (updatedAt.toString() === 'Invalid Date') { | ||
return RocketChat.API.v1.failure('Invalid date for `updatedAt`'); | ||
} | ||
} catch (error) { | ||
return RocketChat.API.v1.failure('Invalid date for `updatedAt`'); | ||
} | ||
} | ||
|
||
return Meteor.runAsUser(this.userId, () => { | ||
return RocketChat.API.v1.success(Meteor.call('subscriptions/get', updatedAt)); | ||
}); | ||
} | ||
} | ||
}); |
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.
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.
Should this be changed to a model call? We already have
RocketChat.models.Settings.findNotHiddenPublic
which has the same filter, just need to implement additionalsort
,skip
andlimit
options.I also think this should only return
_id
andvalue
fields, I cannot see any use for the other fields.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.
The ideia is to have an API that is versatile, that's why the API pass the query and allow the caller to pass more filters and require other fields if necessary
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.
my only concern is how it can be abused.
but still bypassing the model (using .
find
directly) defeats model's purpose and I thought was strongly discouraged.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.
I'm going to agree that this particular endpoint should use the
findNotHIddenPublic
with pagination support, however adding that support requires additional work and can be done via a secondary pull request after this one is merged. This way we don't delay any longer getting this out and come back to it.