pycontribs / python-crowd

A python client to the Atlassian Crowd REST API. ❗️seeking-new-maintainer
https://github.com/pycontribs/python-crowd
BSD 2-Clause "Simplified" License
45 stars 41 forks source link

remove user from group #43

Closed mikuamuro closed 5 years ago

mikuamuro commented 6 years ago

Would it be possible to implement "remove direct group membership" via the python client? (As I noted that no delete had been implemented so far ... )

Here is the restfulAPI from Crowd: https://docs.atlassian.com/atlassian-crowd/3.1.1/REST/#usermanagement/1/group-removeDirectGroupMembership

Thanks!

mikuamuro commented 6 years ago

Got it working with this:

def remove_user_from_group(self, username, groupname, raise_on_error=False):
    """Remove a user from a group
    :param username: The username to remove from the group
    :param groupname: The group name to be removed from the user
    :return: True on success, False on failure.
    """
    response = self._delete(self.rest_url + "/group/user/direct",params={"username": username, "groupname": groupname})

    print response

    if response.status_code == 204:
        return True

    if raise_on_error:
        raise RuntimeError(response.json()['message'])

    return False
potus98 commented 6 years ago

Hi @mikuamuro , Were you planning to submit the suggested code change above as a pull request?

If not, I'm curious to understand why the code would be shared in this format, but not as a PR? I'm new-ish here and would like to know if this a common workflow. Thank you.

potus98 commented 5 years ago

Thanks @mikuamuro for the example code. I've been using it for a while and it works fine.

Pull request #48 was submitted and approved to add remove_user_from_group functionality.

aelse commented 5 years ago

Resolved by #48. Thank you!