Skip to content

Commit dd11d76

Browse files
authored
Merge pull request #233 from Digipalvelutehdas/hotfix/users-security
Hotfix/users security
2 parents 6d91c28 + ecd6a38 commit dd11d76

File tree

6 files changed

+38
-10
lines changed

6 files changed

+38
-10
lines changed

about/client/about.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ <h3>
2828
Apinf
2929
</dt>
3030
<dd>
31-
0.38.0
31+
0.38.1
3232
</dd>
3333
<dt>
3434
API Umbrella

api_catalog/client/api_catalog.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import { Meteor } from 'meteor/meteor';
22
import { Template } from 'meteor/templating';
33
import { Roles } from 'meteor/alanning:roles';
44
import { FlowRouter } from 'meteor/kadira:flow-router';
5-
65
import { Apis } from '/apis/collection';
76
import { ApiBookmarks } from '/bookmarks/collection';
7+
import $ from 'jquery';
88

99
Template.apiCatalog.onCreated(function () {
1010
// Get reference to template instance
1111
const instance = this;
12+
1213
// Get user id
1314
const userId = Meteor.userId();
1415

@@ -43,8 +44,9 @@ Template.apiCatalog.onCreated(function () {
4344

4445
// Subscribe to API logo collection
4546
instance.subscribe('allApiLogo');
47+
4648
// Subscribe to all users, returns only usernames
47-
instance.subscribe('allUsers');
49+
instance.subscribe('allUsersUsernamesOnly');
4850

4951
// Watch for changes in the sort and filter settings
5052
instance.autorun(() => {
@@ -77,29 +79,33 @@ Template.apiCatalog.onCreated(function () {
7779
// Filtering available for registered users
7880
if (userId) {
7981
switch (filterByParameter) {
80-
case 'all':
82+
case 'all': {
8183
// Delete filter for managed apis & bookmarks
8284
delete currentFilters.managerIds;
8385
delete currentFilters._id;
8486
break;
85-
case 'my-apis':
87+
}
88+
case 'my-apis': {
8689
// Delete filter for bookmarks
8790
delete currentFilters._id;
8891
// Set filter for managed apis
8992
currentFilters.managerIds = userId;
9093
break;
91-
case 'my-bookmarks':
94+
}
95+
case 'my-bookmarks': {
9296
// Delete filter for managed apis
9397
delete currentFilters.managerIds;
9498
// Get user bookmarks
9599
const userBookmarks = ApiBookmarks.findOne({ userId }) || '';
96100
// Set filter for bookmarks
97101
currentFilters._id = { $in: userBookmarks.apiIds };
98102
break;
99-
default:
103+
}
104+
default: {
100105
// Otherwise get it like default value
101106
currentFilters = { isPublic: true };
102107
break;
108+
}
103109
}
104110
} else {
105111
// Otherwise get it like default value

apis/client/profile/view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Template.viewApi.onCreated(function () {
3939
instance.subscribe('apiAuthorizedUsersPublicDetails', instance.apiId);
4040

4141
// Subscribe to all users, returns only usernames
42-
instance.subscribe('allUsers');
42+
instance.subscribe('allUsersUsernamesOnly');
4343

4444
// Subscribe to organization for this API
4545
instance.subscribe('apiOrganizationBasicDetails', instance.apiId);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apinf",
3-
"version": "0.38.0",
3+
"version": "0.38.1",
44
"description": "API management portal and proxy.",
55
"main": "index.js",
66
"directories": {

users/client/lib/router.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,32 @@ import { Meteor } from 'meteor/meteor';
22
import { FlowRouter } from 'meteor/kadira:flow-router';
33
import { BlazeLayout } from 'meteor/kadira:blaze-layout';
44
import { Accounts } from 'meteor/accounts-base';
5+
import { Roles } from 'meteor/alanning:roles';
56
import { sAlert } from 'meteor/juliancwirko:s-alert';
67
import { TAPi18n } from 'meteor/tap:i18n';
78
import { AccountsTemplates } from 'meteor/useraccounts:core';
89

910
FlowRouter.route('/users', {
1011
name: 'accountsAdmin',
12+
triggersEnter: [
13+
function (context, redirect) {
14+
/*
15+
Make sure user is authorized to access route (admin users only)
16+
*/
17+
18+
// Get current User ID
19+
const userId = Meteor.userId();
20+
21+
// Check if User is admin
22+
const userIsAdmin = Roles.userIsInRole(userId, 'admin');
23+
24+
// If user is not an admin
25+
if (!userIsAdmin) {
26+
// Redirect to 'not authorized' route
27+
redirect('/not-authorized');
28+
}
29+
},
30+
],
1131
action: function () {
1232
BlazeLayout.render('masterLayout', { main: 'accountsAdmin' });
1333
},

users/collection/server/publications.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Meteor } from 'meteor/meteor';
22
import { Apis } from '/apis/collection';
33

4-
Meteor.publish('allUsers', function () {
4+
Meteor.publish('allUsersUsernamesOnly', function () {
55
return Meteor.users.find({}, { fields: { username: 1 } });
66
});
77

8+
// TODO: determine whether this publication is used
9+
// If it is used, refactor it to be a regular publication
810
Meteor.publishComposite('user', function () {
911
return {
1012
find () {

0 commit comments

Comments
 (0)