Skip to content

Commit 2fa84ba

Browse files
committed
send userId and the subscriptionId for permission checking functions
1 parent 47ceccb commit 2fa84ba

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

laika/tests/read_permissions.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ suite('Read Permissions', function() {
77
client.evalSync(createClientStream, 'hello');
88

99
server.evalSync(function() {
10-
helloStream.permissions.read(function(userId, eventName) {
10+
helloStream.permissions.read(function(eventName) {
1111
return true;
1212
});
1313
emit('return');
@@ -39,7 +39,7 @@ suite('Read Permissions', function() {
3939
var received = 0;
4040

4141
server.evalSync(function() {
42-
helloStream.permissions.read(function(userId, eventName) {
42+
helloStream.permissions.read(function(eventName) {
4343
return false;
4444
});
4545
emit('return');
@@ -124,8 +124,8 @@ suite('Read Permissions', function() {
124124
client.evalSync(createClientStream, 'hello');
125125

126126
server.evalSync(function() {
127-
helloStream.permissions.read(function(userId, eventName) {
128-
return !!userId;
127+
helloStream.permissions.read(function(eventName) {
128+
return !!this.userId;
129129
});
130130
emit('return');
131131
});

laika/tests/write_permissions.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ suite('Write Permissions', function() {
77
client.evalSync(createClientStream, 'hello');
88

99
server.evalSync(function() {
10-
helloStream.permissions.write(function(userId, evt) {
10+
helloStream.permissions.write(function(evt) {
1111
return true;
1212
});
1313
helloStream.on('evt', function(data) {
@@ -37,8 +37,8 @@ suite('Write Permissions', function() {
3737
c1.evalSync(laika.actions.createUser, {username: 'arunoda', password: 'maxapower'});
3838

3939
server.evalSync(function() {
40-
helloStream.permissions.write(function(userId, evt) {
41-
return !!userId;
40+
helloStream.permissions.write(function(evt) {
41+
return !!this.userId;
4242
});
4343
helloStream.on('evt', function(data) {
4444
emit('evt', this.userId, this.allowed, data);
@@ -77,7 +77,7 @@ suite('Write Permissions', function() {
7777
client.evalSync(createClientStream, 'hello');
7878

7979
server.evalSync(function() {
80-
helloStream.permissions.write(function(userId, evt) {
80+
helloStream.permissions.write(function(evt) {
8181
return false;
8282
});
8383
helloStream.on('evt', function(data) {
@@ -153,7 +153,7 @@ suite('Write Permissions', function() {
153153
c2.evalSync(createClientStream, 'hello');
154154

155155
server.evalSync(function() {
156-
helloStream.permissions.write(function(userId, evt) {
156+
helloStream.permissions.write(function(evt) {
157157
return true;
158158
});
159159
emit('return');
@@ -186,7 +186,7 @@ suite('Write Permissions', function() {
186186
var received = 0;
187187

188188
server.evalSync(function() {
189-
helloStream.permissions.write(function(userId, evt) {
189+
helloStream.permissions.write(function(evt) {
190190
return false;
191191
});
192192
emit('return');

lib/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Meteor.Stream = function Stream(name) {
4646
function onItem(item) {
4747
Fibers(function() {
4848
var id = Random.id();
49-
if(self.permissions.checkPermission('read', publication.userId, item.args[0])) {
49+
if(self.permissions.checkPermission('read', subscriptionId, publication.userId, item.args[0])) {
5050
//do not send again this to the sender
5151
if(subscriptionId != item.subscriptionId) {
5252
publication.added(streamName, id, item);
@@ -76,7 +76,7 @@ Meteor.Stream = function Stream(name) {
7676
methodContext.subscriptionId = subscriptionId;
7777

7878
//in order to send this to the serve callback
79-
methodContext.allowed = self.permissions.checkPermission('write', methodContext.userId, args[0]);
79+
methodContext.allowed = self.permissions.checkPermission('write', subscriptionId, methodContext.userId, args[0]);
8080
if(methodContext.allowed) {
8181
//apply filters
8282
args = applyFilters(args, methodContext);

lib/stream_permission.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ Meteor.Stream.Permission = function (acceptAll, cacheAll) {
1818
options['write']['doCache'] = (cache === undefined)? cacheAll: cache;
1919
};
2020

21-
this.checkPermission = function(type, userId, eventName) {
22-
var namespace = userId + '-' + eventName;
21+
this.checkPermission = function(type, subscriptionId, userId, eventName) {
22+
var namespace = subscriptionId + '-' + eventName;
2323
var result = options[type].results[namespace];
2424

2525
if(result === undefined) {
2626
var func = options[type].func;
2727
if(func) {
28-
result = func(userId, eventName);
28+
var context = {subscriptionId: subscriptionId, userId: userId};
29+
result = func.call(context, eventName);
2930
if(options[type].doCache) {
3031
options[type].results[namespace] = result;
3132
return result;

0 commit comments

Comments
 (0)