mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 22:02:11 +03:00
cb59388c5b
no issue - adds `eslint-plugin-sort-imports-es6-autofix` dependency - implements ESLint's base `sort-imports` rule but has a distinction in that `import {foo} from 'bar';` is considered `multiple` rather than `single` - fixes ESLint's autofix behaviour so `eslint --fix` will actually fix the sort order - updates all unordered import rules by using `eslint --fix` With the increased number of `import` statements since Ember+ecosystem started moving towards es6 modules I've found it frustrating at times trying to search through randomly ordered import statements. Recently I've been sorting imports manually when I've added new code or touched old code so I thought I'd add an ESLint rule to codify it.
99 lines
4.0 KiB
JavaScript
99 lines
4.0 KiB
JavaScript
/* eslint-disable camelcase */
|
|
import $ from 'jquery';
|
|
import {Response} from 'ember-cli-mirage';
|
|
import {isBlank} from 'ember-utils';
|
|
|
|
export default function mockAuthentication(server) {
|
|
server.post('/authentication/token', function ({roles, users}, {requestBody}) {
|
|
let params = $.deparam(requestBody);
|
|
|
|
if (params.grant_type === 'authorization_code') {
|
|
// OAuth sign-in
|
|
if (!users.all().models.length) {
|
|
let role = roles.findBy({name: 'Owner'});
|
|
server.create('user', {email: 'oauthtest@example.com', roles: [role]});
|
|
}
|
|
|
|
return {
|
|
access_token: '5JhTdKI7PpoZv4ROsFoERc6wCHALKFH5jxozwOOAErmUzWrFNARuH1q01TYTKeZkPW7FmV5MJ2fU00pg9sm4jtH3Z1LjCf8D6nNqLYCfFb2YEKyuvG7zHj4jZqSYVodN2YTCkcHv6k8oJ54QXzNTLIDMlCevkOebm5OjxGiJpafMxncm043q9u1QhdU9eee3zouGRMVVp8zkKVoo5zlGMi3zvS2XDpx7xsfk8hKHpUgd7EDDQxmMueifWv7hv6n',
|
|
expires_in: 3600,
|
|
refresh_token: 'XP13eDjwV5mxOcrq1jkIY9idhdvN3R1Br5vxYpYIub2P5Hdc8pdWMOGmwFyoUshiEB62JWHTl8H1kACJR18Z8aMXbnk5orG28br2kmVgtVZKqOSoiiWrQoeKTqrRV0t7ua8uY5HdDUaKpnYKyOdpagsSPn3WEj8op4vHctGL3svOWOjZhq6F2XeVPMR7YsbiwBE8fjT3VhTB3KRlBtWZd1rE0Qo2EtSplWyjGKv1liAEiL0ndQoLeeSOCH4rTP7'
|
|
};
|
|
} else {
|
|
// Password sign-in
|
|
return {
|
|
access_token: '5JhTdKI7PpoZv4ROsFoERc6wCHALKFH5jxozwOOAErmUzWrFNARuH1q01TYTKeZkPW7FmV5MJ2fU00pg9sm4jtH3Z1LjCf8D6nNqLYCfFb2YEKyuvG7zHj4jZqSYVodN2YTCkcHv6k8oJ54QXzNTLIDMlCevkOebm5OjxGiJpafMxncm043q9u1QhdU9eee3zouGRMVVp8zkKVoo5zlGMi3zvS2XDpx7xsfk8hKHpUgd7EDDQxmMueifWv7hv6n',
|
|
expires_in: 3600,
|
|
refresh_token: 'XP13eDjwV5mxOcrq1jkIY9idhdvN3R1Br5vxYpYIub2P5Hdc8pdWMOGmwFyoUshiEB62JWHTl8H1kACJR18Z8aMXbnk5orG28br2kmVgtVZKqOSoiiWrQoeKTqrRV0t7ua8uY5HdDUaKpnYKyOdpagsSPn3WEj8op4vHctGL3svOWOjZhq6F2XeVPMR7YsbiwBE8fjT3VhTB3KRlBtWZd1rE0Qo2EtSplWyjGKv1liAEiL0ndQoLeeSOCH4rTP7',
|
|
token_type: 'Bearer'
|
|
};
|
|
}
|
|
});
|
|
|
|
server.post('/authentication/passwordreset', function (schema, request) {
|
|
let {passwordreset} = JSON.parse(request.requestBody);
|
|
// eslint-disable-next-line ember-suave/prefer-destructuring
|
|
let email = passwordreset[0].email;
|
|
|
|
if (email === 'unknown@example.com') {
|
|
return new Response(404, {}, {
|
|
errors: [
|
|
{
|
|
message: 'There is no user with that email address.',
|
|
errorType: 'NotFoundError'
|
|
}
|
|
]
|
|
});
|
|
} else {
|
|
return {
|
|
passwordreset: [
|
|
{message: 'Check your email for further instructions.'}
|
|
]
|
|
};
|
|
}
|
|
});
|
|
|
|
server.get('/authentication/invitation/', function (schema, request) {
|
|
let {email} = request.queryParams;
|
|
let invite = schema.invites.findBy({email});
|
|
let user = schema.users.find(invite.createdBy);
|
|
let valid = !!invite;
|
|
let invitedBy = user && user.name;
|
|
|
|
return {
|
|
invitation: [{
|
|
valid,
|
|
invitedBy
|
|
}]
|
|
};
|
|
});
|
|
|
|
/* Setup ---------------------------------------------------------------- */
|
|
|
|
server.post('/authentication/setup', function ({roles, users}, request) {
|
|
let [attrs] = JSON.parse(request.requestBody).setup;
|
|
let role = roles.findBy({name: 'Owner'});
|
|
|
|
// create owner role unless already exists
|
|
if (!role) {
|
|
role = roles.create({name: 'Owner'});
|
|
}
|
|
attrs.roles = [role];
|
|
|
|
if (!isBlank(attrs.email)) {
|
|
attrs.slug = attrs.email.split('@')[0].dasherize();
|
|
}
|
|
|
|
// NOTE: server does not use the user factory to fill in blank fields
|
|
return users.create(attrs);
|
|
});
|
|
|
|
server.get('/authentication/setup/', function () {
|
|
return {
|
|
setup: [
|
|
{status: true}
|
|
]
|
|
};
|
|
});
|
|
}
|