-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Start of the sharing APIs * Update the user_search API * Rename APi * Add shareapi.py * Temporary lower k8s version * Move user_search to normal master * Return list * Save the object after grant perms * Not saving the actual object to avoid infinite recursion * V1 sharing is done * Clean up * Update user_search API request format * Add sharing incoming source
- Loading branch information
Showing
6 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
""" | ||
Object sharing APIs | ||
""" | ||
from jaseci.extens.api.interface import Interface | ||
from jaseci.prim.element import Element | ||
|
||
|
||
class ShareApi: | ||
""" | ||
Sharing APIs. | ||
""" | ||
|
||
def __init__(self): | ||
self.incoming = {} | ||
|
||
@Interface.private_api() | ||
def share_object( | ||
self, receiver: str, objs: list[Element] = [], read_only: bool = True | ||
): | ||
""" | ||
Sharing an object with a user | ||
obj: The list of elements to share | ||
receiver: master of the receiving user | ||
read_only: if set true, the object shared will be shared as read-only | ||
""" | ||
# Get the master object by id | ||
receiver_mast = self._h.get_obj( | ||
caller_id=self.jid, item_id=receiver, override=True | ||
) | ||
|
||
for obj in objs: | ||
# Grant read-only permission to the new user | ||
self.object_perms_grant(obj, receiver_mast, read_only=read_only) | ||
obj.save() | ||
|
||
# Add the objet id to the receiver's incoming list | ||
receiver_mast.incoming[str(obj.id)] = {"jid": self.jid, "name": self.name} | ||
|
||
receiver_mast.save() | ||
self.save() | ||
|
||
return { | ||
"objects": [str(obj) for obj in objs], | ||
"sharer": str(self), | ||
"receiver": str(receiver_mast), | ||
} | ||
|
||
@Interface.private_api() | ||
def share_incoming_pop(self, obj_id: str): | ||
""" | ||
Remove an item from the incoming list | ||
""" | ||
try: | ||
self.incoming.pop(obj_id) | ||
return True | ||
except Exception: | ||
return None | ||
|
||
@Interface.private_api() | ||
def share_incoming_list(self): | ||
""" | ||
Get the incoming objects | ||
""" | ||
return self.incoming |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters