Skip to content

Commit

Permalink
Fix session service to use user
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasolson committed Feb 9, 2021
1 parent f3abb42 commit bc82023
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class SearchSessionService
if (SavedObjectsErrorHelpers.isNotFoundError(e)) {
try {
this.logger.debug(`Object not found | ${sessionId}`);
return await this.create(deps, sessionId, attributes);
return await this.create(deps, user, sessionId, attributes);
} catch (createError) {
if (
SavedObjectsErrorHelpers.isConflictError(createError) &&
Expand Down Expand Up @@ -150,29 +150,28 @@ export class SearchSessionService
if (!appId) throw new Error('AppId is required');
if (!urlGeneratorId) throw new Error('UrlGeneratorId is required');

const realmType = user?.authentication_realm.type;
const realmName = user?.authentication_realm.name;
const username = user?.username;

return this.updateOrCreate(deps, user, sessionId, {
name,
appId,
urlGeneratorId,
initialState,
restoreState,
persisted: true,
realmType,
realmName,
username,
});
};

private create = (
{ savedObjectsClient }: SearchSessionDependencies,
user: AuthenticatedUser | null,
sessionId: string,
attributes: Partial<SearchSessionSavedObjectAttributes>
) => {
this.logger.debug(`create | ${sessionId}`);

const realmType = user?.authentication_realm.type;
const realmName = user?.authentication_realm.name;
const username = user?.username;

return savedObjectsClient.create<SearchSessionSavedObjectAttributes>(
SEARCH_SESSION_TYPE,
{
Expand All @@ -185,6 +184,9 @@ export class SearchSessionService
touched: new Date().toISOString(),
idMapping: {},
persisted: false,
realmType,
realmName,
username,
...attributes,
},
{ id: sessionId }
Expand Down

0 comments on commit bc82023

Please sign in to comment.