0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Migrated route objects to native class syntax

no issue

- ran the `ember-native-class-codemod` codemod to convert just the route classes to native class syntax and performed some minor manual cleanup
  - modern Ember uses native classes rather than EmberObject-based objects, this brings us closer to normalizing our code style across the codebase
- skipped the Application route as that requires deeper testing with a replacement for the `ShortcutsRoute` mixin
This commit is contained in:
Kevin Ansfield 2022-01-17 09:34:55 +00:00
parent d09db70f43
commit 75abe76346
29 changed files with 249 additions and 246 deletions

View file

@ -1,10 +1,10 @@
import Route from '@ember/routing/route'; import Route from '@ember/routing/route';
import {inject as service} from '@ember/service'; import {inject as service} from '@ember/service';
export default Route.extend({ export default class AuthenticatedRoute extends Route {
session: service(), @service session;
beforeModel(transition) { beforeModel(transition) {
this.session.requireAuthentication(transition, 'signin'); this.session.requireAuthentication(transition, 'signin');
} }
}); }

View file

@ -1,13 +1,13 @@
import Route from '@ember/routing/route'; import Route from '@ember/routing/route';
import {inject as service} from '@ember/service'; import {inject as service} from '@ember/service';
export default Route.extend({ export default class DesignsandboxRoute extends Route {
config: service(), @service config;
beforeModel() { beforeModel() {
this._super(...arguments); super.beforeModel(...arguments);
if (!this.get('config.enableDeveloperExperiments')) { if (!this.config.get('enableDeveloperExperiments')) {
return this.transitionTo('home'); return this.transitionTo('home');
} }
} }
}); }

View file

@ -1,9 +1,9 @@
import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
import {pluralize} from 'ember-inflector'; import {pluralize} from 'ember-inflector';
export default AuthenticatedRoute.extend({ export default class EditRoute extends AuthenticatedRoute {
beforeModel(transition) { beforeModel(transition) {
this._super(...arguments); super.beforeModel(...arguments);
// if the transition is not new->edit, reset the post on the controller // if the transition is not new->edit, reset the post on the controller
// so that the editor view is cleared before showing the loading state // so that the editor view is cleared before showing the loading state
@ -12,7 +12,7 @@ export default AuthenticatedRoute.extend({
editor.set('post', null); editor.set('post', null);
editor.reset(); editor.reset();
} }
}, }
model(params, transition) { model(params, transition) {
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
@ -29,13 +29,13 @@ export default AuthenticatedRoute.extend({
return this.store.query(modelName, query) return this.store.query(modelName, query)
.then(records => records.get('firstObject')); .then(records => records.get('firstObject'));
}, }
// the API will return a post even if the logged in user doesn't have // the API will return a post even if the logged in user doesn't have
// permission to edit it (all posts are public) so we need to do our // permission to edit it (all posts are public) so we need to do our
// own permissions check and redirect if necessary // own permissions check and redirect if necessary
afterModel(post) { afterModel(post) {
this._super(...arguments); super.afterModel(...arguments);
const user = this.session.user; const user = this.session.user;
const returnRoute = pluralize(post.constructor.modelName); const returnRoute = pluralize(post.constructor.modelName);
@ -48,14 +48,14 @@ export default AuthenticatedRoute.extend({
if (user.isContributor && !post.isDraft) { if (user.isContributor && !post.isDraft) {
return this.replaceWith(returnRoute); return this.replaceWith(returnRoute);
} }
}, }
serialize(model) { serialize(model) {
return { return {
type: model.constructor.modelName, type: model.constructor.modelName,
post_id: model.id post_id: model.id
}; };
}, }
// there's no specific controller for this route, instead all editor // there's no specific controller for this route, instead all editor
// handling is done on the editor route/controler // handling is done on the editor route/controler
@ -63,4 +63,4 @@ export default AuthenticatedRoute.extend({
let editor = this.controllerFor('editor'); let editor = this.controllerFor('editor');
editor.setPost(post); editor.setPost(post);
} }
}); }

View file

@ -1,8 +1,8 @@
import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
export default AuthenticatedRoute.extend({ export default class IndexRoute extends AuthenticatedRoute {
beforeModel() { beforeModel() {
this._super(...arguments); super.beforeModel(...arguments);
this.replaceWith('editor.new', 'post'); this.replaceWith('editor.new', 'post');
} }
}); }

View file

@ -1,6 +1,6 @@
import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
export default AuthenticatedRoute.extend({ export default class NewRoute extends AuthenticatedRoute {
model(params, transition) { model(params, transition) {
let {type: modelName} = params; let {type: modelName} = params;
@ -10,18 +10,18 @@ export default AuthenticatedRoute.extend({
} }
return this.store.createRecord(modelName, {authors: [this.session.user]}); return this.store.createRecord(modelName, {authors: [this.session.user]});
}, }
// there's no specific controller for this route, instead all editor // there's no specific controller for this route, instead all editor
// handling is done on the editor route/controler // handling is done on the editor route/controler
setupController(controller, newPost) { setupController(controller, newPost) {
let editor = this.controllerFor('editor'); let editor = this.controllerFor('editor');
editor.setPost(newPost); editor.setPost(newPost);
}, }
buildRouteInfoMetadata() { buildRouteInfoMetadata() {
return { return {
mainClasses: ['editor-new'] mainClasses: ['editor-new']
}; };
} }
}); }

View file

@ -1,14 +1,14 @@
import Route from '@ember/routing/route'; import Route from '@ember/routing/route';
export default Route.extend({ export default class Error404Route extends Route {
controllerName: 'error', controllerName = 'error';
templateName: 'error', templateName = 'error';
model() { model() {
return { return {
status: 404 status: 404
}; };
}, }
buildRouteInfoMetadata() { buildRouteInfoMetadata() {
return { return {
@ -16,4 +16,4 @@ export default Route.extend({
mainClasses: ['gh-main-white'] mainClasses: ['gh-main-white']
}; };
} }
}); }

View file

@ -1,11 +1,11 @@
import PostsRoute from './posts'; import PostsRoute from './posts';
export default PostsRoute.extend({ export default class PagesRoute extends PostsRoute {
modelName: 'page', modelName = 'page';
buildRouteInfoMetadata() { buildRouteInfoMetadata() {
return { return {
titleToken: 'Pages' titleToken: 'Pages'
}; };
} }
}); }

View file

@ -1,27 +1,27 @@
import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
import {action} from '@ember/object';
import {assign} from '@ember/polyfills'; import {assign} from '@ember/polyfills';
import {isBlank} from '@ember/utils'; import {isBlank} from '@ember/utils';
import {inject as service} from '@ember/service'; import {inject as service} from '@ember/service';
export default AuthenticatedRoute.extend({ export default class PostsRoute extends AuthenticatedRoute {
infinity: service(), @service infinity;
router: service(), @service router;
queryParams: { queryParams = {
type: {refreshModel: true}, type: {refreshModel: true},
visibility: {refreshModel: true}, visibility: {refreshModel: true},
access: {refreshModel: true}, access: {refreshModel: true},
author: {refreshModel: true}, author: {refreshModel: true},
tag: {refreshModel: true}, tag: {refreshModel: true},
order: {refreshModel: true} order: {refreshModel: true}
}, };
modelName: 'post', modelName = 'post';
perPage = 30;
perPage: 30, constructor() {
super(...arguments);
init() {
this._super(...arguments);
// if we're already on this route and we're transiting _to_ this route // if we're already on this route and we're transiting _to_ this route
// then the filters are being changed and we shouldn't create a new // then the filters are being changed and we shouldn't create a new
@ -35,7 +35,7 @@ export default AuthenticatedRoute.extend({
} }
} }
}); });
}, }
model(params) { model(params) {
const user = this.session.user; const user = this.session.user;
@ -76,11 +76,11 @@ export default AuthenticatedRoute.extend({
let paginationSettings = assign({perPage, startingPage: 1}, paginationParams, queryParams); let paginationSettings = assign({perPage, startingPage: 1}, paginationParams, queryParams);
return this.infinity.model(this.modelName, paginationSettings); return this.infinity.model(this.modelName, paginationSettings);
}, }
// trigger a background load of all tags, authors, and snipps for use in filter dropdowns and card menu // trigger a background load of all tags, authors, and snipps for use in filter dropdowns and card menu
setupController(controller) { setupController(controller) {
this._super(...arguments); super.setupController(...arguments);
if (!controller._hasLoadedTags) { if (!controller._hasLoadedTags) {
this.store.query('tag', {limit: 'all'}).then(() => { this.store.query('tag', {limit: 'all'}).then(() => {
@ -99,25 +99,24 @@ export default AuthenticatedRoute.extend({
controller._hasLoadedSnippets = true; controller._hasLoadedSnippets = true;
}); });
} }
}, }
actions: { @action
queryParamsDidChange() { queryParamsDidChange() {
// scroll back to the top // scroll back to the top
let contentList = document.querySelector('.content-list'); let contentList = document.querySelector('.content-list');
if (contentList) { if (contentList) {
contentList.scrollTop = 0; contentList.scrollTop = 0;
}
this._super(...arguments);
} }
},
super.actions.queryParamsDidChange.call(this, ...arguments);
}
buildRouteInfoMetadata() { buildRouteInfoMetadata() {
return { return {
titleToken: 'Posts' titleToken: 'Posts'
}; };
}, }
_getTypeFilters(type) { _getTypeFilters(type) {
let status = '[draft,scheduled,published,sent]'; let status = '[draft,scheduled,published,sent]';
@ -140,7 +139,7 @@ export default AuthenticatedRoute.extend({
return { return {
status status
}; };
}, }
_filterString(filter) { _filterString(filter) {
return Object.keys(filter).map((key) => { return Object.keys(filter).map((key) => {
@ -151,4 +150,4 @@ export default AuthenticatedRoute.extend({
} }
}).compact().join('+'); }).compact().join('+');
} }
}); }

View file

@ -1,18 +1,18 @@
import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
import {action} from '@ember/object';
import {inject as service} from '@ember/service'; import {inject as service} from '@ember/service';
// TODO: rename billing route and service to /pro export default class ProRoute extends AuthenticatedRoute {
export default AuthenticatedRoute.extend({ @service billing;
billing: service(), @service session;
session: service(), @service config;
config: service(),
queryParams: { queryParams = {
action: {refreshModel: true} action: {refreshModel: true}
}, };
beforeModel(transition) { beforeModel(transition) {
this._super(...arguments); super.beforeModel(...arguments);
// allow non-owner users to access the BMA when we're in a force upgrade state // allow non-owner users to access the BMA when we're in a force upgrade state
if (!this.session.user.isOwnerOnly && !this.config.get('hostSettings.forceUpgrade')) { if (!this.session.user.isOwnerOnly && !this.config.get('hostSettings.forceUpgrade')) {
@ -20,7 +20,7 @@ export default AuthenticatedRoute.extend({
} }
this.billing.set('previousTransition', transition); this.billing.set('previousTransition', transition);
}, }
model(params) { model(params) {
if (params.action) { if (params.action) {
@ -28,31 +28,30 @@ export default AuthenticatedRoute.extend({
} }
this.billing.toggleProWindow(true); this.billing.toggleProWindow(true);
}, }
actions: { @action
willTransition(transition) { willTransition(transition) {
let isBillingTransition = false; let isBillingTransition = false;
if (transition) { if (transition) {
let destinationUrl = (typeof transition.to === 'string') let destinationUrl = (typeof transition.to === 'string')
? transition.to ? transition.to
: (transition.intent : (transition.intent
? transition.intent.url ? transition.intent.url
: ''); : '');
if (destinationUrl?.includes('/pro')) { if (destinationUrl?.includes('/pro')) {
isBillingTransition = true; isBillingTransition = true;
}
} }
this.billing.toggleProWindow(isBillingTransition);
} }
},
this.billing.toggleProWindow(isBillingTransition);
}
buildRouteInfoMetadata() { buildRouteInfoMetadata() {
return { return {
titleToken: 'Ghost(Pro)' titleToken: 'Ghost(Pro)'
}; };
} }
}); }

View file

@ -1,25 +1,25 @@
import UnauthenticatedRoute from 'ghost-admin/routes/unauthenticated'; import UnauthenticatedRoute from 'ghost-admin/routes/unauthenticated';
import {inject as service} from '@ember/service'; import {inject as service} from '@ember/service';
export default UnauthenticatedRoute.extend({ export default class ResetRoute extends UnauthenticatedRoute {
notifications: service(), @service notifications;
session: service(), @service session;
beforeModel() { beforeModel() {
if (this.get('session.isAuthenticated')) { if (this.session.isAuthenticated) {
this.notifications.showAlert('You can\'t reset your password while you\'re signed in.', {type: 'warn', delayed: true, key: 'password.reset.signed-in'}); this.notifications.showAlert('You can\'t reset your password while you\'re signed in.', {type: 'warn', delayed: true, key: 'password.reset.signed-in'});
} }
this._super(...arguments); super.beforeModel(...arguments);
}, }
setupController(controller, params) { setupController(controller, params) {
controller.token = params.token; controller.token = params.token;
}, }
// Clear out any sensitive information // Clear out any sensitive information
deactivate() { deactivate() {
this._super(...arguments); super.deactivate(...arguments);
this.controller.clearData(); this.controller.clearData();
} }
}); }

View file

@ -1,11 +1,11 @@
import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
import {inject as service} from '@ember/service'; import {inject as service} from '@ember/service';
export default AuthenticatedRoute.extend({ export default class SettingsRoute extends AuthenticatedRoute {
session: service(), @service session;
beforeModel() { beforeModel() {
this._super(...arguments); super.beforeModel(...arguments);
const user = this.session.user; const user = this.session.user;
@ -13,4 +13,4 @@ export default AuthenticatedRoute.extend({
return this.transitionTo('settings.staff.user', user); return this.transitionTo('settings.staff.user', user);
} }
} }
}); }

View file

@ -1,14 +1,14 @@
import AdminRoute from 'ghost-admin/routes/admin'; import AdminRoute from 'ghost-admin/routes/admin';
export default AdminRoute.extend({ export default class EditRoute extends AdminRoute {
model(params) { model(params) {
let integration = this.modelFor('settings.integration'); let integration = this.modelFor('settings.integration');
let webhook = integration.webhooks.findBy('id', params.webhook_id); let webhook = integration.webhooks.findBy('id', params.webhook_id);
return webhook; return webhook;
}, }
deactivate() { deactivate() {
this._super(...arguments); super.deactivate(...arguments);
this.controller.reset(); this.controller.reset();
} }
}); }

View file

@ -1,13 +1,13 @@
import AdminRoute from 'ghost-admin/routes/admin'; import AdminRoute from 'ghost-admin/routes/admin';
export default AdminRoute.extend({ export default class NewRoute extends AdminRoute {
model() { model() {
let integration = this.modelFor('settings.integration'); let integration = this.modelFor('settings.integration');
return this.store.createRecord('webhook', {integration}); return this.store.createRecord('webhook', {integration});
}, }
deactivate() { deactivate() {
this._super(...arguments); super.deactivate(...arguments);
this.controller.webhook.rollbackAttributes(); this.controller.webhook.rollbackAttributes();
} }
}); }

View file

@ -1,18 +1,18 @@
import AdminRoute from 'ghost-admin/routes/admin'; import AdminRoute from 'ghost-admin/routes/admin';
import {inject as service} from '@ember/service'; import {inject as service} from '@ember/service';
export default AdminRoute.extend({ export default class IntegrationsRoute extends AdminRoute {
settings: service(), @service settings;
setupController(controller) { setupController(controller) {
// kick off the background fetch of integrations so that we can // kick off the background fetch of integrations so that we can
// show the screen immediately // show the screen immediately
controller.fetchIntegrations.perform(); controller.fetchIntegrations.perform();
}, }
buildRouteInfoMetadata() { buildRouteInfoMetadata() {
return { return {
titleToken: 'Settings - Integrations' titleToken: 'Settings - Integrations'
}; };
} }
}); }

View file

@ -1,27 +1,27 @@
import AdminRoute from 'ghost-admin/routes/admin'; import AdminRoute from 'ghost-admin/routes/admin';
import {inject as service} from '@ember/service'; import {inject as service} from '@ember/service';
export default AdminRoute.extend({ export default class ZapierRoute extends AdminRoute {
router: service(), @service router;
config: service(), @service config;
init() { constructor() {
this._super(...arguments); super(...arguments);
this.router.on('routeWillChange', () => { this.router.on('routeWillChange', () => {
if (this.controller) { if (this.controller) {
this.controller.set('selectedApiKey', null); this.controller.set('selectedApiKey', null);
this.controller.set('isApiKeyRegenerated', false); this.controller.set('isApiKeyRegenerated', false);
} }
}); });
}, }
beforeModel() { beforeModel() {
this._super(...arguments); super.beforeModel(...arguments);
if (this.config.get('hostSettings.limits.customIntegrations.disabled')) { if (this.config.get('hostSettings.limits.customIntegrations.disabled')) {
return this.transitionTo('settings.integrations'); return this.transitionTo('settings.integrations');
} }
}, }
model(params, transition) { model(params, transition) {
// use the integrations controller to fetch all integrations and pick // use the integrations controller to fetch all integrations and pick
@ -30,11 +30,11 @@ export default AdminRoute.extend({
return this return this
.controllerFor('settings.integrations') .controllerFor('settings.integrations')
.integrationModelHook('slug', 'zapier', this, transition); .integrationModelHook('slug', 'zapier', this, transition);
}, }
buildRouteInfoMetadata() { buildRouteInfoMetadata() {
return { return {
titleToken: 'Zapier' titleToken: 'Zapier'
}; };
} }
}); }

View file

@ -1,23 +1,23 @@
import AdminRoute from 'ghost-admin/routes/admin'; import AdminRoute from 'ghost-admin/routes/admin';
import {inject as service} from '@ember/service'; import {inject as service} from '@ember/service';
export default AdminRoute.extend({ export default class LabsRoute extends AdminRoute {
settings: service(), @service settings;
notifications: service(), @service notifications;
model() { model() {
return this.settings.reload(); return this.settings.reload();
}, }
resetController(controller, isExiting) { resetController(controller, isExiting) {
if (isExiting) { if (isExiting) {
controller.reset(); controller.reset();
} }
}, }
buildRouteInfoMetadata() { buildRouteInfoMetadata() {
return { return {
titleToken: 'Settings - Labs' titleToken: 'Settings - Labs'
}; };
} }
}); }

View file

@ -1,12 +1,13 @@
import AdminRoute from 'ghost-admin/routes/admin'; import AdminRoute from 'ghost-admin/routes/admin';
import {action} from '@ember/object';
import {inject as service} from '@ember/service'; import {inject as service} from '@ember/service';
export default AdminRoute.extend({ export default class MembersEmailRoute extends AdminRoute {
notifications: service(), @service notifications;
settings: service(), @service settings;
beforeModel(transition) { beforeModel(transition) {
this._super(...arguments); super.beforeModel(...arguments);
if (transition.to.queryParams?.fromAddressUpdate === 'success') { if (transition.to.queryParams?.fromAddressUpdate === 'success') {
this.notifications.showAlert( this.notifications.showAlert(
@ -19,25 +20,24 @@ export default AdminRoute.extend({
{type: 'success', key: 'members.settings.support-address.updated'} {type: 'success', key: 'members.settings.support-address.updated'}
); );
} }
}, }
model() { model() {
return this.settings.reload(); return this.settings.reload();
}, }
setupController(controller) { setupController(controller) {
controller.resetEmailAddresses(); controller.resetEmailAddresses();
}, }
actions: { @action
willTransition(transition) { willTransition(transition) {
return this.controller.leaveRoute(transition); return this.controller.leaveRoute(transition);
} }
},
buildRouteInfoMetadata() { buildRouteInfoMetadata() {
return { return {
titleToken: 'Settings - Members' titleToken: 'Settings - Members'
}; };
} }
}); }

View file

@ -1,28 +1,28 @@
import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
import {action} from '@ember/object';
import {inject as service} from '@ember/service'; import {inject as service} from '@ember/service';
export default AuthenticatedRoute.extend({ export default class IndexRoute extends AuthenticatedRoute {
infinity: service(), @service infinity;
session: service(), @service session;
model() { model() {
return this.session.user; return this.session.user;
}, }
setupController(controller) { setupController(controller) {
this._super(...arguments); super.setupController(...arguments);
controller.backgroundUpdate.perform(); controller.backgroundUpdate.perform();
}, }
actions: { @action
reload() { reload() {
this.controller.backgroundUpdate.perform(); this.controller.backgroundUpdate.perform();
} }
},
buildRouteInfoMetadata() { buildRouteInfoMetadata() {
return { return {
titleToken: 'Staff' titleToken: 'Staff'
}; };
} }
}); }

View file

@ -1,13 +1,14 @@
import {action} from '@ember/object';
/* eslint-disable camelcase */ /* eslint-disable camelcase */
import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
export default AuthenticatedRoute.extend({ export default class UserRoute extends AuthenticatedRoute {
model(params) { model(params) {
return this.store.queryRecord('user', {slug: params.user_slug, include: 'count.posts'}); return this.store.queryRecord('user', {slug: params.user_slug, include: 'count.posts'});
}, }
afterModel(user) { afterModel(user) {
this._super(...arguments); super.afterModel(...arguments);
const currentUser = this.session.user; const currentUser = this.session.user;
@ -27,45 +28,46 @@ export default AuthenticatedRoute.extend({
this.controller.set('personalTokenRegenerated', false); this.controller.set('personalTokenRegenerated', false);
}); });
} }
}, }
serialize(model) { serialize(model) {
return {user_slug: model.get('slug')}; return {user_slug: model.get('slug')};
}, }
actions: { @action
didTransition() { didTransition() {
this.modelFor('settings.staff.user').get('errors').clear(); this.modelFor('settings.staff.user').get('errors').clear();
}, }
save() { @action
this.get('controller.save').perform(); save() {
}, this.controller.save.perform();
}
willTransition(transition) { @action
let controller = this.controller; willTransition(transition) {
let user = controller.user; let controller = this.controller;
let dirtyAttributes = controller.dirtyAttributes; let user = controller.user;
let modelIsDirty = user.get('hasDirtyAttributes'); let dirtyAttributes = controller.dirtyAttributes;
let modelIsDirty = user.get('hasDirtyAttributes');
// always reset the password properties on the user model when leaving // always reset the password properties on the user model when leaving
if (user) { if (user) {
user.set('password', ''); user.set('password', '');
user.set('newPassword', ''); user.set('newPassword', '');
user.set('ne2Password', ''); user.set('ne2Password', '');
}
if (modelIsDirty || dirtyAttributes) {
transition.abort();
controller.send('toggleLeaveSettingsModal', transition);
return;
}
} }
},
if (modelIsDirty || dirtyAttributes) {
transition.abort();
controller.send('toggleLeaveSettingsModal', transition);
return;
}
}
buildRouteInfoMetadata() { buildRouteInfoMetadata() {
return { return {
titleToken: 'Staff - User' titleToken: 'Staff - User'
}; };
} }
}); }

View file

@ -1,22 +1,22 @@
import Route from '@ember/routing/route'; import Route from '@ember/routing/route';
import {inject as service} from '@ember/service'; import {inject as service} from '@ember/service';
export default Route.extend({ export default class SetupRoute extends Route {
ghostPaths: service(), @service ghostPaths;
session: service(), @service session;
ajax: service(), @service ajax;
config: service(), @service config;
// use the beforeModel hook to check to see whether or not setup has been // use the beforeModel hook to check to see whether or not setup has been
// previously completed. If it has, stop the transition into the setup page. // previously completed. If it has, stop the transition into the setup page.
beforeModel() { beforeModel() {
this._super(...arguments); super.beforeModel(...arguments);
if (this.get('session.isAuthenticated')) { if (this.session.isAuthenticated) {
return this.transitionTo('home'); return this.transitionTo('home');
} }
let authUrl = this.get('ghostPaths.url').api('authentication', 'setup'); let authUrl = this.ghostPaths.url.api('authentication', 'setup');
// check the state of the setup process via the API // check the state of the setup process via the API
return this.ajax.request(authUrl) return this.ajax.request(authUrl)
@ -40,12 +40,12 @@ export default Route.extend({
} }
} }
}); });
}, }
deactivate() { deactivate() {
this._super(...arguments); super.deactivate(...arguments);
this.controllerFor('setup/two').set('password', ''); this.controllerFor('setup/two').set('password', '');
}, }
buildRouteInfoMetadata() { buildRouteInfoMetadata() {
return { return {
@ -54,4 +54,4 @@ export default Route.extend({
mainClasses: ['gh-main-white'] mainClasses: ['gh-main-white']
}; };
} }
}); }

View file

@ -1,8 +1,8 @@
import Route from '@ember/routing/route'; import Route from '@ember/routing/route';
export default Route.extend({ export default class IndexRoute extends Route {
beforeModel() { beforeModel() {
this._super(...arguments); super.beforeModel(...arguments);
this.transitionTo('setup.one'); this.transitionTo('setup.one');
} }
}); }

View file

@ -1,10 +1,10 @@
import Route from '@ember/routing/route'; import Route from '@ember/routing/route';
export default Route.extend({ export default class ThreeRoute extends Route {
beforeModel() { beforeModel() {
this._super(...arguments); super.beforeModel(...arguments);
if (!this.controllerFor('setup.two').get('blogCreated')) { if (!this.controllerFor('setup.two').get('blogCreated')) {
this.transitionTo('setup.two'); this.transitionTo('setup.two');
} }
} }
}); }

View file

@ -14,24 +14,24 @@ const defaultModel = function defaultModel() {
}); });
}; };
export default UnauthenticatedRoute.extend({ export default class SigninRoute extends UnauthenticatedRoute {
model() { model() {
return defaultModel(); return defaultModel();
}, }
// the deactivate hook is called after a route has been exited. // the deactivate hook is called after a route has been exited.
deactivate() { deactivate() {
let controller = this.controllerFor('signin'); let controller = this.controllerFor('signin');
this._super(...arguments); super.deactivate(...arguments);
// clear the properties that hold the credentials when we're no longer on the signin screen // clear the properties that hold the credentials when we're no longer on the signin screen
controller.set('signin', defaultModel()); controller.set('signin', defaultModel());
}, }
buildRouteInfoMetadata() { buildRouteInfoMetadata() {
return Object.assign(this._super(), { return Object.assign(super.buildRouteInfoMetadata(), {
titleToken: 'Sign In' titleToken: 'Sign In'
}); });
} }
}); }

View file

@ -1,17 +1,17 @@
import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
import {inject as service} from '@ember/service'; import {inject as service} from '@ember/service';
export default AuthenticatedRoute.extend({ export default class SignoutRoute extends AuthenticatedRoute {
notifications: service(), @service notifications;
afterModel(/*model, transition*/) { afterModel/*model, transition*/() {
this.notifications.clearAll(); this.notifications.clearAll();
this.session.invalidate(); this.session.invalidate();
}, }
buildRouteInfoMetadata() { buildRouteInfoMetadata() {
return { return {
titleToken: 'Sign Out' titleToken: 'Sign Out'
}; };
} }
}); }

View file

@ -1,3 +1,4 @@
import {inject as service} from '@ember/service';
// TODO: remove usage of Ember Data's private `Errors` class when refactoring validations // TODO: remove usage of Ember Data's private `Errors` class when refactoring validations
// eslint-disable-next-line // eslint-disable-next-line
import DS from 'ember-data'; import DS from 'ember-data';
@ -5,30 +6,32 @@ import EmberObject from '@ember/object';
import RSVP from 'rsvp'; import RSVP from 'rsvp';
import UnauthenticatedRoute from 'ghost-admin/routes/unauthenticated'; import UnauthenticatedRoute from 'ghost-admin/routes/unauthenticated';
import ValidationEngine from 'ghost-admin/mixins/validation-engine'; import ValidationEngine from 'ghost-admin/mixins/validation-engine';
import {inject as service} from '@ember/service'; import classic from 'ember-classic-decorator';
const {Promise} = RSVP; const {Promise} = RSVP;
const {Errors} = DS; const {Errors} = DS;
export default UnauthenticatedRoute.extend({ export default class SignupRoute extends UnauthenticatedRoute {
ghostPaths: service(), @service ghostPaths;
notifications: service(), @service notifications;
session: service(), @service session;
ajax: service(), @service ajax;
config: service(), @service config;
beforeModel() { beforeModel() {
if (this.get('session.isAuthenticated')) { if (this.session.isAuthenticated) {
this.notifications.showAlert('You need to sign out to register as a new user.', {type: 'warn', delayed: true, key: 'signup.create.already-authenticated'}); this.notifications.showAlert('You need to sign out to register as a new user.', {type: 'warn', delayed: true, key: 'signup.create.already-authenticated'});
} }
this._super(...arguments); super.beforeModel(...arguments);
}, }
model(params) { model(params) {
let SignupDetails = EmberObject.extend(ValidationEngine, { @classic
validationType: 'signup' class SignupDetails extends EmberObject.extend(ValidationEngine) {
}); validationType = 'signup';
}
let signupDetails = SignupDetails.create(); let signupDetails = SignupDetails.create();
let re = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2}|[A-Za-z0-9_-]{3})?$/; let re = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2}|[A-Za-z0-9_-]{3})?$/;
let email, let email,
@ -73,12 +76,12 @@ export default UnauthenticatedRoute.extend({
resolve(signupDetails); resolve(signupDetails);
}); });
}); });
}, }
deactivate() { deactivate() {
this._super(...arguments); super.deactivate(...arguments);
// clear the properties that hold the sensitive data from the controller // clear the properties that hold the sensitive data from the controller
this.controllerFor('signup').get('signupDetails').setProperties({email: '', password: '', token: ''}); this.controllerFor('signup').get('signupDetails').setProperties({email: '', password: '', token: ''});
} }
}); }

View file

@ -1,20 +1,20 @@
import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
import {inject as service} from '@ember/service'; import {inject as service} from '@ember/service';
export default AuthenticatedRoute.extend({ export default class SiteRoute extends AuthenticatedRoute {
config: service(), @service config;
settings: service(), @service settings;
ui: service(), @service ui;
_hasLoggedIn: false, _hasLoggedIn = false;
model() { model() {
return (new Date()).valueOf(); return (new Date()).valueOf();
}, }
buildRouteInfoMetadata() { buildRouteInfoMetadata() {
return { return {
titleToken: 'Site' titleToken: 'Site'
}; };
} }
}); }

View file

@ -1,6 +1,6 @@
import TagRoute from '../tag'; import TagRoute from '../tag';
export default TagRoute.extend({ export default class NewRoute extends TagRoute {
controllerName: 'tag', controllerName = 'tag';
templateName: 'tag' templateName = 'tag';
}); }

View file

@ -1,21 +1,21 @@
import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
export default AuthenticatedRoute.extend({ export default class TagsRoute extends AuthenticatedRoute {
queryParams: { queryParams = {
type: { type: {
refreshModel: true, refreshModel: true,
replace: true replace: true
} }
}, };
// authors aren't allowed to manage tags // authors aren't allowed to manage tags
beforeModel() { beforeModel() {
this._super(...arguments); super.beforeModel(...arguments);
if (this.session.user.isAuthorOrContributor) { if (this.session.user.isAuthorOrContributor) {
return this.transitionTo('home'); return this.transitionTo('home');
} }
}, }
// set model to a live array so all tags are shown and created/deleted tags // set model to a live array so all tags are shown and created/deleted tags
// are automatically added/removed. Also load all tags in the background, // are automatically added/removed. Also load all tags in the background,
@ -28,11 +28,11 @@ export default AuthenticatedRoute.extend({
} else { } else {
return tags; return tags;
} }
}, }
buildRouteInfoMetadata() { buildRouteInfoMetadata() {
return { return {
titleToken: 'Tags' titleToken: 'Tags'
}; };
} }
}); }

View file

@ -1,9 +1,9 @@
import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
export default AuthenticatedRoute.extend({ export default class WhatsnewRoute extends AuthenticatedRoute {
buildRouteInfoMetadata() { buildRouteInfoMetadata() {
return { return {
titleToken: `What's new?` titleToken: `What's new?`
}; };
} }
}); }