<commit_before>import Ember from 'ember';

/**
 * @module ember-osf
 * @submodule services
 */

/**
 * Access information about the currently logged in user
 * Proxies all undefined properties to the the user returned by /users/me/
 * @class current-user
 * @extends Ember.Service
 */
export default Ember.Service.extend(Ember.ObjectProxy.PrototypeMixin, Ember.PromiseProxyMixin, {
    store: Ember.inject.service(),
    session: Ember.inject.service(),

    init() {
        // Trigger initial KVO cycle
        // Because Services don't automatically... because why would they :|
        this.set('promise', this.get('promise'));

        this._super(...arguments);
    },

    // The promise for PromiseProxyMixin
    promise: Ember.computed('session.data.authenticated', {
        get() {
            let userId = this.get('currentUserId');
            if (!userId) return Ember.RSVP.resolve(null);

            let user = this.get('store').peekRecord('user', userId);
            if (user) return Ember.RSVP.resolve(user);

            return this.get('store').findRecord('user', userId);
        },
        set(key, value) {
            // HACK: We need to use the original setter, which is in a closure (go figure), to make the PromiseProxyMixin work
            return Ember.PromiseProxyMixin.mixins[0].properties.promise._setter.apply(this, [key, value]);
        }
    }),


    /**
     * If logged in, return the ID of the current user, else return null.
     *
     * @property currentUserId
     * @type {String|null}
     */
    currentUserId: Ember.computed('session.data.authenticated', function() {
        var session = this.get('session');
        if (session.get('isAuthenticated')) {
            return session.get('data.authenticated.id');
        } else {
            return null;
        }
    }),

    /**
     * Fetch information about the currently logged in user. If no user is logged in, this method returns a rejected promise.
     * @method load
     * @return {Promise}
     */
    load() {
        return this.get('promise');
    }
});
<commit_msg>Add `user` property to current-user instead<commit_after>import Ember from 'ember';

/**
 * @module ember-osf
 * @submodule services
 */

/**
 * Access information about the currently logged in user
 *
 * @class current-user
 * @extends Ember.Service
 */
export default Ember.Service.extend({
    store: Ember.inject.service(),
    session: Ember.inject.service(),

    /**
     * If logged in, return the ID of the current user, else return null.
     *
     * @property currentUserId
     * @type {String|null}
     */
    currentUserId: Ember.computed('session.data.authenticated', function() {
        var session = this.get('session');
        if (session.get('isAuthenticated')) {
            return session.get('data.authenticated.id');
        } else {
            return null;
        }
    }),

    /**
     * Fetch information about the currently logged in user. If no user is logged in, this method returns a rejected promise.
     * @method load
     * @return {Promise}
     */
    load() {
        return new Ember.RSVP.Promise((resolve, reject) => {
            var currentUserId = this.get('currentUserId');
            if (currentUserId) {
                var currentUser = this.get('store').peekRecord('user', currentUserId);
                if (currentUser) {
                    resolve(currentUser);
                } else {
                    this.get('store').findRecord('user', currentUserId).then((user) => resolve(user), reject);
                }
            } else {
                reject();
            }
        });
    },

    /**
     * Return an observable promise proxy for the currently logged in user. If no user is logged in, resolves to null.
     *
     * @property user
     * @return Promise proxy object that resolves to a user or null
     */
    user: Ember.computed('currentUserId', function() {
        const ObjectPromiseProxy = Ember.ObjectProxy.extend(Ember.PromiseProxyMixin);
        return ObjectPromiseProxy.create({
            promise: this.load().catch(() => null),
        });
    }),
});

{'fraction_non_alphanumeric': 0.12539336722343258, 'fraction_numerical': 0.0002420721374969741, 'mean_word_length': 2.256107171000788, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '1981485', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1135, 'n_words': 317}