-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2212 from auslin-aot/feature/FWF-3490-import-supp…
…ort-webapi FWF-3490: [Featue] Import support webapi
- Loading branch information
Showing
19 changed files
with
646 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
forms-flow-api/migrations/versions/b0ecd447cfa5_added_version_to_process_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Added version to process data | ||
Revision ID: b0ecd447cfa5 | ||
Revises: e1d88d2efbcb | ||
Create Date: 2024-08-22 12:04:13.443862 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'b0ecd447cfa5' | ||
down_revision = 'e1d88d2efbcb' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('process', sa.Column('major_version', sa.Integer(), nullable=False)) | ||
op.add_column('process', sa.Column('minor_version', sa.Integer(), nullable=False)) | ||
op.alter_column('process', 'process_data', | ||
existing_type=sa.VARCHAR(), | ||
type_=sa.LargeBinary(), | ||
existing_nullable=False, | ||
postgresql_using="process_data::bytea") | ||
op.create_index(op.f('ix_process_major_version'), 'process', ['major_version'], unique=False) | ||
op.create_index(op.f('ix_process_minor_version'), 'process', ['minor_version'], unique=False) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index(op.f('ix_process_minor_version'), table_name='process') | ||
op.drop_index(op.f('ix_process_major_version'), table_name='process') | ||
op.alter_column('process', 'process_data', | ||
existing_type=sa.LargeBinary(), | ||
type_=sa.VARCHAR(), | ||
existing_nullable=False, | ||
postgresql_using="process_data::bytea") | ||
op.drop_column('process', 'minor_version') | ||
op.drop_column('process', 'major_version') | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,3 +68,4 @@ typing_extensions==4.10.0 | |
urllib3==2.2.1 | ||
wsproto==1.2.0 | ||
zstandard==0.22.0 | ||
lxml==5.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
forms-flow-api/src/formsflow_api/resources/import_support.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""API endpoints for managing import.""" | ||
|
||
from http import HTTPStatus | ||
|
||
from flask import request | ||
from flask_restx import Namespace, Resource | ||
from formsflow_api_utils.utils import ( | ||
CREATE_DESIGNS, | ||
auth, | ||
cors_preflight, | ||
profiletime, | ||
) | ||
|
||
from formsflow_api.services import ImportService | ||
|
||
API = Namespace("Import", description="Import") | ||
|
||
|
||
@cors_preflight("POST,OPTIONS") | ||
@API.route("", methods=["POST", "OPTIONS"]) | ||
class Import(Resource): | ||
"""Resource to support import.""" | ||
|
||
@staticmethod | ||
@auth.has_one_of_roles([CREATE_DESIGNS]) | ||
@profiletime | ||
@API.response(200, "OK:- Successful request.") | ||
@API.response( | ||
400, | ||
"BAD_REQUEST:- Invalid request.", | ||
) | ||
@API.response( | ||
401, | ||
"UNAUTHORIZED:- Authorization header not provided or an invalid token passed.", | ||
) | ||
@API.response( | ||
403, | ||
"FORBIDDEN:- Authorization will not help.", | ||
) | ||
def post(): | ||
"""Import.""" | ||
import_service = ImportService() | ||
return ( | ||
import_service.import_form_workflow(request), | ||
HTTPStatus.OK, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
forms-flow-api/src/formsflow_api/schemas/import_support.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
"""This manages Import Schema.""" | ||
|
||
from marshmallow import EXCLUDE, Schema, fields | ||
|
||
form_workflow_schema = { | ||
"title": "Form Workflow Schema", | ||
"type": "object", | ||
"properties": { | ||
"forms": { | ||
"type": "array", | ||
"properties": { | ||
"formTitle": {"type": "string"}, | ||
"formDescription": {"type": "string"}, | ||
"anonymous": {"type": "boolean"}, | ||
"type": {"type": "string"}, | ||
"content": {"type": "object"}, | ||
}, | ||
"required": [ | ||
"formTitle", | ||
"formDescription", | ||
"content", | ||
"anonymous", | ||
"type", | ||
], | ||
}, | ||
"workflows": { | ||
"type": "array", | ||
"properties": { | ||
"processKey": {"type": "string"}, | ||
"processName": {"type": "string"}, | ||
"type": {"type": "string"}, | ||
"content": {"type": "string"}, | ||
}, | ||
"required": ["content", "processKey", "processName", "type"], | ||
}, | ||
"authorizations": { | ||
"type": "array", | ||
"properties": { | ||
"APPLICATION": { | ||
"type": "array", | ||
"properties": { | ||
"resourceId": {"type": "string"}, | ||
"resourceDetails": {"type": "object"}, | ||
"roles": {"type": "array"}, | ||
"userName": {"type": "string"}, | ||
}, | ||
"required": ["resourceId", "resourceDetails", "roles", "userName"], | ||
}, | ||
"FORM": { | ||
"type": "array", | ||
"properties": { | ||
"resourceId": {"type": "string"}, | ||
"resourceDetails": {"type": "object"}, | ||
"roles": {"type": "array"}, | ||
"userName": {"type": "string"}, | ||
}, | ||
"required": ["resourceId", "resourceDetails", "roles", "userName"], | ||
}, | ||
"DESIGNER": { | ||
"type": "array", | ||
"properties": { | ||
"resourceId": {"type": "string"}, | ||
"resourceDetails": {"type": "object"}, | ||
"roles": {"type": "array"}, | ||
"userName": {"type": "string"}, | ||
}, | ||
"required": ["resourceId", "resourceDetails", "roles", "userName"], | ||
}, | ||
}, | ||
"required": ["APPLICATION", "FORM", "DESIGNER"], | ||
}, | ||
}, | ||
"required": ["forms", "workflows", "rules", "authorizations"], | ||
} | ||
|
||
form_schema = { | ||
"title": "Form Schema", | ||
"type": "object", | ||
"properties": { | ||
"forms": { | ||
"type": "array", | ||
"properties": { | ||
"title": {"type": "string"}, | ||
"name": {"type": "string"}, | ||
"path": {"type": "boolean"}, | ||
"type": {"type": "string"}, | ||
"components": {"type": "array"}, | ||
}, | ||
"required": ["title", "name", "path", "type", "components"], | ||
} | ||
}, | ||
"additionalProperties": False, | ||
} | ||
|
||
|
||
class ImportRequestSchema(Schema): | ||
"""This class manages import request schema.""" | ||
|
||
class Meta: # pylint: disable=too-few-public-methods | ||
"""Exclude unknown fields in the deserialized output.""" | ||
|
||
unknown = EXCLUDE | ||
|
||
import_type = fields.Str(data_key="importType", required=True) | ||
action = fields.Str(data_key="action", required=True) | ||
|
||
|
||
class ImportEditRequestSchema(Schema): | ||
"""This class manages import edit request schema.""" | ||
|
||
class Meta: # pylint: disable=too-few-public-methods | ||
"""Exclude unknown fields in the deserialized output.""" | ||
|
||
unknown = EXCLUDE | ||
|
||
mapper_id = fields.Str(data_key="mapperId", required=True) | ||
forms = fields.Dict(data_key="forms") | ||
workflows = fields.Dict(data_key="workflows") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.