# HG changeset patch # User Goffi # Date 1521011244 -3600 # Node ID e4de2f16a284807b50f1166020717240d8d9d8d4 # Parent cd7a53c31eb6067bc67dc8d2e55750f8956a6230 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. diff -r cd7a53c31eb6 -r e4de2f16a284 src/memory/memory.py --- a/src/memory/memory.py Wed Mar 14 08:05:55 2018 +0100 +++ b/src/memory/memory.py Wed Mar 14 08:07:24 2018 +0100 @@ -1186,6 +1186,8 @@ """ if peer_jid is None and perms_to_check or perms_to_check is None and peer_jid: raise exceptions.InternalError('if you want to disable permission check, both peer_jid and perms_to_check must be None') + if owner is not None: + owner = owner.userhostJID() if path is not None: # permission are checked by _getParentDir parent, remaining_path_elts = yield self._getParentDir(client, path, parent, namespace, owner, peer_jid, perms_to_check) @@ -1244,7 +1246,7 @@ @param created(int): UNIX time of creation @param modified(int,None): UNIX time of last modification, or None to use created date @param owner(jid.JID, None): jid of the owner of the file (mainly useful for component) - will be used to check permission. + will be used to check permission (only bare jid is used, don't use with MUC). Use None to ignore permission (perms_to_check must be None too) @param access(dict, None): serialisable dictionary with access rules. None (or empty dict) to use private access, i.e. allow only profile's jid to access the file @@ -1276,11 +1278,11 @@ if type_ == C.FILE_TYPE_DIRECTORY: if any(version, file_hash, size, mime_type): raise ValueError(u"version, file_hash, size and mime_type can't be set for a directory") + if owner is not None: + owner = owner.userhostJID() if path is not None: - if peer_jid is None: - peer_jid = owner - # _getParentDir will check permissions if peer_jid is set + # _getParentDir will check permissions if peer_jid is set, so we use owner parent, remaining_path_elts = yield self._getParentDir(client, path, parent, namespace, owner, owner, perms_to_check) # if remaining directories don't exist, we have to create them for new_dir in remaining_path_elts: @@ -1288,7 +1290,7 @@ yield self.storage.setFile(client, name=new_dir, file_id=new_dir_id, version=u'', parent=parent, type_=C.FILE_TYPE_DIRECTORY, namespace=namespace, created=time.time(), - owner=owner.userhostJID() if owner else None, + owner=owner, access=access, extra={}) parent = new_dir_id elif parent is None: @@ -1297,7 +1299,7 @@ yield self.storage.setFile(client, file_id=file_id, version=version, parent=parent, type_=type_, file_hash=file_hash, hash_algo=hash_algo, name=name, size=size, namespace=namespace, mime_type=mime_type, created=created, modified=modified, - owner=owner.userhostJID() if owner else None, + owner=owner, access=access, extra=extra) ## Misc ##