pymensago/workspace.py
def generate(self, userid: UserID, server: Domain, wid: UUID, pw: encryption.Password) -> RetVal:
		'''Creates all the data needed for an individual workspace account'''

		if not userid.is_valid() and userid:
			return RetVal(ErrBadValue, 'userid not valid')
		if not server.is_valid():
			return RetVal(ErrBadValue, 'domain not valid')
		if not wid.is_valid():
			return RetVal(ErrBadValue, 'workspace id not valid')
		if not pw.is_valid():
			return RetVal(ErrBadValue, 'password not valid')

		self.uid = userid
		self.wid = wid
		self.domain = server
		self.pw = pw

		address = wid.as_string() + '/' + server.as_string()

		# Generate user's encryption keys
		keys = {
			'crencryption' : (encryption.EncryptionPair(), 'crencrypt'),
			'crsigning' : (encryption.SigningPair(), 'crsign'),
			'encryption' : (encryption.EncryptionPair(), 'encrypt'),
			'signing' : (encryption.SigningPair(), 'sign'),
			'storage' : (encryption.SecretKey(), 'storage'),
			'folder' : (encryption.SecretKey(), 'folder'),
		}
		
		# Add encryption keys
		for keydata in keys.values():
			out = auth.add_key(self.db, keydata[0], address, keydata[1])
			if out.error():
				status = self.remove_workspace_entry(wid, server)
				if status.error():
					return status
		
		# Add folder mappings
		foldermap = FolderMap()

		folderlist = [
			'/messages',
			'/contacts',
			'/events',
			'/tasks',
			'/notes',
			'/files',
			'/files/attachments'
		]

		for folder in folderlist:
			foldermap.MakeID()
			foldermap.Set(address, keys['folder'][0].pubhash, folder, 'root')
			self.add_folder(foldermap)

		# Create the folders themselves
		try:
			self.path.mkdir(parents=True, exist_ok=True)
		except Exception as e:
			self.remove_from_db()
			return RetVal.wrap_exception(e)
		
		self.path.joinpath('files').mkdir(exist_ok=True)
		self.path.joinpath('files','attachments').mkdir(exist_ok=True)

		self.set_userid(userid)
		return RetVal()
Creates all the data needed for an individual workspace account
Creates all the data needed for an individual workspace account
Creates all the data needed for an individual workspace account
def generate(self, userid: UserID, server: Domain, wid: UUID, pw: encryption.Password) -> RetVal:
		if not userid.is_valid() and userid:
			return RetVal(ErrBadValue, 'userid not valid')
		if not server.is_valid():
			return RetVal(ErrBadValue, 'domain not valid')
		if not wid.is_valid():
			return RetVal(ErrBadValue, 'workspace id not valid')
		if not pw.is_valid():
			return RetVal(ErrBadValue, 'password not valid')
		self.uid = userid
		self.wid = wid
		self.domain = server
		self.pw = pw
		address = wid.as_string() + '/' + server.as_string()
		keys = {
			'crencryption' : (encryption.EncryptionPair(), 'crencrypt'),
			'crsigning' : (encryption.SigningPair(), 'crsign'),
			'encryption' : (encryption.EncryptionPair(), 'encrypt'),
			'signing' : (encryption.SigningPair(), 'sign'),
			'storage' : (encryption.SecretKey(), 'storage'),
			'folder' : (encryption.SecretKey(), 'folder'),
		}
		for keydata in keys.values():
			out = auth.add_key(self.db, keydata[0], address, keydata[1])
			if out.error():
				status = self.remove_workspace_entry(wid, server)
				if status.error():
					return status
		foldermap = FolderMap()
		folderlist = [
			'/messages',
			'/contacts',
			'/events',
			'/tasks',
			'/notes',
			'/files',
			'/files/attachments'
		]
		for folder in folderlist:
			foldermap.MakeID()
			foldermap.Set(address, keys['folder'][0].pubhash, folder, 'root')
			self.add_folder(foldermap)
		try:
			self.path.mkdir(parents=True, exist_ok=True)
		except Exception as e:
			self.remove_from_db()
			return RetVal.wrap_exception(e)
		self.path.joinpath('files').mkdir(exist_ok=True)
		self.path.joinpath('files','attachments').mkdir(exist_ok=True)
		self.set_userid(userid)
		return RetVal()
def generate ( self , userid : UserID , server : Domain , wid : UUID , pw : encryption . Password ) -> RetVal : if not userid . is_valid ( ) and userid : return RetVal ( ErrBadValue , 'userid not valid' ) if not server . is_valid ( ) : return RetVal ( ErrBadValue , 'domain not valid' ) if not wid . is_valid ( ) : return RetVal ( ErrBadValue , 'workspace id not valid' ) if not pw . is_valid ( ) : return RetVal ( ErrBadValue , 'password not valid' ) self . uid = userid self . wid = wid self . domain = server self . pw = pw address = wid . as_string ( ) + '/' + server . as_string ( ) keys = { 'crencryption' : ( encryption . EncryptionPair ( ) , 'crencrypt' ) , 'crsigning' : ( encryption . SigningPair ( ) , 'crsign' ) , 'encryption' : ( encryption . EncryptionPair ( ) , 'encrypt' ) , 'signing' : ( encryption . SigningPair ( ) , 'sign' ) , 'storage' : ( encryption . SecretKey ( ) , 'storage' ) , 'folder' : ( encryption . SecretKey ( ) , 'folder' ) , } for keydata in keys . values ( ) : out = auth . add_key ( self . db , keydata [ 0 ] , address , keydata [ 1 ] ) if out . error ( ) : status = self . remove_workspace_entry ( wid , server ) if status . error ( ) : return status foldermap = FolderMap ( ) folderlist = [ '/messages' , '/contacts' , '/events' , '/tasks' , '/notes' , '/files' , '/files/attachments' ] for folder in folderlist : foldermap . MakeID ( ) foldermap . Set ( address , keys [ 'folder' ] [ 0 ] . pubhash , folder , 'root' ) self . add_folder ( foldermap ) try : self . path . mkdir ( parents = True , exist_ok = True ) except Exception as e : self . remove_from_db ( ) return RetVal . wrap_exception ( e ) self . path . joinpath ( 'files' ) . mkdir ( exist_ok = True ) self . path . joinpath ( 'files' , 'attachments' ) . mkdir ( exist_ok = True ) self . set_userid ( userid ) return RetVal ( )
Creates all the data needed for an individual workspace account
Creates all the data needed for an individual workspace account
'''Creates all the data needed for an individual workspace account''' # Generate user's encryption keys # Add encryption keys # Add folder mappings # Create the folders themselves
self
userid
UserID
server
Domain
wid
UUID
pw
encryption.Password