<commit_before>/**
 * Created by Rory on 11/18/2015.
 */
Meteor.methods({
  changeEmail: function(email) {
    if (Accounts.findUserByEmail(email) === Meteor.user() || !Accounts.findUserByEmail(email)) {
      _.each(Meteor.user().emails, function(targetaddress){
          Accounts.removeEmail(Meteor.userId(), targetaddress.address)
      })
    }
    Accounts.addEmail(Meteor.userId(), email);
  },
  removeRole: function(username, role) {
    if(Roles.userIsInRole(Meteor.user(), "role-manager")) {
      var target = Meteor.users.findOne({username:username});
      Roles.removeUsersFromRoles(target, role);
    }
  },
  addRole: function(username, role) {
    if(Roles.userIsInRole(Meteor.user(), "role-manager")) {
      var target = Meteor.users.findOne({username:username});
      Roles.addUsersToRoles(target, role);
    }
  }
});

/**
 * Code modified from user saimeunt's code on stackoverflow from http://stackoverflow.com/a/26086406/5616465
 */
Meteor.publish("userProfile", function(username){
  // try to find the user by username
  var user = Meteor.users.findOne({
    username:username
  });
  // if we can't find it, quit
  if(!user){
    return;
  }
  // if the user we want to display the profile is the currently logged in user...
  if(this.userId==user._id){
    // then we return the corresponding full document via a cursor
    return Meteor.users.find(this.userId);
  }
  else{
    // if we are viewing only the public part, strip the "profile"
    // property from the fetched document, you might want to
    // set only a nested property of the profile as private
    // instead of the whole property
    if (user.profile.shareEmail === true) {
      return Meteor.users.find(user._id,{
        fields:{
          "username":1,
          "emails":1,
          "profile":1
        }
      });
    }
    else {
      return Meteor.users.find(user._id,{
        fields:{
          "username":1,
          "profile":1
        }
      });
    }
  }
});

Meteor.publish("userList", function(){
  var userlist = Meteor.users.find({
    fields: {
      username: 1,
      profile: {
        firstName: 1,
        lastName: 1,
        profileImage: 1
      }
    }
  });

  return userlist;
});<commit_msg>Fixed user list publish function.<commit_after>/**
 * Created by Rory on 11/18/2015.
 */
Meteor.methods({
  changeEmail: function(email) {
    if (Accounts.findUserByEmail(email) === Meteor.user() || !Accounts.findUserByEmail(email)) {
      _.each(Meteor.user().emails, function(targetaddress){
          Accounts.removeEmail(Meteor.userId(), targetaddress.address)
      })
    }
    Accounts.addEmail(Meteor.userId(), email);
  },
  removeRole: function(username, role) {
    if(Roles.userIsInRole(Meteor.user(), "role-manager")) {
      var target = Meteor.users.findOne({username:username});
      Roles.removeUsersFromRoles(target, role);
    }
  },
  addRole: function(username, role) {
    if(Roles.userIsInRole(Meteor.user(), "role-manager")) {
      var target = Meteor.users.findOne({username:username});
      Roles.addUsersToRoles(target, role);
    }
  }
});

/**
 * Code modified from user saimeunt's code on stackoverflow from http://stackoverflow.com/a/26086406/5616465
 */
Meteor.publish("userProfile", function(username){
  // try to find the user by username
  var user = Meteor.users.findOne({
    username:username
  });
  // if we can't find it, quit
  if(!user){
    return;
  }
  // if the user we want to display the profile is the currently logged in user...
  if(this.userId==user._id){
    // then we return the corresponding full document via a cursor
    return Meteor.users.find(this.userId);
  }
  else{
    // if we are viewing only the public part, strip the "profile"
    // property from the fetched document, you might want to
    // set only a nested property of the profile as private
    // instead of the whole property
    if (user.profile.shareEmail === true) {
      return Meteor.users.find(user._id,{
        fields:{
          "username":1,
          "emails":1,
          "profile":1
        }
      });
    }
    else {
      return Meteor.users.find(user._id,{
        fields:{
          "username":1,
          "profile":1
        }
      });
    }
  }
});

Meteor.publish("userList", function(){
  return Meteor.users.find({ }, {
    fields: {
      "username": 1,
      "profile.firstName": 1,
      "profile.lastName": 1,
      "profile.profileImage": 1
    }
  });
});
{'fraction_non_alphanumeric': 0.1402247191011236, 'fraction_numerical': 0.014382022471910113, 'mean_word_length': 2.6513535684987697, 'pattern_counts': {'":': 14, '<': 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': '794422', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1389, 'n_words': 332}