Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added possibility to get receipients and their email addresses #224

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions owncloud/owncloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,46 @@ def user_is_in_subadmin_group(self, user_name, group_name):
"""
return group_name in self.get_user_subadmin_groups(user_name)

def get_possible_user_labels_to_share(self, search_string, items_per_page, item_type):
"""Get user labels corresponding to the username being searched
:param search_string: string being searched, e.g. LastName FirstName
:param items_per_page: item count being returned per page
:param item_type: item type possibly being shared, e.g. folder
"""
receipient_path = "format=xml"
#replace space with plus which is conform with the API
receipient_path += "&search=" + search_string.replace(" ", "+")
receipient_path += "&perPage=" + str(items_per_page)
receipient_path += "&itemType=" + str(item_type)

res = self._make_ocs_request(
'GET',
self.OCS_SERVICE_SHARE,
'sharees?' + receipient_path
)
labelElements = self._parse_xml_for_wanted_element(res.content, "label")
return labelElements

def get_possible_user_emails_to_share(self, search_string, items_per_page, item_type):
"""Get email addresses corresponding to the username being searched
:param search_string: string being searched, e.g. LastName FirstName
:param items_per_page: item count being returned per page
:param item_type: item type possibly being shared, e.g. folder
"""
receipient_path = "format=xml"
#replace space with plus which is conform with the API
receipient_path += "&search=" + search_string.replace(" ", "+")
receipient_path += "&perPage=" + str(items_per_page)
receipient_path += "&itemType=" + str(item_type)

res = self._make_ocs_request(
'GET',
self.OCS_SERVICE_SHARE,
'sharees?' + receipient_path
)
shareWithElements = self._parse_xml_for_wanted_element(res.content, "shareWith")
return shareWithElements

def share_file_with_user(self, path, user, **kwargs):
"""Shares a remote file with specified user

Expand Down Expand Up @@ -1831,6 +1871,23 @@ def _webdav_move_copy(self, remote_path_source, remote_path_target,
headers=headers
)

def _parse_xml_for_wanted_element(self, xmlString, wantedElement):
"""Get labels or emails out of an XML
:param xmlString: result out of a HTTP request which will be gone through
:param wantedElement: XML tag to look for
"""
wantedElementArray = []
tree = ET.fromstring(xmlString)
users = tree.find("data").find("users")
elements = users.findall("element")
if wantedElement == "label":
for element in elements:
wantedElementArray.append(element.find(wantedElement).text)
if (wantedElement == "shareType") or (wantedElement == "shareWith") or (wantedElement == "shareWithAdditionalInfo"):
for element in elements:
wantedElementArray.append(element.find("value").find(wantedElement).text)
return wantedElementArray

def _xml_to_dict(self, element):
"""
Take an XML element, iterate over it and build a dict
Expand Down