diff --git a/pyzipline/zipline.py b/pyzipline/zipline.py index d20d79e..3637fed 100644 --- a/pyzipline/zipline.py +++ b/pyzipline/zipline.py @@ -35,9 +35,14 @@ class ZiplineApi: type: warning /// + /// admonition | Parameter Requires Super Administrator + type: danger + The authenticated user must be a Super Administrator to use the `admin` parameter. + /// + /// admonition | Conditionally Requires Administrator type: danger - The authenticated user must be an Administrator to use the `admin` parameter or register a user when registration is disabled. + The authenticated user must be an Administrator to register a user when registration is disabled. /// Args: @@ -47,23 +52,23 @@ class ZiplineApi: admin (bool): Whether or not the new user should be an administrator, authenticated user must be a super administrator to create an administrator Raises: - Forbidden: Raised if the authenticated user is not an super administrator and attempts to create an administrator FeatureDisabledError: Raised when:\n - - registration or invites are disabled on the Zipline instance and the authenticated user is not an administrator - - invite code is provided and invites are disabled + - registration or invites are disabled on the Zipline instance and the authenticated user is not an administrator + - invite code is provided and invites are disabled + Forbidden: Raised if the authenticated user is not an super administrator and attempts to create an administrator PyZiplineError: Raised if the API changes, causing a breaking change in this method ValueError: Raised when the username is already taken or if the invite code is invalid/expired Returns: User: The newly created user """ - data = {'username': username, 'password': password} + json = {'username': username, 'password': password} if invite is not None: - data['code'] = invite + json['code'] = invite if admin: - data['admin'] = True + json['admin'] = True - result: Result = self._rest_adapter.post(endpoint="auth/register", data=data) + result: Result = self._rest_adapter.post(endpoint="auth/register", json=json) if result.status_code == 200: return User(**result.data) @@ -98,8 +103,8 @@ class ZiplineApi: Returns: bool: True if user exists, False if not """ - data = {'username': username} if invite is None else {'username': username, 'code': invite} - result: Result = self._rest_adapter.post(endpoint="user/check", data=data) + json = {'username': username} if invite is None else {'username': username, 'code': invite} + result: Result = self._rest_adapter.post(endpoint="user/check", json=json) if result.status_code == 200: return False if result.message == 'username already exists': @@ -203,7 +208,7 @@ class ZiplineApi: return stats_list data = result.data[0] if isinstance(result.data, list) else result.data return Stats(**data) - if result.status_code == 401 or result.status_code == 403: + if result.status_code in (401, 403): raise Forbidden(result.message) raise PyZiplineError(f"{result.status_code}: {result.message}\n{result.data}")