forked from TryGhost/Admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added empty member management routes
- Loading branch information
1 parent
0923b1d
commit 337d929
Showing
9 changed files
with
120 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{outlet}} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
}); |