Skip to content

Commit ac71b21

Browse files
JWittmeyerSirDegraflumburovskalinadependabot[bot]FelixKirschKern
authored
release v1.1.0 (#28)
* Update LICENSE * Adds is_demo to mutations * Adds demo check for more endpoints * Adds demo check for project and upload task * Small adjustments and removes check for demo for create orga * Adding admin rights for demo version * Splits app.py into modularized files * submodule update * Adds PR changes to work with frontend * Renames folder handler to middleware * Submodule update * Adds restricted endpoint query * Demo check for rest apis * Adds blacklist of restricted endpoints * Adds and slightly changes endpoint * Removes endpoint notify check for demo * Changes function name & removes endpoint * Init sample project state added * Enum pass without value * Updates submodule * Adds import of exported file for knowledge terms If a file gets imported (for knowledge terms) first the app will try to read it in the strucutre of exported lists. If the imported file don't have a fitting structure it gets canceled and the original import flow will continue * Adds typing * Adds yml file * Add dependabot yml (#20) * Adds small change * Adds small change * Bump pyjwt from 2.1.0 to 2.4.0 (#22) Bumps [pyjwt](https://github.com/jpadilla/pyjwt) from 2.1.0 to 2.4.0. - [Release notes](https://github.com/jpadilla/pyjwt/releases) - [Changelog](https://github.com/jpadilla/pyjwt/blob/master/CHANGELOG.rst) - [Commits](jpadilla/pyjwt@2.1.0...2.4.0) --- updated-dependencies: - dependency-name: pyjwt dependency-type: direct:production ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fixes #10, adds arm tags to exec envs * Extend comment * adds EMBEDDING_CREATION_WARNING to notification data (#24) * Dependabot pip numpy 1.22.0 (#21) * Bump numpy from 1.21.0 to 1.22.0 Bumps [numpy](https://github.com/numpy/numpy) from 1.21.0 to 1.22.0. - [Release notes](https://github.com/numpy/numpy/releases) - [Changelog](https://github.com/numpy/numpy/blob/main/doc/RELEASE_WALKTHROUGH.rst) - [Commits](numpy/numpy@v1.21.0...v1.22.0) --- updated-dependencies: - dependency-name: numpy dependency-type: direct:production ... Signed-off-by: dependabot[bot] <[email protected]> * bump further to 1.23.1 * Changes python version to match numpy version * Changes python version in dockerfile Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Adds qutation escaping (#25) * Adds qutation escaping * remove pass * Update service/search/search.py Co-authored-by: Felix Kirsch <[email protected]> * change to union type Co-authored-by: Felix Kirsch <[email protected]> * Adds hotfix (#26) * Adds hotfix * changes spacy version for drone * remove specific path * Removes project export from demo (#27) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: simonrempel <[email protected]> Co-authored-by: Simon Degraf <[email protected]> Co-authored-by: Lina <[email protected]> Co-authored-by: lumburovskalina <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: felix0496 <[email protected]> Co-authored-by: Felix Kirsch <[email protected]>
1 parent 346fcca commit ac71b21

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+634
-258
lines changed

.drone.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ steps:
7878
trigger:
7979
branch:
8080
- dev
81-
- beta-v2
8281
event:
8382
- push
8483

.github/dependabot.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: 2
2+
updates:
3+
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#package-ecosystem
4+
- package-ecosystem: "pip"
5+
directory: "/"
6+
schedule:
7+
interval: "daily"
8+
# default is / which breaks drone
9+
pull-request-branch-name:
10+
separator: "-"
11+
# not created automatically for version updates so only security ones are created
12+
# https://docs.github.com/en/code-security/dependabot/dependabot-security-updates/configuring-dependabot-security-updates#overriding-the-default-behavior-with-a-configuration-file
13+
open-pull-requests-limit: 0
14+

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.7
1+
FROM python:3.9
22

33
WORKDIR /app
44

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright 2022 onetask.ai GmbH
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

api/__init__.py

Whitespace-only changes.

api/project.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import logging
2+
from starlette.endpoints import HTTPEndpoint
3+
from starlette.responses import JSONResponse
4+
5+
from controller.auth import manager as auth_manager
6+
from controller.project import manager as project_manager
7+
from controller.attribute import manager as attribute_manager
8+
9+
10+
logging.basicConfig(level=logging.DEBUG)
11+
12+
13+
class ProjectDetails(HTTPEndpoint):
14+
def get(self, request) -> JSONResponse:
15+
project_id = request.path_params["project_id"]
16+
user_id = request.query_params["user_id"]
17+
auth_manager.check_project_access_from_user_id(user_id, project_id)
18+
project = project_manager.get_project(project_id)
19+
attributes = attribute_manager.get_all_attributes(project_id)
20+
result = {
21+
"name": project.name,
22+
"description": project.description,
23+
"tokenizer": project.tokenizer,
24+
"attributes": [
25+
{
26+
"name": attribute.name,
27+
"data_type": attribute.data_type,
28+
"is_primary_key": attribute.is_primary_key,
29+
}
30+
for attribute in attributes
31+
],
32+
"knowledge_base_ids": [str(list.id) for list in project.knowledge_bases],
33+
}
34+
return JSONResponse(result)

api/transfer.py

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import logging
2+
import traceback
3+
4+
from controller import organization
5+
from starlette.endpoints import HTTPEndpoint
6+
from starlette.responses import PlainTextResponse, JSONResponse
7+
from submodules.s3 import controller as s3
8+
from submodules.model.business_objects import organization
9+
10+
from controller.transfer import manager as upload_manager
11+
from controller.upload_task import manager as task_manager
12+
from controller.auth import manager as auth_manager
13+
from controller.transfer import manager as transfer_manager
14+
from controller.auth import manager as auth
15+
16+
from submodules.model import enums
17+
from util.notification import create_notification
18+
from submodules.model.enums import NotificationType
19+
from submodules.model.models import UploadTask
20+
from submodules.model.business_objects import general
21+
from util import notification
22+
from controller.tokenization import tokenization_service
23+
24+
logging.basicConfig(level=logging.DEBUG)
25+
logger = logging.getLogger(__name__)
26+
27+
28+
class Notify(HTTPEndpoint):
29+
async def post(self, request) -> PlainTextResponse:
30+
data = await request.json()
31+
file_path = data["Key"]
32+
33+
if len(file_path.split("/")) != 4:
34+
# We need handling for lf execution notification here.
35+
# ATM we have a different path of handling in util/payload_scheduler.py update_records method
36+
return PlainTextResponse("OK")
37+
38+
org_id, project_id, upload_task_id, file_name = file_path.split("/")
39+
if len(project_id) != 36:
40+
return PlainTextResponse("OK")
41+
if upload_task_id == "download":
42+
return PlainTextResponse("OK")
43+
if org_id == "archive":
44+
return PlainTextResponse("OK")
45+
46+
task = task_manager.get_upload_task_secure(
47+
upload_task_id=upload_task_id,
48+
project_id=project_id,
49+
file_name=file_name,
50+
)
51+
is_global_update = True if task.file_type == "project" else False
52+
try:
53+
init_file_import(task, project_id, is_global_update)
54+
except Exception:
55+
file_import_error_handling(task, project_id, is_global_update)
56+
notification.send_organization_update(project_id, "project_update", True)
57+
return PlainTextResponse("OK")
58+
59+
60+
class FileExport(HTTPEndpoint):
61+
def get(self, request) -> JSONResponse:
62+
project_id = request.path_params["project_id"]
63+
user_id = request.query_params["user_id"]
64+
num_samples = request.query_params.get("num_samples")
65+
auth_manager.check_project_access_from_user_id(user_id, project_id)
66+
result = transfer_manager.export_records(project_id, num_samples)
67+
return JSONResponse(result)
68+
69+
70+
class KnowledgeBaseExport(HTTPEndpoint):
71+
def get(self, request) -> JSONResponse:
72+
project_id = request.path_params["project_id"]
73+
list_id = request.path_params["knowledge_base_id"]
74+
user_id = request.query_params["user_id"]
75+
auth_manager.check_project_access_from_user_id(user_id, project_id)
76+
result = transfer_manager.export_knowledge_base(project_id, list_id)
77+
return JSONResponse(result)
78+
79+
80+
class PrepareImport(HTTPEndpoint):
81+
async def post(self, request) -> JSONResponse:
82+
auth.check_is_demo_without_info()
83+
project_id = request.path_params["project_id"]
84+
request_body = await request.json()
85+
86+
user_id = request_body["user_id"]
87+
auth_manager.check_project_access_from_user_id(user_id, project_id)
88+
file_name = request_body["file_name"]
89+
file_type = request_body["file_type"]
90+
file_import_options = request_body.get("file_import_options")
91+
task = task_manager.create_upload_task(
92+
user_id, project_id, file_name, file_type, file_import_options
93+
)
94+
org_id = organization.get_id_by_project_id(project_id)
95+
credentials_and_id = s3.get_upload_credentials_and_id(
96+
org_id, f"{project_id}/{task.id}"
97+
)
98+
return JSONResponse(credentials_and_id)
99+
100+
101+
class UploadTask(HTTPEndpoint):
102+
def get(self, request) -> JSONResponse:
103+
auth.check_is_demo_without_info()
104+
project_id = request.path_params["project_id"]
105+
task_id = request.path_params["task_id"]
106+
user_id = request.query_params["user_id"]
107+
auth_manager.check_project_access_from_user_id(user_id, project_id)
108+
task = task_manager.get_upload_task(project_id, task_id)
109+
task_dict = {
110+
"id": str(task.id),
111+
"file_name": str(task.file_name),
112+
"file_type": str(task.file_type),
113+
"progress": task.progress,
114+
"state": str(task.state),
115+
"started_at": str(task.started_at),
116+
}
117+
return JSONResponse(task_dict)
118+
119+
120+
def init_file_import(task: UploadTask, project_id: str, is_global_update: bool) -> None:
121+
if "records" in task.file_type:
122+
upload_manager.import_records(project_id, task)
123+
elif "project" in task.file_type:
124+
upload_manager.import_project(project_id, task)
125+
elif "knowledge_base" in task.file_type:
126+
upload_manager.import_knowledge_base(project_id, task)
127+
128+
notification.send_organization_update(
129+
project_id, f"file_upload:{str(task.id)}:state:{task.state}", is_global_update
130+
)
131+
if task.file_type != "knowledge_base":
132+
tokenization_service.request_tokenize_project(project_id, str(task.user_id))
133+
134+
135+
def file_import_error_handling(
136+
task: UploadTask, project_id: str, is_global_update: bool
137+
) -> None:
138+
general.rollback()
139+
task.state = enums.UploadStates.ERROR.value
140+
general.commit()
141+
create_notification(
142+
NotificationType.IMPORT_FAILED,
143+
task.user_id,
144+
task.project_id,
145+
task.file_type,
146+
)
147+
logger.error(
148+
task_manager.get_upload_task_message(
149+
task,
150+
)
151+
)
152+
print(traceback.format_exc(), flush=True)
153+
notification.send_organization_update(
154+
project_id, f"file_upload:{str(task.id)}:state:{task.state}", is_global_update
155+
)

0 commit comments

Comments
 (0)