feat: Basic sessions view
This commit is contained in:
11 files changed
+190
-2
No files matched your search
@@ -10,7 +10,10 @@ export default factory.extend({
|
||||
withAccountsAndUsers: trait({
|
||||
afterCreate(authMethod, server) {
|
||||
const { scope } = authMethod;
|
||||
server.createList('user', 5, { scope }).map(user => {
|
||||
const users = server.createList('user', 5, { scope });
|
||||
// Create authorized user: user123
|
||||
users.push(server.create('user', { scope, id: 'user123' }));
|
||||
users.map(user => {
|
||||
const { id } = server.create('account', { scope, authMethod });
|
||||
user.update({ accountIds: [id] });
|
||||
});
|
||||
|
||||
@@ -41,6 +41,29 @@ export default factory.extend({
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
/**
|
||||
* Sessions generated with this trait will automatically form
|
||||
* associations to target, host set, and host (if available) within
|
||||
* the current scope and for specified user.
|
||||
*/
|
||||
withUserAssociations: trait({
|
||||
afterCreate(record, server) {
|
||||
const scopeId = record.scopeId;
|
||||
const user = record.user;
|
||||
record.update({ user });
|
||||
const target = server.schema.targets.where({ scopeId }).models[0];
|
||||
if (target) {
|
||||
record.update({ target });
|
||||
const hostSet = target.hostSets.models[0];
|
||||
if (hostSet) {
|
||||
record.update({ hostSet });
|
||||
const host = hostSet.hosts.models[0];
|
||||
if (host) record.update({ host });
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
@@ -29,6 +29,9 @@ export default function(server) {
|
||||
server.createList('host-catalog', 2, { scope }, 'withChildren');
|
||||
server.createList('target', 2, { scope }, 'withRandomHostSets');
|
||||
server.createList('session', 4, { scope }, 'withAssociations');
|
||||
// Create sessions for all users
|
||||
server.schema.users.where({ scopeId: scope.scope.id }).models.forEach(user =>
|
||||
server.createList('session', 4, { scope, user }, 'withUserAssociations')
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user