Skip to content

Add support for filtering team/organization members by role #415

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

Merged
merged 6 commits into from
Jul 21, 2015
Merged

Add support for filtering team/organization members by role #415

merged 6 commits into from
Jul 21, 2015

Conversation

mwielgoszewski
Copy link
Contributor

Takes advantage of some of the improved organization permissions. In particular:

  • The List team members API accepts an optional role parameter, allowing you to fetch only maintainers or only regular members.
  • The organization Members list API now accepts a role parameter, so that you can request to see only the owners (or non-owners) of your organization.

Wasn't sure if this is something you want to add to github3.py yet, as these API calls are available in preview mode (requires submitting a custom HTTP Accept header).

@sigmavirus24
Copy link
Owner

Could you add tests for this @mwielgoszewski ?

@mwielgoszewski
Copy link
Contributor Author

@sigmavirus24 I'd be happy to, however I'm not sure where the best place to add them is. Some likely candidates are:

  • integration/test_orgs.py
  • integration/test_orgs_team.py
  • unit/test_orgs.py
  • unit/test_orgs_team.py

Would the test be best under integration or unit? I would need to mock the server-side reply which returns the users filtered based on their role. Where would that information reside? Another issue I had in my earlier pull request was filtering users with 2fa_disabled. This information was only available to owners, as can be seen in the following request (how would we test that?):

$ curl https://api.github.com/orgs/hapy/members?filter=2fa_disabled
{
  "message": "Only owners can use this filter.",
  "documentation_url": "https://developer.github.com/v3/orgs/members/#audit-two-factor-auth"
}

To test the Accept header, this appears to already be covered in unit/test_structs.py.

Any guidance you can provide would be appreciated.

@sigmavirus24
Copy link
Owner

So if you look at #395 (which I consider to be easily one of the most complete pull requests I've received recently) you'll see that @antoine-g added both an integration test and a unit test.

Since you're adding functionality to both the Team and Organization classes, you'll need to add at least one test to each of those files.

If there are integration tests that require you to be an org owner (and you aren't already one) do something like:

@pytest.mark.xfail(reason="sigmavirus24 needs to actually write a test for this")
def test_can_filter_organization_members_by_role(self):
    """Show that an owner can filter organization members by role."""
    # TODO(sigmavirus24): Write this integration test
    assert False

:param int number: (optional), number of members to return. Default:
-1 will return all available.
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`User <github3.users.User>`\ s
"""
headers = {}
params = {}
if filter in set(["2fa_disabled", "all"]):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize I didn't catch this on the last PR, but can we make these sets frozensets on the class itself?

In other words, something like,

class Organization(...):
    """docstring"""
    members_filters = frozenset(['2fa_disabled', 'all'])
    members_roles = frozenset(['all', 'admin', 'member'])

And likewise for the Team class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a good idea. I will add and include within this PR along with tests.

@mwielgoszewski
Copy link
Contributor Author

@sigmavirus24 I've added the necessary unit tests, integration tests, and cassettes in 7d3254b. I think the 2fa_disabled filter could have a second look, as this should only be available to organization owners.

@sigmavirus24
Copy link
Owner

@mwielgoszewski looks great! Could you just add 2 or 3 more unit tests to ensure that passing a bogus role/filter won't be passed through? E.g., tests like:

def test_members_excludes_fake_roles(self):
    i = self.instance.members(role='bogus-role-name')
    self.get_next(i)

    self.session.get.assert_called_once_with(
        # ...
        params={'per_page': 100},
        # ...
    )

@mwielgoszewski
Copy link
Contributor Author

Okay, just added some tests to ensure that a bogus role/filter isn't included in the request made to the API.

@sigmavirus24
Copy link
Owner

✨ 🍰 🎆 ✨ You're awesome @mwielgoszewski!

sigmavirus24 added a commit that referenced this pull request Jul 21, 2015
Add support for filtering team/organization members by role
@sigmavirus24 sigmavirus24 merged commit dcb4e48 into sigmavirus24:develop Jul 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants