-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #10: create DrupalUser and MeteorUser instances, refactored not…
…ifications.
- Loading branch information
Showing
5 changed files
with
180 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* @file | ||
* Contains the MeteorUser class. | ||
*/ | ||
|
||
Log.debug('Defining shared/DrupalUser'); | ||
|
||
/** | ||
* A class providing the mechanisms for the Meteor side of Drupal accounts. | ||
* | ||
* @type {MeteorUser} | ||
*/ | ||
MeteorUser = class MeteorUser { | ||
/** | ||
* @constructor | ||
* | ||
* @param {DrupalUser} drupalUser | ||
* The Drupal user to reflect to the Meteor database. | ||
*/ | ||
constructor(drupalUser) { | ||
const anome = Meteor.settings['accounts-drupal'].anonymousName; | ||
const defaultProfile = this.makeProfile(anome); | ||
this._id = new MongoID(); | ||
this.createdAt = new Date(); | ||
this.services = { | ||
'accounts-drupal': { | ||
id: anome, | ||
public: defaultProfile, | ||
onProfile: defaultProfile, | ||
offProfile: defaultProfile, | ||
}, | ||
resume: { | ||
loginTokens: [], | ||
} | ||
}; | ||
this.profile = { | ||
'accounts-drupal': defaultProfile, | ||
}; | ||
this.username = anome; | ||
this.emails = []; | ||
|
||
for (const item of Object.keys(data)) { | ||
this[item] = data[item]; | ||
} | ||
} | ||
|
||
makeProfile(anome, data) { | ||
if (typeof data === 'undefined') { | ||
return { | ||
uid: 0, | ||
name: anome, | ||
displayName: anome, | ||
roles: [], | ||
}; | ||
} | ||
|
||
let result; | ||
return result; | ||
} | ||
|
||
/** | ||
* Find the existing collection record for a given Drupal userID. | ||
* | ||
* @param {int} userId | ||
* The userID to look for. | ||
* @param {Collection} users | ||
* The Meteor users collection. | ||
* | ||
* @returns {bool|Object} | ||
* The database document if found, false otherwise. | ||
*/ | ||
static findByUserId(userId, users) { | ||
const currentRaw = users.findOne({ | ||
[MeteorUser.USER_KEY]: userId, | ||
}) || false; | ||
return currentRaw; | ||
} | ||
|
||
/** | ||
* Update an existing collection record from a DrupalUser instance. | ||
* | ||
* @param {DrupalUser} drupalUser | ||
* @param {Collection} users | ||
*/ | ||
static updateFromDrupal(drupalUser, users) { | ||
} | ||
|
||
/** | ||
* The name of the key used to locate records by Drupal userID. | ||
* | ||
* @returns {string} | ||
* The key. | ||
*/ | ||
static get USER_KEY() { | ||
return 'services.accounts-drupal.public.uid'; | ||
} | ||
}; |