diff --git a/core/client/navbar/navbar.html b/core/client/navbar/navbar.html
index def96104a1..8e8b82c802 100755
--- a/core/client/navbar/navbar.html
+++ b/core/client/navbar/navbar.html
@@ -24,12 +24,14 @@
{{# if currentUser }}
{{# if proxyIsDefined }}
- -
-
-
- {{_ "navbar_dashboard" }}
-
-
+ {{# if userCanViewDashboard }}
+ -
+
+
+ {{_ "navbar_dashboard" }}
+
+
+ {{/ if }}
{{/ if }}
{{/ if }}
-
diff --git a/core/client/navbar/navbar.js b/core/client/navbar/navbar.js
index a3195da6e8..57a791814d 100755
--- a/core/client/navbar/navbar.js
+++ b/core/client/navbar/navbar.js
@@ -91,29 +91,61 @@ Template.navbar.helpers({
return false;
},
userCanAddApi () {
- try {
- // Get settigns document
- const settings = Settings.findOne();
+ // Get settigns document
+ const settings = Settings.findOne();
+ if (settings) {
// Get access setting value
- const onlyAdminsCanAddApis = settings.access.onlyAdminsCanAddApis;
+ // If access field doesn't exist, these is false. Allow users to add an API on default
+ const onlyAdminsCanAddApis = settings.access ? settings.access.onlyAdminsCanAddApis : false;
+ // Allow user to add an API because not only for admin
if (!onlyAdminsCanAddApis) {
return true;
}
+ // Otherwise check of user role
// Get current user Id
const userId = Meteor.userId();
// Check if current user is admin
const userIsAdmin = Roles.userIsInRole(userId, ['admin']);
- return onlyAdminsCanAddApis && userIsAdmin;
- } catch (e) {
- // If caught an error, then returning true because no access settings is set
- // By default allowing all user to add an API
- return true;
+ return userIsAdmin;
+ }
+ // Return true because no settings are set
+ // By default allowing all user to add an API
+ return true;
+ },
+ userCanViewDashboard () {
+ // Allow or not regular user to view Dashboard page
+ // It depends on onlyAdminsCanAddApis settings
+
+ // Get settigns document
+ const settings = Settings.findOne();
+
+ if (settings) {
+ // Get access setting value
+ // If access field doesn't exist, these is false. Allow users to view page
+ const onlyAdminsCanAddApis = settings.access ? settings.access.onlyAdminsCanAddApis : false;
+
+ // Allow user to view page because not only for admin
+ if (!onlyAdminsCanAddApis) {
+ return true;
+ }
+
+ // Otherwise check of user role
+ // Get current user Id
+ const userId = Meteor.userId();
+
+ // Check if current user is admin or manager
+ const userIsAdminOrManager = Roles.userIsInRole(userId, ['admin', 'manager']);
+
+ return userIsAdminOrManager;
}
+ // Return true because no settings are set
+ // By default allowing all user to add an API
+ return true;
},
});