-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #373 from mesozoic/grant_revoke_admin
Add support for grant/revoke admin access
- Loading branch information
Showing
5 changed files
with
93 additions
and
8 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,3 +158,15 @@ via the following methods. | |
`Delete users by email <https://airtable.com/developers/web/api/delete-users-by-email>`__ | ||
|
||
>>> enterprise.delete_users(["[email protected]", "[email protected]"]) | ||
|
||
`Grant admin access <https://airtable.com/developers/web/api/grant-admin-access>`__ | ||
|
||
>>> enterprise.grant_admin("usrUserId") | ||
>>> enterprise.grant_admin("[email protected]") | ||
>>> enterprise.grant_admin(enterprise.user("usrUserId")) | ||
|
||
`Revoke admin access <https://airtable.com/developers/web/api/revoke-admin-access>`__ | ||
|
||
>>> enterprise.revoke_admin("usrUserId") | ||
>>> enterprise.revoke_admin("[email protected]") | ||
>>> enterprise.revoke_admin(enterprise.user("usrUserId")) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,9 @@ | |
import pytest | ||
|
||
from pyairtable.api.enterprise import ( | ||
ClaimUsersResponse, | ||
DeleteUsersResponse, | ||
Enterprise, | ||
ManageUsersResponse, | ||
) | ||
from pyairtable.models.schema import EnterpriseInfo, UserGroup, UserInfo | ||
from pyairtable.testing import fake_id | ||
|
@@ -281,7 +281,7 @@ def test_claim_users(enterprise, enterprise_mocks): | |
"[email protected]": "unmanaged", | ||
} | ||
) | ||
assert isinstance(result, ClaimUsersResponse) | ||
assert isinstance(result, ManageUsersResponse) | ||
assert enterprise_mocks.claim_users.call_count == 1 | ||
assert enterprise_mocks.claim_users.last_request.json() == { | ||
"users": [ | ||
|
@@ -310,3 +310,24 @@ def test_delete_users(enterprise, requests_mock): | |
assert isinstance(parsed, DeleteUsersResponse) | ||
assert parsed.deleted_users[0].email == "[email protected]" | ||
assert parsed.errors[0].type == "INVALID_PERMISSIONS" | ||
|
||
|
||
@pytest.mark.parametrize("action", ["grant", "revoke"]) | ||
def test_manage_admin_access(enterprise, enterprise_mocks, requests_mock, action): | ||
user = enterprise.user(enterprise_mocks.user_id) | ||
m = requests_mock.post(f"{enterprise.url}/users/{action}AdminAccess", json={}) | ||
method = getattr(enterprise, f"{action}_admin") | ||
result = method( | ||
fake_user_id := fake_id("usr"), | ||
fake_email := "[email protected]", | ||
user, | ||
) | ||
assert isinstance(result, ManageUsersResponse) | ||
assert m.call_count == 1 | ||
assert m.last_request.json() == { | ||
"users": [ | ||
{"id": fake_user_id}, | ||
{"email": fake_email}, | ||
{"id": user.id}, | ||
] | ||
} |