mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Removed usage of deprecated EmberSimpleAuth mixins (#1910)
refs https://github.com/TryGhost/Admin/pull/1901 Ember has deprecated mixins in preparation for 4.0 and `ember-simple-auth` has now done the same in 3.1.0. - removed all imports of Ember Simple Auth mixins - moved authenticated and invalidated handling from application route to session service - moved server-notification loading from application route to session service - updated `AuthenticatedRoute` to use the session service directly rather than authenticated route mixin - added `UnauthenticatedRoute` that incorporates the behaviour from our overridden `UnauthenticatedRouteMixin` and switches to using the session service directly
This commit is contained in:
parent
eb28e42ad4
commit
cf7a763199
10 changed files with 107 additions and 120 deletions
|
@ -1,10 +1,9 @@
|
||||||
import AjaxServiceSupport from 'ember-ajax/mixins/ajax-support';
|
import AjaxServiceSupport from 'ember-ajax/mixins/ajax-support';
|
||||||
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
|
|
||||||
import RESTAdapter from '@ember-data/adapter/rest';
|
import RESTAdapter from '@ember-data/adapter/rest';
|
||||||
import ghostPaths from 'ghost-admin/utils/ghost-paths';
|
import ghostPaths from 'ghost-admin/utils/ghost-paths';
|
||||||
import {inject as service} from '@ember/service';
|
import {inject as service} from '@ember/service';
|
||||||
|
|
||||||
export default RESTAdapter.extend(DataAdapterMixin, AjaxServiceSupport, {
|
export default RESTAdapter.extend(AjaxServiceSupport, {
|
||||||
host: window.location.origin,
|
host: window.location.origin,
|
||||||
namespace: ghostPaths().apiRoot.slice(1),
|
namespace: ghostPaths().apiRoot.slice(1),
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ const {Errors} = DS;
|
||||||
export default Controller.extend({
|
export default Controller.extend({
|
||||||
two: controller('setup/two'),
|
two: controller('setup/two'),
|
||||||
notifications: service(),
|
notifications: service(),
|
||||||
|
session: service(),
|
||||||
|
|
||||||
users: '',
|
users: '',
|
||||||
|
|
||||||
|
@ -123,7 +124,7 @@ export default Controller.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
skipInvite() {
|
skipInvite() {
|
||||||
this.send('loadServerNotifications');
|
this.session.loadServerNotifications();
|
||||||
this.transitionToRoute('home');
|
this.transitionToRoute('home');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -176,7 +177,7 @@ export default Controller.extend({
|
||||||
this._showNotifications(invites);
|
this._showNotifications(invites);
|
||||||
|
|
||||||
run.schedule('actions', this, function () {
|
run.schedule('actions', this, function () {
|
||||||
this.send('loadServerNotifications');
|
this.session.loadServerNotifications();
|
||||||
this._transitionAfterSubmission();
|
this._transitionAfterSubmission();
|
||||||
});
|
});
|
||||||
} else if (users.length === 0) {
|
} else if (users.length === 0) {
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
import Mixin from '@ember/object/mixin';
|
|
||||||
import {inject as service} from '@ember/service';
|
|
||||||
|
|
||||||
export default Mixin.create({
|
|
||||||
|
|
||||||
ajax: service(),
|
|
||||||
ghostPaths: service(),
|
|
||||||
session: service(),
|
|
||||||
|
|
||||||
routeIfAlreadyAuthenticated: 'home',
|
|
||||||
|
|
||||||
beforeModel() {
|
|
||||||
let authUrl = this.get('ghostPaths.url').api('authentication', 'setup');
|
|
||||||
|
|
||||||
// check the state of the setup process via the API
|
|
||||||
return this.ajax.request(authUrl).then((result) => {
|
|
||||||
let [setup] = result.setup;
|
|
||||||
|
|
||||||
if (setup.status !== true) {
|
|
||||||
this.transitionTo('setup');
|
|
||||||
} else {
|
|
||||||
// NOTE: this is the same as ESA's UnauthenticatedRouteMixin,
|
|
||||||
// adding that mixin to this and calling _super wasn't calling
|
|
||||||
// the ESA mixin's beforeModel method
|
|
||||||
if (this.session.get('isAuthenticated')) {
|
|
||||||
let routeIfAlreadyAuthenticated = this.routeIfAlreadyAuthenticated;
|
|
||||||
|
|
||||||
return this.transitionTo(routeIfAlreadyAuthenticated);
|
|
||||||
} else {
|
|
||||||
return this._super(...arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
|
@ -1,4 +1,3 @@
|
||||||
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
|
|
||||||
import AuthConfiguration from 'ember-simple-auth/configuration';
|
import AuthConfiguration from 'ember-simple-auth/configuration';
|
||||||
import RSVP from 'rsvp';
|
import RSVP from 'rsvp';
|
||||||
import Route from '@ember/routing/route';
|
import Route from '@ember/routing/route';
|
||||||
|
@ -15,7 +14,6 @@ import {
|
||||||
isMaintenanceError,
|
isMaintenanceError,
|
||||||
isVersionMismatchError
|
isVersionMismatchError
|
||||||
} from 'ghost-admin/services/ajax';
|
} from 'ghost-admin/services/ajax';
|
||||||
import {run} from '@ember/runloop';
|
|
||||||
import {inject as service} from '@ember/service';
|
import {inject as service} from '@ember/service';
|
||||||
|
|
||||||
function K() {
|
function K() {
|
||||||
|
@ -27,13 +25,14 @@ let shortcuts = {};
|
||||||
shortcuts.esc = {action: 'closeMenus', scope: 'default'};
|
shortcuts.esc = {action: 'closeMenus', scope: 'default'};
|
||||||
shortcuts[`${ctrlOrCmd}+s`] = {action: 'save', scope: 'all'};
|
shortcuts[`${ctrlOrCmd}+s`] = {action: 'save', scope: 'all'};
|
||||||
|
|
||||||
export default Route.extend(ApplicationRouteMixin, ShortcutsRoute, {
|
export default Route.extend(ShortcutsRoute, {
|
||||||
ajax: service(),
|
ajax: service(),
|
||||||
config: service(),
|
config: service(),
|
||||||
feature: service(),
|
feature: service(),
|
||||||
ghostPaths: service(),
|
ghostPaths: service(),
|
||||||
notifications: service(),
|
notifications: service(),
|
||||||
router: service(),
|
router: service(),
|
||||||
|
session: service(),
|
||||||
settings: service(),
|
settings: service(),
|
||||||
ui: service(),
|
ui: service(),
|
||||||
whatsNew: service(),
|
whatsNew: service(),
|
||||||
|
@ -57,8 +56,8 @@ export default Route.extend(ApplicationRouteMixin, ShortcutsRoute, {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
|
|
||||||
if (this.get('session.isAuthenticated')) {
|
if (this.get('session.isAuthenticated')) {
|
||||||
this.set('appLoadTransition', transition);
|
this.session.appLoadTransition = transition;
|
||||||
transition.send('loadServerNotifications');
|
this.session.loadServerNotifications();
|
||||||
|
|
||||||
// return the feature/settings load promises so that we block until
|
// return the feature/settings load promises so that we block until
|
||||||
// they are loaded to enable synchronous access everywhere
|
// they are loaded to enable synchronous access everywhere
|
||||||
|
@ -87,37 +86,14 @@ export default Route.extend(ApplicationRouteMixin, ShortcutsRoute, {
|
||||||
},
|
},
|
||||||
|
|
||||||
didTransition() {
|
didTransition() {
|
||||||
this.set('appLoadTransition', null);
|
this.session.appLoadTransition = null;
|
||||||
this.send('closeMenus');
|
this.send('closeMenus');
|
||||||
},
|
},
|
||||||
|
|
||||||
signedIn() {
|
|
||||||
this.notifications.clearAll();
|
|
||||||
this.send('loadServerNotifications', true);
|
|
||||||
},
|
|
||||||
|
|
||||||
authorizationFailed() {
|
authorizationFailed() {
|
||||||
windowProxy.replaceLocation(AuthConfiguration.rootURL);
|
windowProxy.replaceLocation(AuthConfiguration.rootURL);
|
||||||
},
|
},
|
||||||
|
|
||||||
loadServerNotifications(isDelayed) {
|
|
||||||
if (this.get('session.isAuthenticated')) {
|
|
||||||
this.get('session.user').then((user) => {
|
|
||||||
if (!user.get('isAuthorOrContributor')) {
|
|
||||||
this.store.findAll('notification', {reload: true}).then((serverNotifications) => {
|
|
||||||
serverNotifications.forEach((notification) => {
|
|
||||||
if (notification.get('top') || notification.get('custom')) {
|
|
||||||
this.notifications.handleNotification(notification, isDelayed);
|
|
||||||
} else {
|
|
||||||
this.upgradeStatus.handleUpgradeNotification(notification);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// noop default for unhandled save (used from shortcuts)
|
// noop default for unhandled save (used from shortcuts)
|
||||||
save: K,
|
save: K,
|
||||||
|
|
||||||
|
@ -183,29 +159,5 @@ export default Route.extend(ApplicationRouteMixin, ShortcutsRoute, {
|
||||||
// fallback to 500 error page
|
// fallback to 500 error page
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
sessionAuthenticated() {
|
|
||||||
if (this.get('session.skipAuthSuccessHandler')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// standard ESA post-sign-in redirect
|
|
||||||
this._super(...arguments);
|
|
||||||
|
|
||||||
// trigger post-sign-in background behaviour
|
|
||||||
this.get('session.user').then((user) => {
|
|
||||||
this.send('signedIn', user);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
sessionInvalidated() {
|
|
||||||
let transition = this.appLoadTransition;
|
|
||||||
|
|
||||||
if (transition) {
|
|
||||||
transition.send('authorizationFailed');
|
|
||||||
} else {
|
|
||||||
run.scheduleOnce('routerTransitions', this, 'send', 'authorizationFailed');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
|
||||||
import Route from '@ember/routing/route';
|
import Route from '@ember/routing/route';
|
||||||
|
import {inject as service} from '@ember/service';
|
||||||
|
|
||||||
export default Route.extend(AuthenticatedRouteMixin, {
|
export default Route.extend({
|
||||||
authenticationRoute: 'signin'
|
session: service(),
|
||||||
|
|
||||||
|
beforeModel(transition) {
|
||||||
|
this.session.requireAuthentication(transition, 'signin');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import Route from '@ember/routing/route';
|
import UnauthenticatedRoute from 'ghost-admin/routes/unauthenticated';
|
||||||
import UnauthenticatedRouteMixin from 'ghost-admin/mixins/unauthenticated-route-mixin';
|
|
||||||
import {inject as service} from '@ember/service';
|
import {inject as service} from '@ember/service';
|
||||||
|
|
||||||
export default Route.extend(UnauthenticatedRouteMixin, {
|
export default UnauthenticatedRoute.extend({
|
||||||
notifications: service(),
|
notifications: service(),
|
||||||
session: service(),
|
session: service(),
|
||||||
|
|
||||||
|
@ -22,11 +21,5 @@ export default Route.extend(UnauthenticatedRouteMixin, {
|
||||||
deactivate() {
|
deactivate() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
this.controller.clearData();
|
this.controller.clearData();
|
||||||
},
|
|
||||||
|
|
||||||
buildRouteInfoMetadata() {
|
|
||||||
return {
|
|
||||||
bodyClasses: ['unauthenticated-route']
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
import DS from 'ember-data';
|
import DS from 'ember-data';
|
||||||
import EmberObject from '@ember/object';
|
import EmberObject from '@ember/object';
|
||||||
import Route from '@ember/routing/route';
|
import UnauthenticatedRoute from 'ghost-admin/routes/unauthenticated';
|
||||||
import UnauthenticatedRouteMixin from 'ghost-admin/mixins/unauthenticated-route-mixin';
|
|
||||||
|
|
||||||
const {Errors} = DS;
|
const {Errors} = DS;
|
||||||
|
|
||||||
|
@ -15,7 +14,7 @@ const defaultModel = function defaultModel() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Route.extend(UnauthenticatedRouteMixin, {
|
export default UnauthenticatedRoute.extend({
|
||||||
model() {
|
model() {
|
||||||
return defaultModel();
|
return defaultModel();
|
||||||
},
|
},
|
||||||
|
@ -31,9 +30,8 @@ export default Route.extend(UnauthenticatedRouteMixin, {
|
||||||
},
|
},
|
||||||
|
|
||||||
buildRouteInfoMetadata() {
|
buildRouteInfoMetadata() {
|
||||||
return {
|
return Object.assign(this._super(), {
|
||||||
titleToken: 'Sign In',
|
titleToken: 'Sign In'
|
||||||
bodyClasses: ['unauthenticated-route']
|
});
|
||||||
};
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,15 +3,14 @@
|
||||||
import DS from 'ember-data';
|
import DS from 'ember-data';
|
||||||
import EmberObject from '@ember/object';
|
import EmberObject from '@ember/object';
|
||||||
import RSVP from 'rsvp';
|
import RSVP from 'rsvp';
|
||||||
import Route from '@ember/routing/route';
|
import UnauthenticatedRoute from 'ghost-admin/routes/unauthenticated';
|
||||||
import UnauthenticatedRouteMixin from 'ghost-admin/mixins/unauthenticated-route-mixin';
|
|
||||||
import ValidationEngine from 'ghost-admin/mixins/validation-engine';
|
import ValidationEngine from 'ghost-admin/mixins/validation-engine';
|
||||||
import {inject as service} from '@ember/service';
|
import {inject as service} from '@ember/service';
|
||||||
|
|
||||||
const {Promise} = RSVP;
|
const {Promise} = RSVP;
|
||||||
const {Errors} = DS;
|
const {Errors} = DS;
|
||||||
|
|
||||||
export default Route.extend(UnauthenticatedRouteMixin, {
|
export default UnauthenticatedRoute.extend({
|
||||||
ghostPaths: service(),
|
ghostPaths: service(),
|
||||||
notifications: service(),
|
notifications: service(),
|
||||||
session: service(),
|
session: service(),
|
||||||
|
@ -81,11 +80,5 @@ export default Route.extend(UnauthenticatedRouteMixin, {
|
||||||
|
|
||||||
// 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: ''});
|
||||||
},
|
|
||||||
|
|
||||||
buildRouteInfoMetadata() {
|
|
||||||
return {
|
|
||||||
bodyClasses: ['unauthenticated-route']
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
29
ghost/admin/app/routes/unauthenticated.js
Normal file
29
ghost/admin/app/routes/unauthenticated.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import Route from '@ember/routing/route';
|
||||||
|
import {inject as service} from '@ember/service';
|
||||||
|
|
||||||
|
export default class UnauthenticatedRoute extends Route {
|
||||||
|
@service ajax;
|
||||||
|
@service ghostPaths;
|
||||||
|
@service session;
|
||||||
|
|
||||||
|
beforeModel() {
|
||||||
|
let authUrl = this.ghostPaths.url.api('authentication', 'setup');
|
||||||
|
|
||||||
|
// check the state of the setup process via the API
|
||||||
|
return this.ajax.request(authUrl).then((result) => {
|
||||||
|
let [setup] = result.setup;
|
||||||
|
|
||||||
|
if (setup.status !== true) {
|
||||||
|
this.transitionTo('setup');
|
||||||
|
} else {
|
||||||
|
return this.session.prohibitAuthentication('home');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
buildRouteInfoMetadata() {
|
||||||
|
return {
|
||||||
|
bodyClasses: ['unauthenticated-route']
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,14 @@
|
||||||
import SessionService from 'ember-simple-auth/services/session';
|
import SessionService from 'ember-simple-auth/services/session';
|
||||||
import {computed} from '@ember/object';
|
import {computed} from '@ember/object';
|
||||||
|
import {getOwner} from '@ember/application';
|
||||||
|
import {run} from '@ember/runloop';
|
||||||
import {inject as service} from '@ember/service';
|
import {inject as service} from '@ember/service';
|
||||||
|
|
||||||
export default SessionService.extend({
|
export default SessionService.extend({
|
||||||
dataStore: service('store'), // SessionService.store already exists
|
dataStore: service('store'), // SessionService.store already exists
|
||||||
|
notifications: service(),
|
||||||
|
router: service(),
|
||||||
|
upgradeStatus: service(),
|
||||||
|
|
||||||
user: computed(function () {
|
user: computed(function () {
|
||||||
return this.dataStore.queryRecord('user', {id: 'me'});
|
return this.dataStore.queryRecord('user', {id: 'me'});
|
||||||
|
@ -14,5 +19,53 @@ export default SessionService.extend({
|
||||||
this.notifyPropertyChange('user');
|
this.notifyPropertyChange('user');
|
||||||
|
|
||||||
return this._super(...arguments);
|
return this._super(...arguments);
|
||||||
|
},
|
||||||
|
|
||||||
|
handleAuthentication() {
|
||||||
|
if (this.skipAuthSuccessHandler) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// standard ESA post-sign-in redirect
|
||||||
|
this._super('home');
|
||||||
|
|
||||||
|
// trigger post-sign-in background behaviour
|
||||||
|
this.user.then(() => {
|
||||||
|
this.notifications.clearAll();
|
||||||
|
this.loadServerNotifications();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
handleInvalidation() {
|
||||||
|
let transition = this.appLoadTransition;
|
||||||
|
|
||||||
|
if (transition) {
|
||||||
|
transition.send('authorizationFailed');
|
||||||
|
} else {
|
||||||
|
run.scheduleOnce('routerTransitions', this, 'triggerAuthorizationFailed');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// TODO: this feels hacky, find a better way than using .send
|
||||||
|
triggerAuthorizationFailed() {
|
||||||
|
getOwner(this).lookup(`route:${this.router.currentRouteName}`).send('authorizationFailed');
|
||||||
|
},
|
||||||
|
|
||||||
|
loadServerNotifications() {
|
||||||
|
if (this.isAuthenticated) {
|
||||||
|
this.user.then((user) => {
|
||||||
|
if (!user.isAuthorOrContributor) {
|
||||||
|
this.dataStore.findAll('notification', {reload: true}).then((serverNotifications) => {
|
||||||
|
serverNotifications.forEach((notification) => {
|
||||||
|
if (notification.top || notification.custom) {
|
||||||
|
this.notifications.handleNotification(notification);
|
||||||
|
} else {
|
||||||
|
this.upgradeStatus.handleUpgradeNotification(notification);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue