Code and documentation cleanup
This commit is contained in:
parent
fd9c224c06
commit
aa2963c0c6
6 changed files with 51 additions and 36 deletions
32
API.md
32
API.md
|
@ -1495,10 +1495,10 @@ data.
|
||||||
|
|
||||||
Deletes existing user.
|
Deletes existing user.
|
||||||
|
|
||||||
## Listing tokens
|
## Listing user tokens
|
||||||
- **Request**
|
- **Request**
|
||||||
|
|
||||||
`GET /user-tokens/`
|
`GET /user-tokens/<user_name>`
|
||||||
|
|
||||||
- **Output**
|
- **Output**
|
||||||
|
|
||||||
|
@ -1513,15 +1513,19 @@ data.
|
||||||
|
|
||||||
Searches for users tokens for the currently logged in user.
|
Searches for users tokens for the currently logged in user.
|
||||||
|
|
||||||
## Creating token
|
## Creating a user token
|
||||||
- **Request**
|
- **Request**
|
||||||
|
|
||||||
`POST /user-token`
|
`POST /user-token/<user_name>`
|
||||||
|
|
||||||
- **Input**
|
- **Input**
|
||||||
|
|
||||||
```json5
|
```json5
|
||||||
{}
|
{
|
||||||
|
"enabled": <enabled>, // optional
|
||||||
|
"note": <note>, // optional
|
||||||
|
"expiration": <expiration>, // optional
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
- **Output**
|
- **Output**
|
||||||
|
@ -1537,10 +1541,10 @@ data.
|
||||||
Creates a new user token that can be used for authentication of api
|
Creates a new user token that can be used for authentication of api
|
||||||
endpoints instead of a password.
|
endpoints instead of a password.
|
||||||
|
|
||||||
## Updating user
|
## Updating a user token
|
||||||
- **Request**
|
- **Request**
|
||||||
|
|
||||||
`PUT /user-token/<token>`
|
`PUT /user-token/<user_name>/<token>`
|
||||||
|
|
||||||
- **Input**
|
- **Input**
|
||||||
|
|
||||||
|
@ -1548,6 +1552,8 @@ data.
|
||||||
{
|
{
|
||||||
"version": <version>,
|
"version": <version>,
|
||||||
"enabled": <enabled>, // optional
|
"enabled": <enabled>, // optional
|
||||||
|
"note": <note>, // optional
|
||||||
|
"expiration": <expiration>, // optional
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -1567,15 +1573,17 @@ data.
|
||||||
except the [`version`](#versioning) are optional - update concerns only
|
except the [`version`](#versioning) are optional - update concerns only
|
||||||
provided fields.
|
provided fields.
|
||||||
|
|
||||||
## Deleting token
|
## Deleting a user token
|
||||||
- **Request**
|
- **Request**
|
||||||
|
|
||||||
`DELETE /user-token/<token>`
|
`DELETE /user-token/<user_name>/<token>`
|
||||||
|
|
||||||
- **Input**
|
- **Input**
|
||||||
|
|
||||||
```json5
|
```json5
|
||||||
{}
|
{
|
||||||
|
"version": <version>,
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
- **Output**
|
- **Output**
|
||||||
|
@ -1836,7 +1844,9 @@ A single user token.
|
||||||
{
|
{
|
||||||
"user": <user>,
|
"user": <user>,
|
||||||
"token": <token>,
|
"token": <token>,
|
||||||
|
"note": <token>,
|
||||||
"enabled": <enabled>,
|
"enabled": <enabled>,
|
||||||
|
"expiration": <expiration>,
|
||||||
"version": <version>,
|
"version": <version>,
|
||||||
"creationTime": <creation-time>,
|
"creationTime": <creation-time>,
|
||||||
"lastEditTime": <last-edit-time>,
|
"lastEditTime": <last-edit-time>,
|
||||||
|
@ -1846,7 +1856,9 @@ A single user token.
|
||||||
**Field meaning**
|
**Field meaning**
|
||||||
- `<user>`: micro user. See [micro user](#micro-user).
|
- `<user>`: micro user. See [micro user](#micro-user).
|
||||||
- `<token>`: the token that can be used to authenticate the user.
|
- `<token>`: the token that can be used to authenticate the user.
|
||||||
|
- `<note>`: a note that describes the token.
|
||||||
- `<enabled>`: whether the token is still valid for authentication.
|
- `<enabled>`: whether the token is still valid for authentication.
|
||||||
|
- `<expiration>`: time when the token expires.
|
||||||
- `<version>`: resource version. See [versioning](#versioning).
|
- `<version>`: resource version. See [versioning](#versioning).
|
||||||
- `<creation-time>`: time the user token was created , formatted as per RFC 3339.
|
- `<creation-time>`: time the user token was created , formatted as per RFC 3339.
|
||||||
- `<last-edit-time>`: time the user token was edited, formatted as per RFC 3339.
|
- `<last-edit-time>`: time the user token was edited, formatted as per RFC 3339.
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any, Optional, Union, List, Dict, Callable
|
from typing import Any, Optional, Union, List, Dict, Callable
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
from szurubooru import config, db, model, errors, rest
|
from szurubooru import config, db, model, errors, rest
|
||||||
from szurubooru.func import auth, util, serialization, files, images
|
from szurubooru.func import auth, util, serialization, files, images
|
||||||
|
|
||||||
|
|
|
@ -26,11 +26,11 @@ def upgrade():
|
||||||
sa.Column('creation_time', sa.DateTime(), nullable=False),
|
sa.Column('creation_time', sa.DateTime(), nullable=False),
|
||||||
sa.Column('last_edit_time', sa.DateTime(), nullable=True),
|
sa.Column('last_edit_time', sa.DateTime(), nullable=True),
|
||||||
sa.Column('version', sa.Integer(), nullable=False),
|
sa.Column('version', sa.Integer(), nullable=False),
|
||||||
sa.ForeignKeyConstraint(['user_id'], ['user.id'],
|
sa.ForeignKeyConstraint(
|
||||||
ondelete='CASCADE'),
|
['user_id'], ['user.id'], ondelete='CASCADE'),
|
||||||
sa.PrimaryKeyConstraint('id'))
|
sa.PrimaryKeyConstraint('id'))
|
||||||
op.create_index(op.f('ix_user_token_user_id'), 'user_token',
|
op.create_index(
|
||||||
['user_id'], unique=False)
|
op.f('ix_user_token_user_id'), 'user_token', ['user_id'], unique=False)
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from szurubooru.model.base import Base
|
from szurubooru.model.base import Base
|
||||||
from szurubooru.model.user import (User, UserToken)
|
from szurubooru.model.user import User, UserToken
|
||||||
from szurubooru.model.tag_category import TagCategory
|
from szurubooru.model.tag_category import TagCategory
|
||||||
from szurubooru.model.tag import Tag, TagName, TagSuggestion, TagImplication
|
from szurubooru.model.tag import Tag, TagName, TagSuggestion, TagImplication
|
||||||
from szurubooru.model.post import (
|
from szurubooru.model.post import (
|
||||||
|
|
|
@ -12,14 +12,16 @@ def test_serialize_user_token(user_token_factory):
|
||||||
with patch('szurubooru.func.users.get_avatar_url'):
|
with patch('szurubooru.func.users.get_avatar_url'):
|
||||||
users.get_avatar_url.return_value = 'https://example.com/avatar.png'
|
users.get_avatar_url.return_value = 'https://example.com/avatar.png'
|
||||||
result = user_tokens.serialize_user_token(user_token, user_token.user)
|
result = user_tokens.serialize_user_token(user_token, user_token.user)
|
||||||
assert result == {'creationTime': datetime(1997, 1, 1, 0, 0),
|
assert result == {
|
||||||
|
'creationTime': datetime(1997, 1, 1, 0, 0),
|
||||||
'enabled': True,
|
'enabled': True,
|
||||||
'lastEditTime': None,
|
'lastEditTime': None,
|
||||||
'token': 'dummy',
|
'token': 'dummy',
|
||||||
'user': {
|
'user': {
|
||||||
'avatarUrl': 'https://example.com/avatar.png',
|
'avatarUrl': 'https://example.com/avatar.png',
|
||||||
'name': user_token.user.name},
|
'name': user_token.user.name},
|
||||||
'version': 1}
|
'version': 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_serialize_user_token_none():
|
def test_serialize_user_token_none():
|
||||||
|
|
|
@ -14,7 +14,8 @@ def test_process_request_no_header(context_factory):
|
||||||
|
|
||||||
def test_process_request_basic_auth_valid(context_factory, user_factory):
|
def test_process_request_basic_auth_valid(context_factory, user_factory):
|
||||||
user = user_factory()
|
user = user_factory()
|
||||||
ctx = context_factory(headers={
|
ctx = context_factory(
|
||||||
|
headers={
|
||||||
'Authorization': "Basic dGVzdFVzZXI6dGVzdFBhc3N3b3Jk"
|
'Authorization': "Basic dGVzdFVzZXI6dGVzdFBhc3N3b3Jk"
|
||||||
})
|
})
|
||||||
with patch('szurubooru.func.auth.is_valid_password'), \
|
with patch('szurubooru.func.auth.is_valid_password'), \
|
||||||
|
@ -27,7 +28,8 @@ def test_process_request_basic_auth_valid(context_factory, user_factory):
|
||||||
|
|
||||||
def test_process_request_token_auth_valid(context_factory, user_token_factory):
|
def test_process_request_token_auth_valid(context_factory, user_token_factory):
|
||||||
user_token = user_token_factory()
|
user_token = user_token_factory()
|
||||||
ctx = context_factory(headers={
|
ctx = context_factory(
|
||||||
|
headers={
|
||||||
'Authorization': "Token dGVzdFVzZXI6dGVzdFRva2Vu"
|
'Authorization': "Token dGVzdFVzZXI6dGVzdFRva2Vu"
|
||||||
})
|
})
|
||||||
with patch('szurubooru.func.auth.is_valid_token'), \
|
with patch('szurubooru.func.auth.is_valid_token'), \
|
||||||
|
@ -41,7 +43,8 @@ def test_process_request_token_auth_valid(context_factory, user_token_factory):
|
||||||
|
|
||||||
|
|
||||||
def test_process_request_bad_header(context_factory):
|
def test_process_request_bad_header(context_factory):
|
||||||
ctx = context_factory(headers={
|
ctx = context_factory(
|
||||||
|
headers={
|
||||||
'Authorization': "Secret SuperSecretValue"
|
'Authorization': "Secret SuperSecretValue"
|
||||||
})
|
})
|
||||||
with pytest.raises(errors.HttpBadRequest):
|
with pytest.raises(errors.HttpBadRequest):
|
||||||
|
|
Reference in a new issue