<commit_before>(function() {
  'use strict';
  angular.module('civic.services')
    .factory('CurrentUserResource', CurrentUserResource)
    .factory('CurrentUser', CurrentUserService);

  // @ngInject
  function CurrentUserResource($resource) {
    //var cache = $cacheFactory.get('$http');

    //var cacheInterceptor = function(response) {
    //  console.log(['EvidenceResource: removing', response.config.url, 'from $http cache.'].join(' '));
    //  cache.remove(response.config.url);
    //  return response.$promise;
    //};


    return $resource('/api/current_user',
      {},
      {
        get: {
          method: 'GET',
          isArray: false,
          cache: false
        },
        getStats: {
          ur1l:'/api/current_user/stats',
          isArray: false,
          cache: false
        },<commit_msg>created userOrgsInterceptor to handle most_recent_org logic<commit_after>(function() {
  'use strict';
  angular.module('civic.services')
    .factory('CurrentUserResource', CurrentUserResource)
    .factory('CurrentUser', CurrentUserService);

  // @ngInject
  function CurrentUserResource($resource, _) {

    var userOrgsInterceptor = function(response) {
      var user = response.data;
      if(_.isNull(user.most_recent_organization)) { // most_recent_org not defined
        if(!_.isEmpty(user.organizations)) { // is a member of at least one org
          // assign u.orgs[0] to most_recent_org
          user.most_recent_organization = user.organizations[0];
        } else { /* no orgs, most_recent remains null */ }
      } else { // most_recent_org is defined, ensure it's also present in user.orgs array
        var orgId = user.most_recent_organization.id;
        if (!_.some(user.organizations, { id: orgId })) { // user is not currently member of most_recent_org
          if(!_.isEmpty(user.organizations)) { // user is a member of at least one org
            user.most_recent_organization = user.organizations[0];
          } else { // user is not a member of their most_recent_org, assign null
            user.most_recent_organization = null;
          }
        }
      }
      return user;
    };

    return $resource('/api/current_user',
      {},
      {
        get: {
          method: 'GET',
          isArray: false,
          cache: false,
          interceptor: {
            response: userOrgsInterceptor
          }
        },
        getStats: {
          ur1l:'/api/current_user/stats',
          isArray: false,
          cache: false
        },
{'fraction_non_alphanumeric': 0.12261146496815287, 'fraction_numerical': 0.0019904458598726115, 'mean_word_length': 2.293577981651376, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '2131495', 'n_tokens_mistral': 733, 'n_tokens_neox': 708, 'n_words': 158}