Skip to content

Commit bb490e4

Browse files
committed
Hide settings/apps unless apps:true is in config.js
fixes #3031 - Adds an initializer for passing config to the frontend, it's not pretty but it works - Forwards the apps route and hides the apps menu item if apps:true is not present in config.js
1 parent f4c6309 commit bb490e4

File tree

7 files changed

+40
-11
lines changed

7 files changed

+40
-11
lines changed

core/client/controllers/settings.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var SettingsController = Ember.Controller.extend({
2+
showApps: Ember.computed.bool('config.apps')
3+
});
4+
5+
export default SettingsController;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var ConfigInitializer = {
2+
name: 'config',
3+
4+
initialize: function (container, application) {
5+
application.register('ghost:config', application.get('config'), {instantiate: false});
6+
7+
application.inject('route', 'config', 'ghost:config');
8+
application.inject('controller', 'config', 'ghost:config');
9+
}
10+
};
11+
12+
export default ConfigInitializer;

core/client/routes/settings/apps.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import AuthenticatedRoute from 'ghost/routes/authenticated';
22

33
var AppsRoute = AuthenticatedRoute.extend({
4+
beforeModel: function () {
5+
if (!this.get('config.apps')) {
6+
this.transitionTo('settings.general');
7+
}
8+
},
49
model: function () {
510
return this.store.find('app');
611
}

core/client/templates/settings.hbs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
{{#view "item-view" tagName="li" class="general"}}
99
{{#link-to "settings.general"}}General{{/link-to}}
1010
{{/view}}
11-
11+
1212
{{#view "item-view" tagName="li" class="users"}}
1313
{{#link-to "settings.user"}}User{{/link-to}}
1414
{{/view}}
15-
16-
{{#view "item-view" tagName="li" class="apps"}}
17-
{{#link-to "settings.apps"}}Apps{{/link-to}}
18-
{{/view}}
15+
16+
{{#if showApps}}
17+
{{#view "item-view" tagName="li" class="apps"}}
18+
{{#link-to "settings.apps"}}Apps{{/link-to}}
19+
{{/view}}
20+
{{/if}}
1921
</ul>
2022
</nav>
2123
</aside>

core/server/controllers/admin.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,21 @@ function setSelected(list, name) {
4242

4343
adminControllers = {
4444
'index': function (req, res) {
45+
4546
/*jslint unparam:true*/
46-
var userData;
47+
var userData,
48+
// config we need on the frontend
49+
frontConfig = {
50+
apps: config().apps
51+
};
4752

4853
if (req.session && req.session.userData) {
4954
userData = JSON.stringify(req.session.userData);
5055
}
5156

5257
res.render('default-ember', {
53-
user: userData
58+
user: userData,
59+
config: JSON.stringify(frontConfig)
5460
});
5561
},
5662
// Route: index

core/server/views/default-ember.hbs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@
4141

4242
<script>
4343
window.ENV = {
44-
{{#user}}
45-
user: {{{this}}}
46-
{{/user}}
44+
{{#user}}user: {{{this}}},{{/user}}
45+
config: {{{config}}}
4746
};
4847
window.App = require('ghost/app')['default'].create(window.ENV);
4948
</script>

core/test/functional/client/settings_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ CasperTest.emberBegin('Settings screen is correct', 17, function suite(test) {
2020
test.assertExists('.settings-menu', 'Settings menu is present');
2121
test.assertExists('.settings-menu .general', 'General tab is present');
2222
test.assertExists('.settings-menu .users', 'Users tab is present');
23-
test.assertExists('.settings-menu .apps', 'Apps is present');
23+
test.assertNotExists('.settings-menu .apps', 'Apps is present');
2424
test.assertExists('.wrapper', 'Settings main view is present');
2525
test.assertExists('.settings-content', 'Settings content view is present');
2626
test.assertExists('.settings-menu .general.active', 'General tab is marked active');

0 commit comments

Comments
 (0)