sharing: add property overlay and update support
This commit is contained in:
@@ -122,8 +122,9 @@ class Sharing(sharing.BaseSharing):
|
||||
UserShare = row['User']
|
||||
Permissions = row['Permissions']
|
||||
Hidden: bool = (row['HiddenByOwner'] or row['HiddenByUser'])
|
||||
Properties = row['Properties']
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("TRACE/sharing: map %r to %r (Owner=%r User=%r Permissions=%r Hidden=%s)", PathOrToken, PathMapped, Owner, UserShare, Permissions, Hidden)
|
||||
logger.debug("TRACE/sharing: map %r to %r (Owner=%r User=%r Permissions=%r Hidden=%s Properties=%r)", PathOrToken, PathMapped, Owner, UserShare, Permissions, Hidden, Properties)
|
||||
return {
|
||||
"mapped": True,
|
||||
"PathOrToken": PathOrToken,
|
||||
@@ -131,7 +132,8 @@ class Sharing(sharing.BaseSharing):
|
||||
"Owner": Owner,
|
||||
"User": UserShare,
|
||||
"Hidden": Hidden,
|
||||
"Permissions": Permissions}
|
||||
"Permissions": Permissions,
|
||||
"Properties": Properties}
|
||||
|
||||
return None
|
||||
|
||||
@@ -214,7 +216,8 @@ class Sharing(sharing.BaseSharing):
|
||||
Permissions: str = "r",
|
||||
EnabledByOwner: bool = False, EnabledByUser: bool = False,
|
||||
HiddenByOwner: bool = True, HiddenByUser: bool = True,
|
||||
Timestamp: int = 0) -> dict:
|
||||
Timestamp: int = 0,
|
||||
Properties: Union[str, None] = None) -> dict:
|
||||
""" create sharing """
|
||||
row: dict
|
||||
|
||||
@@ -258,16 +261,17 @@ class Sharing(sharing.BaseSharing):
|
||||
def update_sharing(self,
|
||||
ShareType: str,
|
||||
PathOrToken: str,
|
||||
Owner: Union[str, None] = None,
|
||||
OwnerOrUser: str,
|
||||
User: Union[str, None] = None,
|
||||
PathMapped: Union[str, None] = None,
|
||||
Permissions: Union[str, None] = None,
|
||||
EnabledByOwner: Union[bool, None] = None,
|
||||
HiddenByOwner: Union[bool, None] = None,
|
||||
Timestamp: int = 0) -> dict:
|
||||
Timestamp: int = 0,
|
||||
Properties: Union[str, None] = None) -> dict:
|
||||
""" update sharing """
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("TRACE/sharing/%s/update: PathOrToken=%r Owner=%r User=%r", ShareType, PathOrToken, Owner, User)
|
||||
logger.debug("TRACE/sharing/%s/update: PathOrToken=%r OwnerOrUser=%r User=%r Properties=%r", ShareType, PathOrToken, OwnerOrUser, User, Properties)
|
||||
|
||||
sharing_config_file = os.path.join(self._sharing_db_path_ShareType[ShareType], self._encode_path(PathOrToken))
|
||||
|
||||
@@ -275,7 +279,7 @@ class Sharing(sharing.BaseSharing):
|
||||
return {"status": "not-found"}
|
||||
|
||||
# read content
|
||||
with self._storage.acquire_lock("w", Owner, path=sharing_config_file):
|
||||
with self._storage.acquire_lock("w", OwnerOrUser, path=sharing_config_file):
|
||||
# read file
|
||||
with open(sharing_config_file, "rb") as fb:
|
||||
(version, row) = pickle.load(fb)
|
||||
@@ -286,8 +290,17 @@ class Sharing(sharing.BaseSharing):
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("TRACE/sharing/%s/update: check: %r", ShareType, row)
|
||||
|
||||
if Owner is not None and row['Owner'] != Owner:
|
||||
return {"status": "permission-denied"}
|
||||
if row['Owner'] != OwnerOrUser:
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("TRACE/sharing/%s/update: OwnerOrUser=%r not matching Owner=%r -> check now for matching User=%r", ShareType, OwnerOrUser, row['Owner'], row['User'])
|
||||
if row['User'] == OwnerOrUser and PathMapped is None and Permissions is None and EnabledByOwner is None and HiddenByOwner is None and Properties is not None:
|
||||
# user is only permitted to update Properties
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("TRACE/sharing/%s/update: OwnerOrUser=%r PathOrToken=%r is permitted to update Properties", ShareType, OwnerOrUser, PathOrToken)
|
||||
pass
|
||||
else:
|
||||
return {"status": "permission-denied"}
|
||||
|
||||
if User is not None and row['User'] != User:
|
||||
return {"status": "permission-denied"}
|
||||
|
||||
@@ -304,6 +317,8 @@ class Sharing(sharing.BaseSharing):
|
||||
row["EnabledByOwner"] = EnabledByOwner
|
||||
if HiddenByOwner is not None:
|
||||
row["HiddenByOwner"] = HiddenByOwner
|
||||
if Properties is not None:
|
||||
row["Properties"] = Properties
|
||||
# update timestamp
|
||||
row["TimestampUpdated"] = Timestamp
|
||||
|
||||
|
||||
Reference in New Issue
Block a user