Skip to content

Commit a008173

Browse files
author
STAFYNIAK Sacha
committed
Merge branch 'master' into update-kuzzle-security-document
Conflicts: package.json
2 parents 72430bc + e35bc88 commit a008173

File tree

7 files changed

+55
-22
lines changed

7 files changed

+55
-22
lines changed

dist/kuzzle.js

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,7 +2077,7 @@ function KuzzleDataMapping(kuzzleDataCollection, mapping) {
20772077
//read-only properties
20782078
collection: {
20792079
value: kuzzleDataCollection,
2080-
eunmerable: true
2080+
enumerable: true
20812081
},
20822082
kuzzle: {
20832083
value: kuzzleDataCollection.kuzzle,
@@ -2663,13 +2663,18 @@ KuzzleRoom.prototype.count = function (cb) {
26632663
var data;
26642664

26652665
this.kuzzle.callbackRequired('KuzzleRoom.count', cb);
2666+
26662667
data = this.kuzzle.addHeaders({body: {roomId: this.roomId}}, this.headers);
26672668

26682669
if (this.subscribing) {
26692670
this.queue.push({action: 'count', args: [cb]});
26702671
return this;
26712672
}
26722673

2674+
if (!this.roomId) {
2675+
throw new Error('KuzzleRoom.count: cannot count subscriptions on an inactive room');
2676+
}
2677+
26732678
this.kuzzle.query(this.collection.buildQueryArgs('subscribe', 'count'), data, function (err, res) {
26742679
if (err) {
26752680
return cb(err);
@@ -2702,6 +2707,8 @@ KuzzleRoom.prototype.renew = function (filters, cb) {
27022707
filters = null;
27032708
}
27042709

2710+
self.kuzzle.callbackRequired('KuzzleRoom.renew', cb);
2711+
27052712
/*
27062713
Skip subscription renewal if another one was performed a moment before
27072714
*/
@@ -2728,8 +2735,6 @@ KuzzleRoom.prototype.renew = function (filters, cb) {
27282735
return self;
27292736
}
27302737

2731-
self.kuzzle.callbackRequired('KuzzleRoom.renew', cb);
2732-
27332738
self.unsubscribe();
27342739
self.roomId = null;
27352740
self.subscribing = true;
@@ -3037,7 +3042,7 @@ KuzzleProfile.prototype.hydrate = function (options, cb) {
30373042
return cb(error);
30383043
}
30393044

3040-
cb(null, new KuzzleProfile(self, response.result._id, response.result._source));
3045+
cb(null, new KuzzleProfile(self, self.id, {roles: response.result.hits}));
30413046
});
30423047
};
30433048

@@ -3764,7 +3769,7 @@ function KuzzleSecurityDocument(kuzzleSecurity, id, content) {
37643769
});
37653770

37663771
if (content) {
3767-
this.setContent(content);
3772+
this.setContent(content, true);
37683773
}
37693774

37703775
// promisifying
@@ -3781,13 +3786,25 @@ function KuzzleSecurityDocument(kuzzleSecurity, id, content) {
37813786
}
37823787

37833788
/**
3789+
* Replaces the current content with new data.
3790+
* Changes made by this function won’t be applied until the save method is called.
37843791
*
37853792
* @param {Object} data - New securityDocument content
3793+
* @param {boolean} replace - if true: replace this document content with the provided data.
37863794
*
37873795
* @return {Object} this
37883796
*/
3789-
KuzzleSecurityDocument.prototype.setContent = function (data) {
3790-
this.content = data;
3797+
KuzzleSecurityDocument.prototype.setContent = function (data, replace) {
3798+
var self = this;
3799+
3800+
if (replace) {
3801+
this.content = data;
3802+
}
3803+
else {
3804+
Object.keys(data).forEach(function (key) {
3805+
self.content[key] = data[key];
3806+
});
3807+
}
37913808

37923809
return this;
37933810
};
@@ -3901,11 +3918,16 @@ KuzzleUser.prototype.hydrate = function (options, cb) {
39013918
}
39023919

39033920
self.kuzzle.query(this.kuzzleSecurity.buildQueryArgs('getProfile'), {_id: this.content.profile}, options, function (error, response) {
3921+
var hydratedUser;
3922+
39043923
if (error) {
39053924
return cb(error);
39063925
}
39073926

3908-
cb(null, new KuzzleUser(self, response.result._id, response.result._source));
3927+
hydratedUser = new KuzzleUser(self.kuzzleSecurity, self.id, self.content);
3928+
hydratedUser.setProfile(new KuzzleProfile(self.kuzzleSecurity, response.result._id, response.result._source));
3929+
3930+
cb(null, hydratedUser);
39093931
});
39103932
};
39113933

dist/kuzzle.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/kuzzle.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kuzzle-sdk",
3-
"version": "1.6.2",
3+
"version": "1.6.4",
44
"description": "Official Javascript SDK for Kuzzle",
55
"author": "The Kuzzle Team <[email protected]>",
66
"repository": {
@@ -24,23 +24,23 @@
2424
"main": "index.js",
2525
"license": "Apache-2.0",
2626
"dependencies": {
27-
"bluebird": "3.1.1",
27+
"bluebird": "3.3.1",
2828
"node-uuid": "1.4.7",
29-
"socket.io-client": "1.4.4"
29+
"socket.io-client": "1.4.5"
3030
},
3131
"devDependencies": {
3232
"browserify": "13.0.0",
3333
"codecov": "^1.0.1",
3434
"grunt": "0.4.5",
3535
"grunt-browserify": "^4.0.1",
36-
"grunt-contrib-jshint": "^0.11.3",
37-
"grunt-contrib-uglify": "0.11.0",
36+
"grunt-contrib-jshint": "^1.0.0",
37+
"grunt-contrib-uglify": "0.11.1",
3838
"gruntify-eslint": "^2.0.0",
3939
"istanbul": "0.4.2",
4040
"istanbul-middleware": "0.2.2",
41-
"mocha": "2.3.4",
41+
"mocha": "2.4.5",
4242
"proxyquire": "^1.7.3",
4343
"rewire": "^2.5.0",
44-
"should": "8.1.1"
44+
"should": "8.2.2"
4545
}
4646
}

src/kuzzleDataMapping.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function KuzzleDataMapping(kuzzleDataCollection, mapping) {
2424
//read-only properties
2525
collection: {
2626
value: kuzzleDataCollection,
27-
eunmerable: true
27+
enumerable: true
2828
},
2929
kuzzle: {
3030
value: kuzzleDataCollection.kuzzle,

src/kuzzleRoom.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,18 @@ KuzzleRoom.prototype.count = function (cb) {
126126
var data;
127127

128128
this.kuzzle.callbackRequired('KuzzleRoom.count', cb);
129+
129130
data = this.kuzzle.addHeaders({body: {roomId: this.roomId}}, this.headers);
130131

131132
if (this.subscribing) {
132133
this.queue.push({action: 'count', args: [cb]});
133134
return this;
134135
}
135136

137+
if (!this.roomId) {
138+
throw new Error('KuzzleRoom.count: cannot count subscriptions on an inactive room');
139+
}
140+
136141
this.kuzzle.query(this.collection.buildQueryArgs('subscribe', 'count'), data, function (err, res) {
137142
if (err) {
138143
return cb(err);
@@ -165,6 +170,8 @@ KuzzleRoom.prototype.renew = function (filters, cb) {
165170
filters = null;
166171
}
167172

173+
self.kuzzle.callbackRequired('KuzzleRoom.renew', cb);
174+
168175
/*
169176
Skip subscription renewal if another one was performed a moment before
170177
*/
@@ -191,8 +198,6 @@ KuzzleRoom.prototype.renew = function (filters, cb) {
191198
return self;
192199
}
193200

194-
self.kuzzle.callbackRequired('KuzzleRoom.renew', cb);
195-
196201
self.unsubscribe();
197202
self.roomId = null;
198203
self.subscribing = true;

test/kuzzleRoom/methods.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ describe('KuzzleRoom methods', function () {
7171
body: {}
7272
};
7373
room = new KuzzleRoom(dataCollection);
74+
room.roomId = 'foobar';
7475
});
7576

7677
it('should send the right query to Kuzzle', function () {
@@ -111,6 +112,11 @@ describe('KuzzleRoom methods', function () {
111112
done();
112113
});
113114
});
115+
116+
it('should fail if the room has no room ID', function () {
117+
room.roomId = undefined;
118+
should(function () {room.count(function () {})}).throw();
119+
});
114120
});
115121

116122
describe('#renew', function () {

0 commit comments

Comments
 (0)