-
Notifications
You must be signed in to change notification settings - Fork 119
get all users + get all groups + get group members #187
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
Conversation
|
@nikaro, thanks for your PR! By analyzing the history of the files in this pull request, we identified @soalhn, @PVince81 and @individual-it to be potential reviewers. |
PVince81
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff!
Apart from the duplicate code from get_users this looks good.
|
|
||
| raise HTTPResponseError(res) | ||
|
|
||
| def get_users(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the existing method "search_users" already does that but it requires an additional argument.
I suggest you rewire it with "get_users" to avoid duplicate code.
Maybe rewrite get_users to call search_users without argument, and make search_users accept the empty argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PVince81 what do you think about this :
def search_users(self, user_name=''):
"""Searches for users via provisioning API.
If you get back an error 999, then the provisioning API is not enabled.
:param user_name: name of user to be searched for
:returns: list of usernames that contain user_name as substring
:raises: HTTPResponseError in case an HTTP error status was returned
"""
res = self._make_ocs_request(
'GET',
self.OCS_SERVICE_CLOUD,
'users?search=' + user_name
)
if res.status_code == 200:
tree = ET.fromstring(res.content)
users = [x.text for x in tree.findall('data/users/element')]
return users
raise HTTPResponseError(res)
def get_users(self):
"""Get users via provisioning API.
If you get back an error 999, then the provisioning API is not enabled.
:returns: list of usernames
:raises: HTTPResponseError in case an HTTP error status was returned
"""
return self.search_users()There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or i can leave search_users untouched by doing :
def search_users(self, user_name):
"""Searches for users via provisioning API.
If you get back an error 999, then the provisioning API is not enabled.
:param user_name: name of user to be searched for
:returns: list of usernames that contain user_name as substring
:raises: HTTPResponseError in case an HTTP error status was returned
"""
res = self._make_ocs_request(
'GET',
self.OCS_SERVICE_CLOUD,
'users?search=' + user_name
)
if res.status_code == 200:
tree = ET.fromstring(res.content)
users = [x.text for x in tree.findall('data/users/element')]
return users
raise HTTPResponseError(res)
def get_users(self):
"""Get users via provisioning API.
If you get back an error 999, then the provisioning API is not enabled.
:returns: list of usernames
:raises: HTTPResponseError in case an HTTP error status was returned
"""
return self.search_users('')What do you think is the best ?
- in the first case
get_usersis just an alias for emptysearch_users - in the second case, we keep throwing an exception if there is no argument passed `search_users'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to let search_users accept an empty string.
So let's use your last solution, the one with the code from #187 (comment).
As a bonus, it would be good to discard the "?search=" bit if no search string is passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done :-)
|
Great, thanks a lot ! 👍 |
Hello, i needed these functions so here they are.