Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
> v0.2.1 ~ "Inspection display dates"

> v0.2.2 ~ "Managed login state"

---
## Highlights

- **Inspection display dates are formatted** — `inspection-form` and `inspection-submission` format their display-date getters as `yyyy-MM-dd HH:mm` and answer `null` for a date they cannot read, the way every other model in this package does. The console's inspection indexes were showing a raw datetime instance string.
- **`frequency` is gone from `inspection-form`** — nothing scheduled an inspection from it, and it is being dropped from the FleetOps API resource, report schema and console in fleetbase/fleetops#319.

The underscored attributes (`created_at`, `published_at`, …) are untouched, so anything needing a real `Date` is unaffected.
- **Driver and contact models expose their login state.** New read-only `is_staff_linked` and `login_status` attributes let the console show Reset Password, Send Credentials and Deactivate/Reactivate Login. They also lock email and phone on a profile linked to a team member's account.
- **The login account is never sent back.** Driver and contact login accounts are now managed by the server from the profile's name, email and phone (fleetbase/fleetops#338). The driver serializer no longer sends `user_uuid` or the login fields. The contact serializer no longer sends `user`, `user_uuid` or the login fields.

---
## Need help?
Expand Down
4 changes: 4 additions & 0 deletions addon/models/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export default class ContactModel extends Model {
photo_url;
@attr('string') slug;

/** @managed-login (read-only, maintained by the server) */
@attr('boolean') is_staff_linked;
@attr('string') login_status;

/** @dates */
@attr('date') deleted_at;
@attr('date') created_at;
Expand Down
4 changes: 4 additions & 0 deletions addon/models/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export default class DriverModel extends Model {
@attr('string') city;
@attr('string', { defaultValue: 'available' }) status;
@attr('boolean') online;

/** @managed-login (read-only, maintained by the server) */
@attr('boolean') is_staff_linked;
@attr('string') login_status;
@attr('raw') meta;

/** @dates */
Expand Down
23 changes: 22 additions & 1 deletion addon/serializers/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,32 @@ export default class ContactSerializer extends ApplicationSerializer.extend(Embe
*/
get attrs() {
return {
user: { embedded: 'always' },
// The login account is managed by the server from name/email/phone
user: { embedded: 'always', serialize: false },
user_uuid: { serialize: false },
is_staff_linked: { serialize: false },
login_status: { serialize: false },
place: { embedded: 'always' },
places: { embedded: 'always' },
photo: { embedded: 'always' },
custom_field_values: { embedded: 'always' },
};
}

/**
* The login account is resolved by the server from the contact's name,
* email and phone, so the account reference is never sent back.
*
* @param {Snapshot} snapshot
* @param {Object} options
* @return {Object} json
*/
serialize() {
const json = super.serialize(...arguments);

delete json.user;
delete json.user_uuid;

return json;
}
}
4 changes: 4 additions & 0 deletions addon/serializers/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export default class DriverSerializer extends ApplicationSerializer.extend(Embed
current_job: { embedded: 'always' },
jobs: { embedded: 'always' },
custom_field_values: { embedded: 'always' },
// The login account is managed by the server from name/email/phone
user_uuid: { serialize: false },
is_staff_linked: { serialize: false },
login_status: { serialize: false },
};
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleetbase/fleetops-data",
"version": "0.2.1",
"version": "0.2.2",
"description": "Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.",
"keywords": [
"fleetbase-data",
Expand Down
14 changes: 13 additions & 1 deletion tests/unit/serializers/contact-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ module('Unit | Serializer | contact', function (hooks) {

test('it declares exactly the expected relationship serialization contract', function (assert) {
assertEmbeddedAttrs(assert, this.store, 'contact', {
user: { embedded: 'always' },
user: { embedded: 'always', serialize: false },
user_uuid: { serialize: false },
is_staff_linked: { serialize: false },
login_status: { serialize: false },
place: { embedded: 'always' },
places: { embedded: 'always' },
photo: { embedded: 'always' },
Expand All @@ -40,6 +43,15 @@ module('Unit | Serializer | contact', function (hooks) {
assert.strictEqual(record.serialize().name, 'contract-value');
});

test('the server-managed login fields never travel back to the server', function (assert) {
const record = this.store.createRecord('contact', { name: 'contract-value', is_staff_linked: true, login_status: 'active' });
const json = record.serialize();

assert.false('is_staff_linked' in json);
assert.false('login_status' in json);
assert.false('user' in json);
});

test('the place relationship travels inline with the record', function (assert) {
const record = this.store.createRecord('contact');
record.set('place', this.store.createRecord('place', { name: 'related-value' }));
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/serializers/customer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ module('Unit | Serializer | customer', function (hooks) {

test('it declares exactly the expected relationship serialization contract', function (assert) {
assertEmbeddedAttrs(assert, this.store, 'customer', {
user: { embedded: 'always' },
user: { embedded: 'always', serialize: false },
user_uuid: { serialize: false },
is_staff_linked: { serialize: false },
login_status: { serialize: false },
place: { embedded: 'always' },
places: { embedded: 'always' },
photo: { embedded: 'always' },
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/serializers/driver-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,20 @@ module('Unit | Serializer | driver', function (hooks) {
current_job: EMBEDDED,
jobs: EMBEDDED,
custom_field_values: EMBEDDED,
user_uuid: { serialize: false },
is_staff_linked: { serialize: false },
login_status: { serialize: false },
});
});

test('the server-managed login fields never travel back to the server', function (assert) {
const driver = this.store.createRecord('driver', { name: 'Ada Lovelace', is_staff_linked: true, login_status: 'active' });
const json = driver.serialize();

assert.false('is_staff_linked' in json);
assert.false('login_status' in json);
});

test('a server payload is normalized onto a record keyed by uuid', function (assert) {
const driver = assertNormalizesUuidAsId(assert, this.store, 'driver', { name: 'Ada Lovelace', status: 'available' });

Expand Down
Loading