Skip to content

Commit

Permalink
Sync createPrivateGroup and createChannel parameter order for readOnl…
Browse files Browse the repository at this point in the history
…y and customFields
  • Loading branch information
engelgabriel committed Jan 19, 2017
1 parent 6811201 commit 54379d1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ oauth1@1.1.11
oauth2@1.1.11
observe-sequence@1.0.14
ordered-dict@1.0.9
ostrio:cookies@2.0.5
ostrio:cookies@2.1.0
pauli:accounts-linkedin@1.3.1
pauli:linkedin@1.3.1
peerlibrary:aws-sdk@2.4.9_1
Expand Down
5 changes: 4 additions & 1 deletion example-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ set -x
set -euvo pipefail
IFS=$'\n\t'

export METEOR_SETTINGS=$(cat settings.json)
# Build
export NODE_ENV=production
meteor add rocketchat:internal-hubot meteorhacks:kadira
meteor build --server https://demo.rocket.chat --directory /var/www/rocket.chat

# Run
export METEOR_SETTINGS=$(cat settings.json)
cd /var/www/rocket.chat/bundle/programs/server
npm install
cd /var/www/rocket.chat/current
Expand Down
6 changes: 5 additions & 1 deletion packages/rocketchat-api/server/v1/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,18 @@ RocketChat.API.v1.addRoute('channels.create', { authRequired: true }, {
return RocketChat.API.v1.failure('Body param "members" must be an array if provided');
}

if (this.bodyParams.customFields && !(typeof this.bodyParams.customFields === 'object')) {
return RocketChat.API.v1.failure('Body param "customFields" must be an object if provided');
}

let readOnly = false;
if (typeof this.bodyParams.readOnly !== 'undefined') {
readOnly = this.bodyParams.readOnly;
}

let id;
Meteor.runAsUser(this.userId, () => {
id = Meteor.call('createChannel', this.bodyParams.name, this.bodyParams.members ? this.bodyParams.members : [], readOnly);
id = Meteor.call('createChannel', this.bodyParams.name, this.bodyParams.members ? this.bodyParams.members : [], readOnly, this.bodyParams.customFields);
});

return RocketChat.API.v1.success({
Expand Down
7 changes: 6 additions & 1 deletion packages/rocketchat-api/server/v1/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,14 @@ RocketChat.API.v1.addRoute('groups.create', { authRequired: true }, {
return RocketChat.API.v1.failure('Body param "customFields" must be an object if provided');
}

let readOnly = false;
if (typeof this.bodyParams.readOnly !== 'undefined') {
readOnly = this.bodyParams.readOnly;
}

let id;
Meteor.runAsUser(this.userId, () => {
id = Meteor.call('createPrivateGroup', this.bodyParams.name, this.bodyParams.members ? this.bodyParams.members : [], this.bodyParams.customFields);
id = Meteor.call('createPrivateGroup', this.bodyParams.name, this.bodyParams.members ? this.bodyParams.members : [], readOnly, this.bodyParams.customFields);
});

return RocketChat.API.v1.success({
Expand Down
6 changes: 3 additions & 3 deletions packages/rocketchat-lib/server/methods/createChannel.coffee
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Meteor.methods
createChannel: (name, members, readOnly) ->
createChannel: (name, members, readOnly = false, customFields = {}) ->

check name, String
check members, Match.Optional([String])

if not Meteor.userId()
throw new Meteor.Error 'error-invalid-user', "Invalid user", { method: 'createChannel' }

if RocketChat.authz.hasPermission(Meteor.userId(), 'create-c') isnt true
if not RocketChat.authz.hasPermission(Meteor.userId(), 'create-c')
throw new Meteor.Error 'error-not-allowed', "Not allowed", { method: 'createChannel' }

return RocketChat.createRoom('c', name, Meteor.user()?.username, members, readOnly);
return RocketChat.createRoom('c', name, Meteor.user()?.username, members, readOnly, {customFields: customFields});
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Meteor.methods
createPrivateGroup: (name, members, customFields) ->
createPrivateGroup: (name, members, readOnly = false, customFields = {}) ->

check name, String
check members, Match.Optional([String])

if not Meteor.userId()
throw new Meteor.Error 'error-invalid-user', "Invalid user", { method: 'createPrivateGroup' }

unless RocketChat.authz.hasPermission(Meteor.userId(), 'create-p')
if not RocketChat.authz.hasPermission(Meteor.userId(), 'create-p')
throw new Meteor.Error 'error-not-allowed', "Not allowed", { method: 'createPrivateGroup' }

return RocketChat.createRoom('p', name, Meteor.user()?.username, members, {customFields: customFields});
return RocketChat.createRoom('p', name, Meteor.user()?.username, members, readOnly, {customFields: customFields});

0 comments on commit 54379d1

Please sign in to comment.