UserCollection

api/user. UserCollection

Represents a user, which is someone who has a Meteor account.

Users are defined when the various Profile collections are initialized, so the User collection is the union
of Students, Faculty, Advisors, and Mentors, plus the single Admin account who also has a Meteor account.

Note that this collection does not extend any of our Base collections, because it has a very limited API
which should be used by clients to access the various Profile collections.

It is not saved out or restored when the DB is dumped. It is not listed in RadGrad.collections.

Clients provide a "user" as a parameter, which is either the username (i.e. email) or userID.

Constructor

new UserCollection()

Source:

Methods

assertInRole(user, role)

Source:

Asserts that the passed user has the specified role.

Parameters:
Name Type Description
user

The user (username or userID).

role

The role or an array of roles.

Throws:

If the user does not have the role, or if user or role is not valid.

Type
Meteor.Error

define(username, role) → {String}

Source:

Define a new user, which means creating an entry in Meteor.Accounts.
This is called in the various Profile define() methods.

Parameters:
Name Type Description
username

The username to be defined (must be an email address).

role

The role.

Throws:

If the user exists.

Type
Meteor.Error
Returns:

The docID of the newly created user.

Type
String

filterProfiles(filter) → {Array}

Source:

Iterates through all Profile collections, and returns an array of profiles that satisfy filter.

Parameters:
Name Type Description
filter

A function that accepts a profile a document and returns truthy if that document should be included
in the returned array.

Returns:

An array of profile documents from across all the Profile collections satisfying filter.

Type
Array

findProfiles(selector, options) → {Array}

Source:
See:

Runs find on all the Profile collections, fetches the associated documents, and returns an array containing all
of the matches.

Parameters:
Name Type Description
selector Object

A MongoDB selector.

options Object

MongoDB options.

Returns:

An array of documents matching the selector and options.

Type
Array

findProfilesWithRole(selector, options) → {Array}

Source:
See:

Runs find on all the Profile collections, fetches the associated documents, and returns an array containing all
of the matches.

Parameters:
Name Type Description
selector Object

A MongoDB selector.

options Object

MongoDB options.

Returns:

An array of documents matching the selector and options.

Type
Array

getFullName(user) → {string}

Source:

Returns the full name for the given user.

Parameters:
Name Type Description
user

the user (username or ID).

Throws:

If user is not a valid user.

Type
Meteor.Error
Returns:

The user's full name.

Type
string

getID(user) → {String}

Source:

Returns the userID associated with user, or throws an error if not defined.

Parameters:
Name Type Description
user

The user (username or userID).

Throws:

If user is not a defined username or userID.

Type
Meteor.Error
Returns:

The userID

Type
String

getIDs(users) → {Array.<String>}

Source:

Returns the userIDs associated with users, or throws an error if any cannot be found.

Parameters:
Name Type Description
users Array.<String>

An array of valid users.

Throws:

If any instance is not a user.

Type
Meteor.Error
Returns:

The docIDs associated with users.

Type
Array.<String>

getInterestIDs(user) → {Array}

Source:

Returns the user's interests as IDs. It is a union of interestIDs and careerGoal interestIDs.

Parameters:
Name Type Description
user

The username or userID.

Returns:

An array of interestIDs.

Type
Array

getInterestIDsByType(user) → {Array}

Source:

Returns the user's interest IDs in an Array with two sub-arrays. The first sub-array is the interest IDs that the
User selected. The second sub-array is the interestIDs from the user's career goals that are not already present
in the first subarray.

Parameters:
Name Type Description
user

The username or userID.

Returns:

An array with two subarrays, each containing interestIDs.

Type
Array

getProfile(user) → {Object}

Source:

Returns the profile document associated with user.

Parameters:
Name Type Description
user

The username or userID.

Throws:

If the document was not found.

Type
Meteor.Error
Returns:

The profile document.

Type
Object

getPublicationName() → {String}

Source:

Return the publication name.

Returns:

The publication name, as a string.

Type
String

hasProfile(user) → {Object|Null}

Source:

Returns the profile document associated with user, or null if not found.

Parameters:
Name Type Description
user

The username or userID.

Returns:

The profile document or null if not found.

Type
Object | Null

isDefined(user) → {boolean}

Source:

Returns true if user is a defined userID or username.

Parameters:
Name Type Description
user

The user.

Returns:

True if user is defined, false otherwise.

Type
boolean

isReferenced(user) → {boolean}

Source:

Returns true if user is referenced by other "public" entities. Specifically:

  • The user is a student and has published a review.
  • The user is a mentor and has published an answer.
  • The user is a student and has published a question.
  • The user is a faculty member as has sponsored an opportunity.
    Used to determine if this user can be deleted.
    Note this doesn't test for references to CourseInstances, etc. These are "private" and will be deleted
    implicitly if this user is deleted.
Parameters:
Name Type Description
user

The username or userID.

Throws:

If the username is not defined.

Type
Meteor.Error
Returns:

True if this user is referenced "publicly" elsewhere.

Type
boolean

publish()

Source:

Publish the username field for all users.

removeAll()

Source:

Removes all users except for the admin user.
This is implemented by mapping through all elements because mini-mongo does not implement the remove operation.
So this approach can be used on both client and server side.
removeAll should only used for testing purposes, so it doesn't need to be efficient.

removeIt()

Source:

DO NOT USE.

Throws:

Should not be used. Should remove the profile for the user.

Type
Meteor.Error

someProfiles(predicate) → {boolean}

Source:

Returns true if at least one profile satisfies the passed predicate.

Parameters:
Name Type Description
predicate

A function which can be applied to any document in any profile collection and returns true
or false.

Returns:

True if at least one document satisfies the predicate.

Type
boolean

subscribe()

Source:

Default subscription method for entities.
It subscribes to the entire collection.