Skip to content

Commit

Permalink
Improve layer state mgmt
Browse files Browse the repository at this point in the history
  • Loading branch information
bkis committed Dec 7, 2023
1 parent 2dfd8c5 commit fd88cfb
Showing 16 changed files with 385 additions and 407 deletions.
176 changes: 96 additions & 80 deletions Tekst-API/openapi.json
Original file line number Diff line number Diff line change
@@ -573,42 +573,6 @@
"default": 4096,
"title": "Limit"
}
},
{
"name": "owners",
"in": "query",
"required": false,
"schema": {
"type": "boolean",
"description": "Include owners' user data, if any",
"default": false,
"title": "Owners"
},
"description": "Include owners' user data, if any"
},
{
"name": "writable",
"in": "query",
"required": false,
"schema": {
"type": "boolean",
"description": "Add flag indicating write permissions for requesting user",
"default": false,
"title": "Writable"
},
"description": "Add flag indicating write permissions for requesting user"
},
{
"name": "shares",
"in": "query",
"required": false,
"schema": {
"type": "boolean",
"description": "Include shared-with users' user data, if any",
"default": false,
"title": "Shares"
},
"description": "Include shared-with users' user data, if any"
}
],
"responses": {
@@ -773,42 +737,6 @@
"example": "5eb7cf5a86d9755df3a6c593",
"title": "Id"
}
},
{
"name": "owners",
"in": "query",
"required": false,
"schema": {
"type": "boolean",
"description": "Include owners' user data, if any",
"default": false,
"title": "Owners"
},
"description": "Include owners' user data, if any"
},
{
"name": "writable",
"in": "query",
"required": false,
"schema": {
"type": "boolean",
"description": "Add flag indicating write permissions for requesting user",
"default": false,
"title": "Writable"
},
"description": "Add flag indicating write permissions for requesting user"
},
{
"name": "shares",
"in": "query",
"required": false,
"schema": {
"type": "boolean",
"description": "Include shared-with users' user data, if any",
"default": false,
"title": "Shares"
},
"description": "Include shared-with users' user data, if any"
}
],
"responses": {
@@ -926,8 +854,30 @@
}
],
"responses": {
"204": {
"description": "Successful Response"
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/DebugLayerRead"
},
{
"$ref": "#/components/schemas/PlaintextLayerRead"
}
],
"discriminator": {
"propertyName": "layerType",
"mapping": {
"debug": "#/components/schemas/DebugLayerRead",
"plaintext": "#/components/schemas/PlaintextLayerRead"
}
},
"title": "Response Propose Layer Layers Id Propose Post"
}
}
}
},
"404": {
"description": "Not found"
@@ -973,8 +923,30 @@
}
],
"responses": {
"204": {
"description": "Successful Response"
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/DebugLayerRead"
},
{
"$ref": "#/components/schemas/PlaintextLayerRead"
}
],
"discriminator": {
"propertyName": "layerType",
"mapping": {
"debug": "#/components/schemas/DebugLayerRead",
"plaintext": "#/components/schemas/PlaintextLayerRead"
}
},
"title": "Response Unpropose Layer Layers Id Unpropose Post"
}
}
}
},
"404": {
"description": "Not found"
@@ -1020,8 +992,30 @@
}
],
"responses": {
"204": {
"description": "Successful Response"
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/DebugLayerRead"
},
{
"$ref": "#/components/schemas/PlaintextLayerRead"
}
],
"discriminator": {
"propertyName": "layerType",
"mapping": {
"debug": "#/components/schemas/DebugLayerRead",
"plaintext": "#/components/schemas/PlaintextLayerRead"
}
},
"title": "Response Publish Layer Layers Id Publish Post"
}
}
}
},
"404": {
"description": "Not found"
@@ -1067,8 +1061,30 @@
}
],
"responses": {
"204": {
"description": "Successful Response"
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/DebugLayerRead"
},
{
"$ref": "#/components/schemas/PlaintextLayerRead"
}
],
"discriminator": {
"propertyName": "layerType",
"mapping": {
"debug": "#/components/schemas/DebugLayerRead",
"plaintext": "#/components/schemas/PlaintextLayerRead"
}
},
"title": "Response Unpublish Layer Layers Id Unpublish Post"
}
}
}
},
"404": {
"description": "Not found"
10 changes: 5 additions & 5 deletions Tekst-API/tekst/models/layer.py
Original file line number Diff line number Diff line change
@@ -156,6 +156,11 @@ def restricted_fields(self, user: UserRead | None = None) -> set[str] | None:


class LayerBaseDocument(LayerBase, DocumentBase):
class Settings(DocumentBase.Settings):
name = "layers"
is_root = True
indexes = ["text_id", "level", "layer_type", "owner_id"]

@classmethod
async def allowed_to_read(cls, user: UserRead | None) -> dict:
if not user:
@@ -194,11 +199,6 @@ def allowed_to_write(cls, user: UserRead | None) -> dict:
LayerBaseDocument.shared_write == str(uid),
)

class Settings(DocumentBase.Settings):
name = "layers"
is_root = True
indexes = ["text_id", "level", "layer_type", "owner_id"]


class LayerReadExtras(ModelBase):
writable: Annotated[
Loading

0 comments on commit fd88cfb

Please sign in to comment.