This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
requires #tbd - adds a new `Invite` model with associated serializer and test setup - updates team screen to use invites rather than existing users with the "invited" property - updates signup process to work with new invite model
- Loading branch information
1 parent
bb63ee3
commit feee8a2
Showing
13 changed files
with
326 additions
and
77 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
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
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,52 @@ | ||
import Mirage from 'ember-cli-mirage'; | ||
import {paginatedResponse} from '../utils'; | ||
|
||
export default function mockInvites(server) { | ||
server.get('/invites/', function (db, request) { | ||
let response = paginatedResponse('invites', db.invites, request); | ||
return response; | ||
}); | ||
|
||
server.get('/invites/:id', function (db, request) { | ||
let {id} = request.params; | ||
let invite = db.invites.find(id); | ||
|
||
if (!invite) { | ||
return new Mirage.Response(404, {}, { | ||
errors: [{ | ||
errorType: 'NotFoundError', | ||
message: 'Invite not found.' | ||
}] | ||
}); | ||
} else { | ||
return {invites: [invite]}; | ||
} | ||
}); | ||
|
||
server.post('/invites/', function (db, request) { | ||
let [attrs] = JSON.parse(request.requestBody).invites; | ||
let invite; | ||
|
||
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */ | ||
attrs.token = `${db.invites.length}-token`; | ||
attrs.expires = moment.utc().add(1, 'day').unix(); | ||
attrs.created_at = moment.utc().format(); | ||
attrs.created_by = 1; | ||
attrs.updated_at = moment.utc().format(); | ||
attrs.updated_by = 1; | ||
attrs.status = 'sent'; | ||
/* jscs:enable requireCamelCaseOrUpperCaseIdentifiers */ | ||
|
||
invite = db.invites.insert(attrs); | ||
|
||
return { | ||
invite | ||
}; | ||
}); | ||
|
||
server.del('/invites/:id/', function (db, request) { | ||
db.invites.remove(request.params.id); | ||
|
||
return new Mirage.Response(204, {}, {}); | ||
}); | ||
} |
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,14 @@ | ||
/* jscs:disable */ | ||
import Mirage from 'ember-cli-mirage'; | ||
|
||
export default Mirage.Factory.extend({ | ||
token(i) { return `${i}-token`; }, | ||
email(i) { return `invited-user-${i}@example.com`; }, | ||
expires() { return moment.utc().add(1, 'day').unix(); }, | ||
created_at() { return moment.utc().format(); }, | ||
created_by() { return 1; }, | ||
updated_at() { return moment.utc().format(); }, | ||
updated_by() { return 1; }, | ||
status() { return 'sent'; }, | ||
roles() { return []; } | ||
}); |
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,55 @@ | ||
import Model from 'ember-data/model'; | ||
import attr from 'ember-data/attr'; | ||
import {hasMany} from 'ember-data/relationships'; | ||
import computed from 'ember-computed'; | ||
import injectService from 'ember-service/inject'; | ||
|
||
export default Model.extend({ | ||
token: attr('string'), | ||
email: attr('string'), | ||
expires: attr('number'), | ||
createdAtUTC: attr('moment-utc'), | ||
createdBy: attr('number'), | ||
updatedAtUTC: attr('moment-utc'), | ||
updatedBy: attr('number'), | ||
status: attr('string'), | ||
roles: hasMany('role', { | ||
embedded: 'always', | ||
async: false | ||
}), | ||
|
||
// TODO: remove once `gh-user-invited` is updated to work with invite | ||
// models instead of the current hacks which make invites look like | ||
// users | ||
invited: true, | ||
|
||
ajax: injectService(), | ||
ghostPaths: injectService(), | ||
|
||
role: computed('roles', { | ||
get() { | ||
return this.get('roles.firstObject'); | ||
}, | ||
set(key, value) { | ||
// Only one role per user, so remove any old data. | ||
this.get('roles').clear(); | ||
this.get('roles').pushObject(value); | ||
|
||
return value; | ||
} | ||
}), | ||
|
||
resendInvite() { | ||
let fullInviteData = this.toJSON(); | ||
let inviteData = { | ||
email: fullInviteData.email, | ||
roles: fullInviteData.roles | ||
}; | ||
let inviteUrl = this.get('ghostPaths.url').api('invites'); | ||
|
||
return this.get('ajax').post(inviteUrl, { | ||
data: JSON.stringify({invites: [inviteData]}), | ||
contentType: 'application/json' | ||
}); | ||
} | ||
}); |
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
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 @@ | ||
import ApplicationSerializer from 'ghost-admin/serializers/application'; | ||
import EmbeddedRecordsMixin from 'ember-data/serializers/embedded-records-mixin'; | ||
|
||
export default ApplicationSerializer.extend(EmbeddedRecordsMixin, { | ||
attrs: { | ||
roles: {embedded: 'always'}, | ||
createdAtUTC: {key: 'created_at'}, | ||
updatedAtUTC: {key: 'updated_at'} | ||
} | ||
}); |
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
Oops, something went wrong.