<commit_before>import Ember from 'ember';
import ApplicationRouteMixin
  from 'ember-simple-auth/mixins/application-route-mixin';

// TODO: DSS-6581 Create URL retrieval module
const appConfigUrl = '/config';

const {
  Route,
  run,
  get,
  $: { getJSON },
  inject: { service },
  testing
} = Ember;

export default Route.extend(ApplicationRouteMixin, {
  // Injected Ember#Service for the current user
  sessionUser: service('current-user'),

  /**
   * Metrics tracking service
   * @type {Ember.Service}
   */
  metrics: service(),

  /**
   * Attempt to load the current user
   * @returns {Promise}
   */
  beforeModel() {
    this._super(...arguments);

    return this._loadCurrentUser();
  },

  /**
   * Perform post model operations
   * @return {Promise}
   */
  afterModel() {
    this._super(...arguments);

    return this._setupMetricsTrackers();
  },

  /**
   * Augments sessionAuthenticated.
   * @override ApplicationRouteMixin.sessionAuthenticated
   */
  sessionAuthenticated() {
    this._super(...arguments);
    this._loadCurrentUser();
  },

  /**
   * __It reloads the Ember.js application__ by redirecting the browser
   * to the application's root URL so that all in-memory data (such as Ember
   * Data stores etc.) gets cleared.
   * @override ApplicationRouteMixin.sessionInvalidated
   * @link https://github.com/simplabs/ember-simple-auth/issues/1048
   */
  sessionInvalidated() {
    if (!testing) {
      window.location.replace('/');
    }
  },

  /**
   * Internal method to invoke the currentUser service's load method
   *   If an exception occurs during the load for the current user,
   *   invalidate the session.
   * @returns {Promise<T, V>|RSVP.Promise<any>|Ember.RSVP.Promise<any, any>|Promise.<T>}
   * @private
   */
  _loadCurrentUser() {
    return get(this, 'sessionUser')
      .load()
      .catch(() => get(this, 'session').invalidate());
  },

  /**
   * Requests app configuration props then if enabled, sets up metrics
   *   tracking using the supported trackers
   * @return {Promise.<TResult>}
   * @private
   */
  _setupMetricsTrackers() {
    // TODO: DSS-6813 Make this request for appConfig a singleton object
    return Promise.resolve(getJSON(appConfigUrl))
      .then(({ status, config = {} }) => {
        const { tracking = {} } = config;

        if (status === 'ok' && tracking.isEnabled) {
          const metrics = get(this, 'metrics');
          const { trackers = {} } = tracking;
          const {
            piwikSiteId,
            piwikUrl = '//piwik.corp.linkedin.com/piwik/'
          } = trackers.piwik;

          metrics.activateAdapters([{
            name: 'Piwik',
            environments: ['all'],
            config: {
              piwikUrl,
              siteId: piwikSiteId
            }
          }]);
        }
      });
  },

  init() {
    this._super(...arguments);
    run.scheduleOnce('afterRender', this, 'processLegacyDomOperations');
  },

  processLegacyDomOperations() {
    // TODO: DSS-6122 Refactor Remove tree legacy operations & references
    // window.legacySearch();
    // window.legacyTree();
    window.legacyMain();
  }
});<commit_msg>reinstates userId tracking, search tracking using the non default trackSiteSearch api<commit_after>import Ember from 'ember';
import ApplicationRouteMixin
  from 'ember-simple-auth/mixins/application-route-mixin';

// TODO: DSS-6581 Create URL retrieval module
const appConfigUrl = '/config';

const {
  Route,
  run,
  get,
  $: { getJSON },
  inject: { service },
  testing
} = Ember;

export default Route.extend(ApplicationRouteMixin, {
  // Injected Ember#Service for the current user
  sessionUser: service('current-user'),

  /**
   * Metrics tracking service
   * @type {Ember.Service}
   */
  metrics: service(),

  /**
   * Attempt to load the current user
   * @returns {Promise}
   */
  beforeModel() {
    this._super(...arguments);

    return this._loadCurrentUser();
  },

  /**
   * Perform post model operations
   * @return {Promise}
   */
  afterModel() {
    this._super(...arguments);

    return this._setupMetricsTrackers();
  },

  /**
   * Augments sessionAuthenticated.
   * @override ApplicationRouteMixin.sessionAuthenticated
   */
  sessionAuthenticated() {
    this._super(...arguments);
    this._loadCurrentUser();
  },

  /**
   * __It reloads the Ember.js application__ by redirecting the browser
   * to the application's root URL so that all in-memory data (such as Ember
   * Data stores etc.) gets cleared.
   * @override ApplicationRouteMixin.sessionInvalidated
   * @link https://github.com/simplabs/ember-simple-auth/issues/1048
   */
  sessionInvalidated() {
    if (!testing) {
      window.location.replace('/');
    }
  },

  /**
   * Internal method to invoke the currentUser service's load method
   *   If an exception occurs during the load for the current user,
   *   invalidate the session.
   * @returns {Promise<T, V>|RSVP.Promise<any>|Ember.RSVP.Promise<any, any>|Promise.<T>}
   * @private
   */
  _loadCurrentUser() {
    return get(this, 'sessionUser')
      .load()
      .catch(() => get(this, 'session').invalidate());
  },

  /**
   * Requests app configuration props then if enabled, sets up metrics
   *   tracking using the supported trackers
   * @return {Promise.<TResult>}
   * @private
   */
  _setupMetricsTrackers() {
    // TODO: DSS-6813 Make this request for appConfig a singleton object
    return Promise.resolve(getJSON(appConfigUrl))
      .then(({ status, config = {} }) => {
        const { tracking = {} } = config;
        const userId = get(this, 'sessionUser.userName') ||
          get(this, 'sessionUser.currentUser.userName');

        if (status === 'ok' && tracking.isEnabled) {
          const metrics = get(this, 'metrics');
          const { trackers = {} } = tracking;
          const {
            piwikSiteId,
            piwikUrl = '//piwik.corp.linkedin.com/piwik/'
          } = trackers.piwik;

          metrics.activateAdapters([{
            name: 'Piwik',
            environments: ['all'],
            config: {
              piwikUrl,
              siteId: piwikSiteId
            }
          }]);

          // Track currently logged in user
          metrics.identify({ userId });
        }
      });
  },

  init() {
    this._super(...arguments);
    run.scheduleOnce('afterRender', this, 'processLegacyDomOperations');
  },

  processLegacyDomOperations() {
    // TODO: DSS-6122 Refactor Remove tree legacy operations & references
    // window.legacySearch();
    // window.legacyTree();
    window.legacyMain();
  }
});
{'fraction_non_alphanumeric': 0.13349514563106796, 'fraction_numerical': 0.0048543689320388345, 'mean_word_length': 2.5890038105606967, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7306864', 'n_tokens_mistral': 1999, 'n_tokens_neox': 1936, 'n_words': 469}