def __init__(self, data, raise_on_unknown=True): self._data_in = copy.deepcopy(data) # to not modify callers data self._data_orig = copy.deepcopy(data) # to not modify callers data self._data = dict() self._parse_check_invalid_users() # things without setters _id = self._data_in.pop('_id', None) if _id is None: _id = bson.ObjectId() if not isinstance(_id, bson.ObjectId): _id = bson.ObjectId(_id) self._data['_id'] = _id if 'sn' in self._data_in: self._data_in['surname'] = self._data_in.pop('sn') if 'eduPersonEntitlement' in self._data_in: self._data_in['entitlements'] = self._data_in.pop( 'eduPersonEntitlement') self._parse_mail_addresses() self._parse_phone_numbers() self._parse_nins() self._parse_tous() self._passwords = PasswordList(self._data_in.pop('passwords', [])) # generic (known) attributes self.eppn = self._data_in.pop('eduPersonPrincipalName') # mandatory self.subject = self._data_in.pop('subject', None) self.display_name = self._data_in.pop('displayName', None) self.given_name = self._data_in.pop('givenName', None) self.surname = self._data_in.pop('surname', None) self.language = self._data_in.pop('preferredLanguage', None) self.modified_ts = self._data_in.pop('modified_ts', None) self.entitlements = self._data_in.pop('entitlements', None) self.terminated = self._data_in.pop('terminated', None) # obsolete attributes if 'postalAddress' in self._data_in: del self._data_in['postalAddress'] if 'date' in self._data_in: del self._data_in['date'] if 'csrf' in self._data_in: del self._data_in['csrf'] # temporary data we just want to retain as is for copy_attribute in ['letter_proofing_data']: if copy_attribute in self._data_in: self._data[copy_attribute] = self._data_in.pop(copy_attribute) if len(self._data_in) > 0: if raise_on_unknown: raise UserHasUnknownData( 'User {!s}/{!s} unknown data: {!r}'.format( self.user_id, self.eppn, self._data_in.keys())) # Just keep everything that is left as-is self._data.update(self._data_in)
def __init__(self, userid=None, tou=None, data=None, raise_on_unknown=True): """ """ if data is None: data = {'_id': userid, 'tou': tou} if '_id' not in data or data['_id'] is None: raise UserMissingData('Attempting to record a ToU acceptance ' 'for an unidentified user.') if 'tou' not in data or data['tou'] is None: raise UserMissingData('Attempting to record the acceptance of ' 'an unknown version of the ToU for ' 'the user with id ' + str(data['_id'])) self._data_in = deepcopy(data) self._data = dict() # things without setters _id = self._data_in.pop('_id', None) if not isinstance(_id, bson.ObjectId): _id = bson.ObjectId(_id) self._data['_id'] = _id self._parse_tous() self.modified_ts = self._data_in.pop('modified_ts', None) if len(self._data_in) > 0: if raise_on_unknown: raise UserHasUnknownData('User {!s} unknown data: {!r}'.format( self.user_id, self._data_in.keys())) # Just keep everything that is left as-is self._data.update(self._data_in)
def __init__(self, userid=None, passwords=None, data=None, raise_on_unknown=True): """ """ if data is None: data = {'_id': userid, 'passwords': passwords} if '_id' not in data or data['_id'] is None: raise UserMissingData('Attempting to record passwords ' 'for an unidentified user.') if 'passwords' not in data or data['passwords'] is None: raise UserMissingData('Attempting to record ' 'an unknown password for ' 'the user with id ' + str(data['_id'])) self._data_in = deepcopy(data) self._data = dict() # things without setters _id = self._data_in.pop('_id', None) if not isinstance(_id, bson.ObjectId): _id = bson.ObjectId(_id) self._data['_id'] = _id self._passwords = PasswordList(self._data_in.pop('passwords', [])) self.modified_ts = self._data_in.pop('modified_ts', None) if len(self._data_in) > 0: if raise_on_unknown: raise UserHasUnknownData('User {!s} unknown data: {!r}'.format( self.user_id, self._data_in.keys())) # Just keep everything that is left as-is self._data.update(self._data_in)
def __init__(self, credential_id=None, salt=None, application=None, created_ts=None, data=None, raise_on_unknown=True): data_in = data data = copy.copy(data_in) # to not modify callers data if data is None: if created_ts is None: created_ts = True data = dict( id=credential_id, salt=salt, created_by=application, created_ts=created_ts, ) if 'source' in data: # XXX We should rename source in db data['created_by'] = data.pop('source') Element.__init__(self, data) self.id = data.pop('id') self.salt = data.pop('salt') leftovers = data.keys() if leftovers: if raise_on_unknown: raise UserHasUnknownData( 'Password {!r} unknown data: {!r}'.format( self.id, leftovers, )) # Just keep everything that is left as-is self._data.update(data)
def __init__(self, data, raise_on_unknown=True): self._data_in = copy.deepcopy(data) # to not modify callers data self._data = dict() # things without setters # _id _id = self._data_in.pop('_id', None) if _id is None: _id = bson.ObjectId() if not isinstance(_id, bson.ObjectId): _id = bson.ObjectId(_id) self._data['_id'] = _id # eppn eppn = self._data_in.pop('eduPersonPrincipalName') self._data['eduPersonPrincipalName'] = eppn self.modified_ts = self._data_in.pop('modified_ts', None) if len(self._data_in) > 0: if raise_on_unknown: raise UserHasUnknownData('User {!s} unknown data: {!r}'.format( self.eppn, self._data_in.keys())) # Just keep everything that is left as-is self._data.update(self._data_in)