Skip to content

Commit

Permalink
Added empty member management routes
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinansfield committed Jan 22, 2019
1 parent 0923b1d commit 337d929
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Router.map(function () {
this.route('settings.integrations.unsplash', {path: '/settings/integrations/unsplash'});
this.route('settings.integrations.zapier', {path: '/settings/integrations/zapier'});

this.route('members', function () {
this.route('details', {path: ':member_id'});
});

this.route('subscribers', function () {
this.route('new');
this.route('import');
Expand Down
26 changes: 26 additions & 0 deletions app/routes/members.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
import {inject as service} from '@ember/service';

export default AuthenticatedRoute.extend({
config: service(),

titleToken: 'Members',

// redirect to posts screen if:
// - developer experiments aren't enabled
// - TODO: members is disabled?
// - logged in user isn't owner/admin
beforeModel() {
this._super(...arguments);

if (!this.config.get('enableDeveloperExperiments')) {
return this.transitionTo('posts');
}

return this.session.user.then((user) => {
if (!user.isOwnerOrAdmin) {
return this.transitionTo('posts');
}
});
}
});
3 changes: 3 additions & 0 deletions app/routes/members/details.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';

export default AuthenticatedRoute.extend({});
3 changes: 3 additions & 0 deletions app/routes/members/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';

export default AuthenticatedRoute.extend({});
9 changes: 5 additions & 4 deletions app/templates/components/gh-nav-menu.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@
{{/if}}
</li>
<li>{{#link-to "team" data-test-nav="team"}}{{svg-jar "account-group"}}Team{{/link-to}}</li>
{{#if feature.subscribers}}
{{#if (gh-user-can-admin session.user)}}
<li>{{#link-to "subscribers" data-test-nav="subscribers"}}{{svg-jar "email"}}Subscribers{{/link-to}}</li>
{{/if}}
{{#if (and config.enableDeveloperExperiments (gh-user-can-admin session.user))}}
<li>{{#link-to "members" data-test-nav="members"}}{{svg-jar "email"}}Members{{/link-to}}</li>
{{/if}}
{{#if (and feature.subscribers (gh-user-can-admin session.user))}}
<li>{{#link-to "subscribers" data-test-nav="subscribers"}}{{svg-jar "email"}}Subscribers{{/link-to}}</li>
{{/if}}
</ul>
{{#if (gh-user-can-admin session.user)}}
Expand Down
1 change: 1 addition & 0 deletions app/templates/members.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{outlet}}
Empty file.
10 changes: 10 additions & 0 deletions app/templates/members/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<section class="gh-canvas">
<header class="gh-canvas-header">
<h2 class="gh-canvas-title" data-test-screen-title>Members</h2>
<div class="view-actions"></div>
</header>

<section class="view-container">
<p>...</p>
</section>
</section>
68 changes: 68 additions & 0 deletions tests/acceptance/members-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import {authenticateSession, invalidateSession} from 'ember-simple-auth/test-support';
import {beforeEach, describe, it} from 'mocha';
import {click, currentRouteName, currentURL, find} from '@ember/test-helpers';
import {expect} from 'chai';
import {setupApplicationTest} from 'ember-mocha';
import {visit} from '../helpers/visit';

describe('Acceptance: Members', function () {
let hooks = setupApplicationTest();
setupMirage(hooks);

it('redirects to signin when not authenticated', async function () {
await invalidateSession();
await visit('/members');

expect(currentURL()).to.equal('/signin');
});

it('redirects non-admins to posts', async function () {
let role = this.server.create('role', {name: 'Editor'});
this.server.create('user', {roles: [role]});

await authenticateSession();
await visit('/members');

expect(currentURL()).to.equal('/');
expect(find('[data-test-nav="members"]'), 'sidebar link')
.to.not.exist;
});

describe('as admin', function () {
beforeEach(async function () {
this.server.loadFixtures('configurations');
let config = this.server.schema.configurations.first();
config.update({enableDeveloperExperiments: true});

let role = this.server.create('role', {name: 'Administrator'});
this.server.create('user', {roles: [role]});

return await authenticateSession();
});

it('redirects to posts if developer experiments is disabled', async function () {
let config = this.server.schema.configurations.first();
config.update({enableDeveloperExperiments: false});

await visit('/members');

expect(currentURL()).to.equal('/');
expect(find('[data-test-nav="members"]'), 'sidebar link')
.to.not.exist;
});

it('shows sidebar link which navigates to members list', async function () {
await visit('/');

expect(find('[data-test-nav="members"]'), 'sidebar link')
.to.exist;

await click('[data-test-nav="members"]');

expect(currentURL()).to.equal('/members');
expect(currentRouteName()).to.equal('members.index');
expect(find('[data-test-screen-title]')).to.have.text('Members');
});
});
});

0 comments on commit 337d929

Please sign in to comment.