- .then(resp => ({
- email: resp.data.email,
- firstName: resp.data.first_name,
- lastName: resp.data.last_name,
- uuid: resp.data.uuid,
- ownerUuid: resp.data.owner_uuid
- }));
- }
-
- public getRootUuid() {
- const uuid = this.getOwnerUuid();
- const uuidParts = uuid ? uuid.split('-') : [];
- return uuidParts.length > 1 ? `${uuidParts[0]}-${uuidParts[1]}` : undefined;
+ .then(resp => {
+ this.actions.progressFn(reqId, false);
+ const prefs = resp.data.prefs.profile ? resp.data.prefs : { profile: {} };
+ return {
+ email: resp.data.email,
+ firstName: resp.data.first_name,
+ lastName: resp.data.last_name,
+ uuid: resp.data.uuid,
+ ownerUuid: resp.data.owner_uuid,
+ isAdmin: resp.data.is_admin,
+ isActive: resp.data.is_active,
+ username: resp.data.username,
+ prefs
+ };
+ })
+ .catch(e => {
+ this.actions.progressFn(reqId, false);
+ this.actions.errorFn(reqId, e, showErrors);
+ throw e;
+ });
+ }
+
+ public getSessions(): Session[] {
+ try {
+ const sessions = JSON.parse(this.getStorage().getItem("sessions") || '');
+ return sessions;
+ } catch {
+ return [];
+ }
+ }
+
+ public saveSessions(sessions: Session[]) {
+ this.getStorage().setItem("sessions", JSON.stringify(sessions));
+ }
+
+ public removeSessions() {
+ this.getStorage().removeItem("sessions");
+ }
+
+ public buildSessions(cfg: Config, user?: User) {
+ const currentSession = {
+ clusterId: cfg.uuidPrefix,
+ remoteHost: cfg.rootUrl,
+ baseUrl: cfg.baseUrl,
+ name: user ? getUserDisplayName(user) : '',
+ email: user ? user.email : '',
+ userIsActive: user ? user.isActive : false,
+ token: this.getApiToken(),
+ loggedIn: true,
+ active: true,
+ uuid: user ? user.uuid : '',
+ status: SessionStatus.VALIDATED,
+ apiRevision: cfg.apiRevision,
+ } as Session;
+ const localSessions = this.getSessions().map(s => ({
+ ...s,
+ active: false,
+ status: SessionStatus.INVALIDATED
+ }));
+
+ const cfgSessions = Object.keys(cfg.remoteHosts).map(clusterId => {
+ const remoteHost = cfg.remoteHosts[clusterId];
+ return {
+ clusterId,
+ remoteHost,
+ baseUrl: '',
+ name: '',
+ email: '',
+ token: '',
+ loggedIn: false,
+ active: false,
+ uuid: '',
+ status: SessionStatus.INVALIDATED,
+ apiRevision: 0,
+ } as Session;
+ });
+ const sessions = [currentSession]
+ .concat(cfgSessions)
+ .concat(localSessions)
+ .filter((r: Session) => r.clusterId !== "*");
+
+ const uniqSessions = uniqBy(sessions, 'clusterId');
+
+ return uniqSessions;