fix: various fixes to ziplineapi
This commit is contained in:
parent
a6d127a903
commit
0cdb079f5e
1 changed files with 16 additions and 11 deletions
|
@ -35,9 +35,14 @@ class ZiplineApi:
|
||||||
type: warning
|
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
|
/// admonition | Conditionally Requires Administrator
|
||||||
type: danger
|
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:
|
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
|
admin (bool): Whether or not the new user should be an administrator, authenticated user must be a super administrator to create an administrator
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
Forbidden: Raised if the authenticated user is not an super administrator and attempts to create an administrator
|
|
||||||
FeatureDisabledError: Raised when:\n
|
FeatureDisabledError: Raised when:\n
|
||||||
- registration or invites are disabled on the Zipline instance and the authenticated user is not an administrator
|
- 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
|
- 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
|
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
|
ValueError: Raised when the username is already taken or if the invite code is invalid/expired
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
User: The newly created user
|
User: The newly created user
|
||||||
"""
|
"""
|
||||||
data = {'username': username, 'password': password}
|
json = {'username': username, 'password': password}
|
||||||
if invite is not None:
|
if invite is not None:
|
||||||
data['code'] = invite
|
json['code'] = invite
|
||||||
if admin:
|
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:
|
if result.status_code == 200:
|
||||||
return User(**result.data)
|
return User(**result.data)
|
||||||
|
|
||||||
|
@ -98,8 +103,8 @@ class ZiplineApi:
|
||||||
Returns:
|
Returns:
|
||||||
bool: True if user exists, False if not
|
bool: True if user exists, False if not
|
||||||
"""
|
"""
|
||||||
data = {'username': username} if invite is None else {'username': username, 'code': invite}
|
json = {'username': username} if invite is None else {'username': username, 'code': invite}
|
||||||
result: Result = self._rest_adapter.post(endpoint="user/check", data=data)
|
result: Result = self._rest_adapter.post(endpoint="user/check", json=json)
|
||||||
if result.status_code == 200:
|
if result.status_code == 200:
|
||||||
return False
|
return False
|
||||||
if result.message == 'username already exists':
|
if result.message == 'username already exists':
|
||||||
|
@ -203,7 +208,7 @@ class ZiplineApi:
|
||||||
return stats_list
|
return stats_list
|
||||||
data = result.data[0] if isinstance(result.data, list) else result.data
|
data = result.data[0] if isinstance(result.data, list) else result.data
|
||||||
return Stats(**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 Forbidden(result.message)
|
||||||
raise PyZiplineError(f"{result.status_code}: {result.message}\n{result.data}")
|
raise PyZiplineError(f"{result.status_code}: {result.message}\n{result.data}")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue