mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Added Mentions endpoint to Admin (#16136)
ref https://github.com/TryGhost/Team/issues/2421 - added the Mentions API endpoint to Admin - setup initial mention model in the Ember Store to be able to dev with the endpoint - added basic routing to access the `/mentions` page that is currently behind feature flags - Setup basic testing with a mirage mock endpoint.
This commit is contained in:
parent
008d83ad08
commit
57bc14e00f
9 changed files with 117 additions and 0 deletions
8
ghost/admin/app/adapters/mention.js
Normal file
8
ghost/admin/app/adapters/mention.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
import ApplicationAdapter from 'ghost-admin/adapters/application';
|
||||
|
||||
export default class Mention extends ApplicationAdapter {
|
||||
queryRecord() {
|
||||
let url = this.buildURL('mentions');
|
||||
return this.ajax(url, 'GET');
|
||||
}
|
||||
}
|
21
ghost/admin/app/controllers/mentions.js
Normal file
21
ghost/admin/app/controllers/mentions.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
import Controller from '@ember/controller';
|
||||
import {A} from '@ember/array';
|
||||
import {inject as service} from '@ember/service';
|
||||
import {task} from 'ember-concurrency';
|
||||
import {tracked} from '@glimmer/tracking';
|
||||
|
||||
export default class MentionsController extends Controller {
|
||||
@service store;
|
||||
|
||||
@tracked mentionsList = A([]);
|
||||
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
}
|
||||
|
||||
@task
|
||||
*loadMentionsTask() {
|
||||
const mentions = yield this.store.query('mention', {});
|
||||
this.mentionsList = mentions;
|
||||
}
|
||||
}
|
15
ghost/admin/app/models/mention.js
Normal file
15
ghost/admin/app/models/mention.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import Model, {attr} from '@ember-data/model';
|
||||
|
||||
// @todo this is a temporary model until we have the api / db model structure figured out
|
||||
export default Model.extend({
|
||||
source: attr('string'),
|
||||
target: attr('string'),
|
||||
timestamp: attr('date'),
|
||||
resourceId: attr('string', {allowNull: true}),
|
||||
sourceTitle: attr('string'),
|
||||
sourcExcerpt: attr('string'),
|
||||
sourceFavicon: attr('string'),
|
||||
sourceFeaturedImage: attr('string'),
|
||||
payload: attr(),
|
||||
mentions: attr() // @todo this is a temporary field until we have the api / db model structure figured out
|
||||
});
|
|
@ -123,6 +123,8 @@ Router.map(function () {
|
|||
this.route('error404', {path: '/*path'});
|
||||
|
||||
this.route('designsandbox');
|
||||
|
||||
this.route('mentions');
|
||||
});
|
||||
|
||||
export default Router;
|
||||
|
|
19
ghost/admin/app/routes/mentions.js
Normal file
19
ghost/admin/app/routes/mentions.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
||||
import {inject as service} from '@ember/service';
|
||||
|
||||
export default class MentionsRoute extends AuthenticatedRoute {
|
||||
@service store;
|
||||
@service feature;
|
||||
|
||||
beforeModel() {
|
||||
super.beforeModel(...arguments);
|
||||
if (!this.feature.webmentions) {
|
||||
return this.transitionTo('dashboard');
|
||||
}
|
||||
}
|
||||
|
||||
setupController(controller) {
|
||||
super.setupController(...arguments);
|
||||
controller.loadMentionsTask.perform();
|
||||
}
|
||||
}
|
10
ghost/admin/app/templates/mentions.hbs
Normal file
10
ghost/admin/app/templates/mentions.hbs
Normal file
|
@ -0,0 +1,10 @@
|
|||
<section class="gh-canvas">
|
||||
<GhCanvasHeader class="gh-canvas-header">
|
||||
<h2 class="gh-canvas-title" data-test-screen-title>
|
||||
Mentions
|
||||
</h2>
|
||||
</GhCanvasHeader>
|
||||
{{#each this.mentionsList as |mention|}}
|
||||
<li>from: {{mention.source}} to {{mention.target}}</li>
|
||||
{{/each}}
|
||||
</section>
|
5
ghost/admin/mirage/config/mentions.js
Normal file
5
ghost/admin/mirage/config/mentions.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
import {paginatedResponse} from '../utils';
|
||||
|
||||
export default function mockMentions(server) {
|
||||
server.get('/mentions/', paginatedResponse('mentions'));
|
||||
}
|
|
@ -10,6 +10,7 @@ import mockIntegrations from './config/integrations';
|
|||
import mockInvites from './config/invites';
|
||||
import mockLabels from './config/labels';
|
||||
import mockMembers from './config/members';
|
||||
import mockMentions from './config/mentions';
|
||||
import mockNewsletters from './config/newsletters';
|
||||
import mockOffers from './config/offers';
|
||||
import mockPages from './config/pages';
|
||||
|
@ -59,6 +60,7 @@ export default function () {
|
|||
mockSnippets(this);
|
||||
mockNewsletters(this);
|
||||
mockStats(this);
|
||||
mockMentions(this);
|
||||
|
||||
/* Notifications -------------------------------------------------------- */
|
||||
|
||||
|
|
35
ghost/admin/tests/acceptance/mentions-test.js
Normal file
35
ghost/admin/tests/acceptance/mentions-test.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
import {authenticateSession, invalidateSession} from 'ember-simple-auth/test-support';
|
||||
import {currentURL, visit} from '@ember/test-helpers';
|
||||
import {describe, it} from 'mocha';
|
||||
import {enableLabsFlag} from '../helpers/labs-flag';
|
||||
import {expect} from 'chai';
|
||||
import {setupApplicationTest} from 'ember-mocha';
|
||||
import {setupMirage} from 'ember-cli-mirage/test-support';
|
||||
|
||||
describe('Acceptance: Mentions', function () {
|
||||
const hooks = setupApplicationTest();
|
||||
setupMirage(hooks);
|
||||
|
||||
it('redirects to signin when not authenticated', async function () {
|
||||
await invalidateSession();
|
||||
await visit('/mentions');
|
||||
expect(currentURL()).to.equal('/signin');
|
||||
});
|
||||
|
||||
describe('as admin', function () {
|
||||
beforeEach(async function () {
|
||||
this.server.loadFixtures('configs');
|
||||
this.server.loadFixtures('settings');
|
||||
|
||||
let role = this.server.create('role', {name: 'Administrator'});
|
||||
this.server.create('user', {roles: [role]});
|
||||
enableLabsFlag(this.server, 'webmentions');
|
||||
return await authenticateSession();
|
||||
});
|
||||
it('can render mentions page', async function () {
|
||||
await visit('/mentions');
|
||||
expect(currentURL(), 'currentURL').to.equal('/mentions');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Add table
Reference in a new issue