Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✏️ Added role details to generated API spec #1021

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/code-ql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "CodeQL - Scanning"

on:
workflow_dispatch:
push:
branches:
- develop
- master
- release/**
pull_request:
branches:
- develop
- master
- release/**

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript', 'python' ] #java is throwing error on initialization, need more troubleshooting
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}


- name: Autobuild
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
19 changes: 8 additions & 11 deletions .github/workflows/forms-flow-api-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ jobs:
- uses: actions/checkout@v2
- run: "true"

linting:
Lint:
if: always()
needs: setup-job
runs-on: ubuntu-20.04

Expand All @@ -54,8 +55,10 @@ jobs:
run: |
flake8 src/formsflow_api tests

PyTest:
Test:
if: always()
needs: setup-job
name: Test
env:
FLASK_ENV: "testing"
DATABASE_URL_TEST: "postgresql://postgres:postgres@localhost:5432/postgres"
Expand Down Expand Up @@ -108,15 +111,9 @@ jobs:
id: test
run: |
make test
# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v1
# with:
# file: ./forms-flow-api/coverage.xml
# flags: formsflowapi
# name: codecov-formsflow-api
# fail_ci_if_error: true
build:
needs: PyTest
Build:
if: always()
needs: setup-job
runs-on: ubuntu-20.04
name: Build
steps:
Expand Down
26 changes: 9 additions & 17 deletions .github/workflows/forms-flow-bpm-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#Workflow name
name: Forms Flow BPM CI
on:
workflow_dispatch:
Expand Down Expand Up @@ -27,10 +26,11 @@ jobs:
steps:
- uses: actions/checkout@v2
- run: "true"
tests:
Test:
if: always()
needs: setup-job
runs-on: ubuntu-20.04
name: Unit tests
name: Test
steps:
- uses: actions/checkout@v2
- name: Set up JDK
Expand All @@ -45,21 +45,13 @@ jobs:
restore-keys: ${{ runner.os }}-m2
- name: Run Tests
run: mvn -B test --file pom.xml
build:
needs: tests
Build:
if: always()
needs: setup-job
runs-on: ubuntu-20.04
name: Build
steps:
- uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: '17'
- name: Cache Maven packages
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build with Maven
run: mvn -B package -DskipTests --file pom.xml
- name: Build
run: |
docker build . -t forms-flow-bpm
8 changes: 5 additions & 3 deletions .github/workflows/forms-flow-data-analysis-api-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v2
- run: "true"

linting:
Lint:
needs: setup-job
runs-on: ubuntu-20.04

Expand All @@ -45,7 +45,8 @@ jobs:
run: |
pylint --rcfile=setup.cfg src/api

PyTest:
Test:
if: always()
needs: setup-job
env:
FLASK_ENV: "testing"
Expand Down Expand Up @@ -101,7 +102,8 @@ jobs:
run: |
make test

build:
Build:
if: always()
runs-on: ubuntu-20.04
name: Build
steps:
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/forms-flow-documents-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- uses: actions/checkout@v2
- run: "true"

linting:
Lint:
needs: setup-job
runs-on: ubuntu-20.04

Expand All @@ -54,7 +54,7 @@ jobs:
run: |
flake8 src/formsflow_documents tests

PyTest:
Test:
needs: setup-job
env:
FLASK_ENV: "testing"
Expand Down Expand Up @@ -103,7 +103,8 @@ jobs:
id: test
run: |
make test
build:
Build:
if: always()
runs-on: ubuntu-20.04
name: Build
steps:
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/forms-flow-web-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- uses: actions/checkout@v2
- run: "true"

linting:
Lint:
needs: setup-job
runs-on: ubuntu-20.04

Expand All @@ -48,7 +48,8 @@ jobs:
- name: Linting
run: |
npm run lint
unit-tests:
Test:
if: Always()
needs: setup-job
runs-on: ubuntu-20.04

Expand All @@ -70,7 +71,8 @@ jobs:
run: |
npm test a

build-check:
Build:
if: always()
needs: setup-job
runs-on: ubuntu-20.04

Expand Down
4 changes: 2 additions & 2 deletions forms-flow-api-utils/src/formsflow_api_utils/utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def translate(to_lang: str, data: dict) -> dict:

def get_role_ids_from_user_groups(role_ids, user_role):
"""Filters out formio role ids specific to user groups."""
if user_role is None or user_role is None:
raise ValueError("Inavlid arguments passed")
if role_ids is None or user_role is None:
return None

if DESIGNER_GROUP in user_role:
return role_ids
Expand Down
4 changes: 4 additions & 0 deletions forms-flow-api/src/formsflow_api/models/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class Application(
submission_id = db.Column(db.String(100), nullable=True)
latest_form_id = db.Column(db.String(100), nullable=False)

draft = db.relationship(
"Draft", backref=db.backref("Application", cascade="save-update, merge, delete")
)

@classmethod
def create_from_dict(cls, application_info: dict) -> Application:
"""Create new application."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from http import HTTPStatus

from flask import current_app, request
from flask_restx import Namespace, Resource
from flask_restx import Namespace, Resource, fields
from formsflow_api_utils.utils import (
ANONYMOUS_USER,
cors_preflight,
Expand All @@ -16,6 +16,35 @@

API = Namespace("Public", description="Public api endpoints")

application_create_model = API.model(
"AnonymousApplicationCreate",
{
"formId": fields.String(),
"submissionId": fields.String(),
"formUrl": fields.String(),
},
)

application_base_model = API.model(
"AnonymousApplicationCreateResponse",
{
"applicationStatus": fields.String(),
"created": fields.String(),
"createdBy": fields.String(),
"formId": fields.String(),
"formProcessMapperId": fields.String(),
"id": fields.Integer(),
"modified": fields.String(),
"modifiedBy": fields.String(),
"processInstanceId": fields.String(),
"submissionId": fields.String(),
},
)

check_response = API.model(
"CheckStatus", {"is_anonymous": fields.Boolean(), "status": fields.String()}
)


@cors_preflight("POST,OPTIONS")
@API.route("/application/create", methods=["POST", "OPTIONS"])
Expand All @@ -24,13 +53,14 @@ class ApplicationAnonymousResourcesByIds(Resource):

@staticmethod
@profiletime
@API.doc(body=application_create_model)
@API.response(201, "CREATED:- Successful request.", model=application_base_model)
@API.response(
400,
"BAD_REQUEST:- Invalid request.",
)
def post():
"""Post a new anonymous application using the request body.

: formId:- Unique Id for the corresponding form
: submissionId:- Unique Id for the submitted form
: formUrl:- Unique URL for the submitted application
"""
"""Post a new anonymous application using the request body."""
application_json = request.get_json()
try:
application_schema = ApplicationSchema()
Expand Down Expand Up @@ -68,12 +98,13 @@ class AnonymousResourceById(Resource):

@staticmethod
@profiletime
@API.response(200, "OK:- Successful request.", model=check_response)
@API.response(
400,
"BAD_REQUEST:- Invalid request.",
)
def get(form_id: str):
"""Get form by form id and return is_anonymous and published status.

: formId:- Unique Id for the corresponding form
: response: is_anonymous, status(published or not)
"""
"""Get form by form id and return is_anonymous and published status."""
try:
mapper = FormProcessMapper.find_form_by_form_id(form_id)
response, status = {
Expand Down