comparison src/memory/memory.py @ 2518:e4de2f16a284

core (memory): use bare jid for owner in setFiles: this makes files unusable for MUCs private conversations, but it doesn't make much sense to use it in this case.
author Goffi <goffi@goffi.org>
date Wed, 14 Mar 2018 08:07:24 +0100
parents 4e5cc45e2be7
children 35d591086974
comparison
equal deleted inserted replaced
2517:cd7a53c31eb6 2518:e4de2f16a284
1184 @raise exceptions.PermissionError: peer_jid can't use perms_to_check for one of the file 1184 @raise exceptions.PermissionError: peer_jid can't use perms_to_check for one of the file
1185 on the path 1185 on the path
1186 """ 1186 """
1187 if peer_jid is None and perms_to_check or perms_to_check is None and peer_jid: 1187 if peer_jid is None and perms_to_check or perms_to_check is None and peer_jid:
1188 raise exceptions.InternalError('if you want to disable permission check, both peer_jid and perms_to_check must be None') 1188 raise exceptions.InternalError('if you want to disable permission check, both peer_jid and perms_to_check must be None')
1189 if owner is not None:
1190 owner = owner.userhostJID()
1189 if path is not None: 1191 if path is not None:
1190 # permission are checked by _getParentDir 1192 # permission are checked by _getParentDir
1191 parent, remaining_path_elts = yield self._getParentDir(client, path, parent, namespace, owner, peer_jid, perms_to_check) 1193 parent, remaining_path_elts = yield self._getParentDir(client, path, parent, namespace, owner, peer_jid, perms_to_check)
1192 if remaining_path_elts: 1194 if remaining_path_elts:
1193 # if we have remaining path elements, 1195 # if we have remaining path elements,
1242 for instance, namespace could be used to group files in a specific photo album 1244 for instance, namespace could be used to group files in a specific photo album
1243 @param mime_type(unicode): MIME type of the file, or None if not known/guessed 1245 @param mime_type(unicode): MIME type of the file, or None if not known/guessed
1244 @param created(int): UNIX time of creation 1246 @param created(int): UNIX time of creation
1245 @param modified(int,None): UNIX time of last modification, or None to use created date 1247 @param modified(int,None): UNIX time of last modification, or None to use created date
1246 @param owner(jid.JID, None): jid of the owner of the file (mainly useful for component) 1248 @param owner(jid.JID, None): jid of the owner of the file (mainly useful for component)
1247 will be used to check permission. 1249 will be used to check permission (only bare jid is used, don't use with MUC).
1248 Use None to ignore permission (perms_to_check must be None too) 1250 Use None to ignore permission (perms_to_check must be None too)
1249 @param access(dict, None): serialisable dictionary with access rules. 1251 @param access(dict, None): serialisable dictionary with access rules.
1250 None (or empty dict) to use private access, i.e. allow only profile's jid to access the file 1252 None (or empty dict) to use private access, i.e. allow only profile's jid to access the file
1251 key can be on on C.ACCESS_PERM_*, 1253 key can be on on C.ACCESS_PERM_*,
1252 then a sub dictionary with a type key is used (one of C.ACCESS_TYPE_*). 1254 then a sub dictionary with a type key is used (one of C.ACCESS_TYPE_*).
1274 if namespace is not None: 1276 if namespace is not None:
1275 namespace = namespace.strip() or None 1277 namespace = namespace.strip() or None
1276 if type_ == C.FILE_TYPE_DIRECTORY: 1278 if type_ == C.FILE_TYPE_DIRECTORY:
1277 if any(version, file_hash, size, mime_type): 1279 if any(version, file_hash, size, mime_type):
1278 raise ValueError(u"version, file_hash, size and mime_type can't be set for a directory") 1280 raise ValueError(u"version, file_hash, size and mime_type can't be set for a directory")
1281 if owner is not None:
1282 owner = owner.userhostJID()
1279 1283
1280 if path is not None: 1284 if path is not None:
1281 if peer_jid is None: 1285 # _getParentDir will check permissions if peer_jid is set, so we use owner
1282 peer_jid = owner
1283 # _getParentDir will check permissions if peer_jid is set
1284 parent, remaining_path_elts = yield self._getParentDir(client, path, parent, namespace, owner, owner, perms_to_check) 1286 parent, remaining_path_elts = yield self._getParentDir(client, path, parent, namespace, owner, owner, perms_to_check)
1285 # if remaining directories don't exist, we have to create them 1287 # if remaining directories don't exist, we have to create them
1286 for new_dir in remaining_path_elts: 1288 for new_dir in remaining_path_elts:
1287 new_dir_id = shortuuid.uuid() 1289 new_dir_id = shortuuid.uuid()
1288 yield self.storage.setFile(client, name=new_dir, file_id=new_dir_id, version=u'', parent=parent, 1290 yield self.storage.setFile(client, name=new_dir, file_id=new_dir_id, version=u'', parent=parent,
1289 type_=C.FILE_TYPE_DIRECTORY, namespace=namespace, 1291 type_=C.FILE_TYPE_DIRECTORY, namespace=namespace,
1290 created=time.time(), 1292 created=time.time(),
1291 owner=owner.userhostJID() if owner else None, 1293 owner=owner,
1292 access=access, extra={}) 1294 access=access, extra={})
1293 parent = new_dir_id 1295 parent = new_dir_id
1294 elif parent is None: 1296 elif parent is None:
1295 parent = u'' 1297 parent = u''
1296 1298
1297 yield self.storage.setFile(client, file_id=file_id, version=version, parent=parent, type_=type_, 1299 yield self.storage.setFile(client, file_id=file_id, version=version, parent=parent, type_=type_,
1298 file_hash=file_hash, hash_algo=hash_algo, name=name, size=size, 1300 file_hash=file_hash, hash_algo=hash_algo, name=name, size=size,
1299 namespace=namespace, mime_type=mime_type, created=created, modified=modified, 1301 namespace=namespace, mime_type=mime_type, created=created, modified=modified,
1300 owner=owner.userhostJID() if owner else None, 1302 owner=owner,
1301 access=access, extra=extra) 1303 access=access, extra=extra)
1302 1304
1303 ## Misc ## 1305 ## Misc ##
1304 1306
1305 def isEntityAvailable(self, entity_jid, profile_key): 1307 def isEntityAvailable(self, entity_jid, profile_key):