From 337d929c2774d219e487d95da2f8234579b65704 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Tue, 22 Jan 2019 16:23:26 +0000 Subject: [PATCH] Added empty member management routes --- app/router.js | 4 ++ app/routes/members.js | 26 +++++++++ app/routes/members/details.js | 3 ++ app/routes/members/index.js | 3 ++ app/templates/components/gh-nav-menu.hbs | 9 ++-- app/templates/members.hbs | 1 + app/templates/members/details.hbs | 0 app/templates/members/index.hbs | 10 ++++ tests/acceptance/members-test.js | 68 ++++++++++++++++++++++++ 9 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 app/routes/members.js create mode 100644 app/routes/members/details.js create mode 100644 app/routes/members/index.js create mode 100644 app/templates/members.hbs create mode 100644 app/templates/members/details.hbs create mode 100644 app/templates/members/index.hbs create mode 100644 tests/acceptance/members-test.js diff --git a/app/router.js b/app/router.js index db79192318..31f67e58e0 100644 --- a/app/router.js +++ b/app/router.js @@ -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'); diff --git a/app/routes/members.js b/app/routes/members.js new file mode 100644 index 0000000000..63bdc43deb --- /dev/null +++ b/app/routes/members.js @@ -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'); + } + }); + } +}); diff --git a/app/routes/members/details.js b/app/routes/members/details.js new file mode 100644 index 0000000000..7ff4a4b892 --- /dev/null +++ b/app/routes/members/details.js @@ -0,0 +1,3 @@ +import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; + +export default AuthenticatedRoute.extend({}); diff --git a/app/routes/members/index.js b/app/routes/members/index.js new file mode 100644 index 0000000000..7ff4a4b892 --- /dev/null +++ b/app/routes/members/index.js @@ -0,0 +1,3 @@ +import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; + +export default AuthenticatedRoute.extend({}); diff --git a/app/templates/components/gh-nav-menu.hbs b/app/templates/components/gh-nav-menu.hbs index 54069762c3..d919771734 100644 --- a/app/templates/components/gh-nav-menu.hbs +++ b/app/templates/components/gh-nav-menu.hbs @@ -50,10 +50,11 @@ {{/if}}
  • {{#link-to "team" data-test-nav="team"}}{{svg-jar "account-group"}}Team{{/link-to}}
  • - {{#if feature.subscribers}} - {{#if (gh-user-can-admin session.user)}} -
  • {{#link-to "subscribers" data-test-nav="subscribers"}}{{svg-jar "email"}}Subscribers{{/link-to}}
  • - {{/if}} + {{#if (and config.enableDeveloperExperiments (gh-user-can-admin session.user))}} +
  • {{#link-to "members" data-test-nav="members"}}{{svg-jar "email"}}Members{{/link-to}}
  • + {{/if}} + {{#if (and feature.subscribers (gh-user-can-admin session.user))}} +
  • {{#link-to "subscribers" data-test-nav="subscribers"}}{{svg-jar "email"}}Subscribers{{/link-to}}
  • {{/if}} {{#if (gh-user-can-admin session.user)}} diff --git a/app/templates/members.hbs b/app/templates/members.hbs new file mode 100644 index 0000000000..c24cd68950 --- /dev/null +++ b/app/templates/members.hbs @@ -0,0 +1 @@ +{{outlet}} diff --git a/app/templates/members/details.hbs b/app/templates/members/details.hbs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/templates/members/index.hbs b/app/templates/members/index.hbs new file mode 100644 index 0000000000..c172af5bee --- /dev/null +++ b/app/templates/members/index.hbs @@ -0,0 +1,10 @@ +
    +
    +

    Members

    +
    +
    + +
    +

    ...

    +
    +
    \ No newline at end of file diff --git a/tests/acceptance/members-test.js b/tests/acceptance/members-test.js new file mode 100644 index 0000000000..f2ad0057ea --- /dev/null +++ b/tests/acceptance/members-test.js @@ -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'); + }); + }); +});