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 templates for openinfo publishing cronjobs #1241

Closed
wants to merge 9 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions .github/workflows/openinfoservice-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: OpenInfo Service CD


on:
push:
branches:
- dev
- main
- dev-marshal
- test-marshal
- dev-rook
- test-rook
paths:
- "computingservices/OpenInfoServices/**"
- ".github/workflows/openinfoservice-cd.yml"

defaults:
run:
shell: bash
working-directory: ./computingservices/OpenInfoServices

env:
APP_NAME: "reviewer-openinfoservice"
TOOLS_NAME: "${{secrets.OPENSHIFT4_REPOSITORY}}"

jobs:
openinfoservice-cd-by-push:
runs-on: ubuntu-20.04

if: github.event_name == 'push' && github.repository == 'bcgov/foi-docreviewer'
steps:
- uses: actions/checkout@v2
- name: Set ENV variables for dev branch
if: ${{ github.ref_name == 'dev' }}
shell: bash
run: |
echo "For ${{ github.ref_name }} branch"
echo "TAG_NAME=dev" >> $GITHUB_ENV
echo "BRANCH_NAME=dev" >> $GITHUB_ENV
echo "ENV_NAME=dev" >> $GITHUB_ENV

- name: Set ENV variables for main branch
if: ${{ github.ref_name == 'main' }}
shell: bash
run: |
echo "For ${{ github.ref_name }} branch"
echo "TAG_NAME=test" >> $GITHUB_ENV
echo "BRANCH_NAME=main" >> $GITHUB_ENV
echo "ENV_NAME=test" >> $GITHUB_ENV

- name: Set ENV variables for dev-marshal branch
if: ${{ github.ref_name == 'dev-marshal' }}
run: |
echo "For ${{ github.ref_name }} branch"
echo "TAG_NAME=dev-marshal" >> $GITHUB_ENV
echo "BRANCH_NAME=dev-marshal" >> $GITHUB_ENV
echo "ENV_NAME=dev" >> $GITHUB_ENV

- name: Set ENV variables for test-marshal branch
if: ${{ github.ref_name == 'test-marshal' }}
run: |
echo "For ${{ github.ref_name }} branch"
echo "TAG_NAME=test-marshal" >> $GITHUB_ENV
echo "BRANCH_NAME=test-marshal" >> $GITHUB_ENV
echo "ENV_NAME=test" >> $GITHUB_ENV

- name: Set ENV variables for dev-rook branch
if: ${{ github.ref_name == 'dev-rook' }}
run: |
echo "For ${{ github.ref_name }} branch"
echo "TAG_NAME=dev-rook" >> $GITHUB_ENV
echo "BRANCH_NAME=dev-rook" >> $GITHUB_ENV
echo "ENV_NAME=dev" >> $GITHUB_ENV
echo "ENV_TAG_NAME=rook" >> $GITHUB_ENV

- name: Set ENV variables for test-rook branch
if: ${{ github.ref_name == 'test-rook' }}
run: |
echo "For ${{ github.ref_name }} branch"
echo "TAG_NAME=test-rook" >> $GITHUB_ENV
echo "BRANCH_NAME=test-rook" >> $GITHUB_ENV
echo "ENV_NAME=test" >> $GITHUB_ENV
echo "ENV_TAG_NAME=rook" >> $GITHUB_ENV

- name: Login Openshift
shell: bash
run: |
oc login --server=${{secrets.OPENSHIFT4_LOGIN_REGISTRY}} --token=${{secrets.OPENSHIFT4_SA_TOKEN}}

- name: Tools project
shell: bash
run: |
oc project ${{ env.TOOLS_NAME }}-tools

- name: Build from ${{ env.BRANCH_NAME }} branch
shell: bash
run: |
oc patch bc/${{ env.APP_NAME }}-build -p '{"spec":{"source":{"contextDir":"/computingservices/OpenInfoServices","git":{"ref":"${{ env.BRANCH_NAME }}"}}}}'

- name: Start Build Openshift
shell: bash
run: |
oc start-build ${{ env.APP_NAME }}-build --wait

- name: Tag+Deploy for ${{ env.TAG_NAME }}
shell: bash
run: |
oc tag ${{ env.APP_NAME }}:latest ${{ env.APP_NAME }}:${{ env.TAG_NAME }}

# - name: Watch new rollout (trigger by image change in Openshift)
# shell: bash
# run: |
# oc rollout status dc/${{ env.APP_NAME }}-{{ env.ENV_TAG_NAME }} -n ${{ env.TOOLS_NAME }}-${{ env.ENV_NAME }} -w
46 changes: 46 additions & 0 deletions .github/workflows/openinfoservice-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Open Info Service CI


on:
pull_request:
branches:
- main
- dev
- dev-marshal
- test-marshal
- dev-rook
- test-rook
paths:
- "computingservices/OpenInfoServices/**"

defaults:
run:
shell: bash
working-directory: ./computingservices/OpenInfoServices

jobs:
docker-build-check:
runs-on: ubuntu-latest
name: Build dockerfile to ensure it works

steps:
- uses: actions/checkout@v2
- name: docker build to check strictness
id: docker-build
run: |
docker build -f Dockerfile.local .

go-build-check:
runs-on: ubuntu-latest
name: Build go to ensure it works

steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'
- name: Build the application
run: go build -v .
- name: Test the application
run: go test ./...
26 changes: 26 additions & 0 deletions api/migrations/versions/6e91c6b84964_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""empty message

Revision ID: 6e91c6b84964
Revises: 18a45d1b33cc
Create Date: 2024-10-18 11:25:57.222327

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '6e91c6b84964'
down_revision = '9d45ce57481e'
branch_labels = None
depends_on = None


def upgrade():

op.execute('INSERT INTO public."RedactionLayers"(name, description, sortorder, isactive, createdby, created_at) VALUES (\'Open Info\', \'Open Info\', 4, True, \'System\', now());commit;')

def downgrade():

op.execute('delete from public."RedactionLayers" WHERE name in (\'Open Info\');commit;')
# ### end Alembic commands ###
69 changes: 69 additions & 0 deletions api/migrations/versions/81eb14daaace_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""empty message

Revision ID: 81eb14daaace
Revises: 6e91c6b84964
Create Date: 2024-10-28 09:07:42.841630

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
from sqlalchemy.sql import column, table
from sqlalchemy.sql.sqltypes import Boolean, String, Integer
from sqlalchemy.sql import func


# revision identifiers, used by Alembic.
revision = '81eb14daaace'
down_revision = '6e91c6b84964'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('OIRedactionCodes',
sa.Column('redactioncodeid', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('redactioncode', sa.String(length=100), nullable=False),
sa.Column('description', sa.String(length=1000), nullable=True),
sa.Column('sortorder', sa.Integer(), nullable=True),
sa.Column('isactive', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=True,server_default=func.now()),
sa.Column('createdby', sa.String(length=120), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('updatedby', sa.String(length=120), nullable=True),
sa.PrimaryKeyConstraint('redactioncodeid')
)
redactioncode_table = table('OIRedactionCodes',
column('redactioncode',String),
column('description',String),
column('isactive',Boolean),
column('createdby',String),
column('sortorder',Integer),
)
op.bulk_insert(
redactioncode_table,
[
{"redactioncode":"Copyright Information","description":"Copyright Information","isactive":True, "createdby": "System","sortorder":1},
{"redactioncode":"Cabinet Confidences","description":"Cabinet Confidences","isactive":True, "createdby": "System","sortorder":2},
{"redactioncode":"Advice/Recommendations","description":"Advice/Recommendations","isactive":True, "createdby": "System","sortorder":3},
{"redactioncode":"Legal Information","description":"Legal Information","isactive":True, "createdby": "System","sortorder":4},
{"redactioncode":"Security Concern","description":"Security Concern","isactive":True, "createdby": "System","sortorder":5},
{"redactioncode":"Intergovernmental Communications","description":"Intergovernmental Communications","isactive":True, "createdby": "System","sortorder":6},
{"redactioncode":"Interests of an Indigenous People","description":"Interests of an Indigenous People","isactive":True, "createdby": "System","sortorder":7},
{"redactioncode":"Government Financial Information","description":"Government Financial Information","isactive":True, "createdby": "System","sortorder":8},
{"redactioncode":"Conservation of Heritage Sites","description":"Conservation of Heritage Sites","isactive":True, "createdby": "System","sortorder":9},
{"redactioncode":"Personal Security","description":"Personal Security","isactive":True, "createdby": "System","sortorder":10},
{"redactioncode":"Business Information","description":"Business Information","isactive":True, "createdby": "System","sortorder":11},
{"redactioncode":"Personal Information","description":"Personal Information","isactive":True, "createdby": "System","sortorder":12},
{"redactioncode":"Court Records","description":"Court Records","isactive":True, "createdby": "System","sortorder":13},
{"redactioncode":"Application","description":"Application","isactive":True, "createdby": "System","sortorder":14},
]
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('OIRedactionCodes')
# ### end Alembic commands ###
32 changes: 32 additions & 0 deletions api/reviewer_api/models/OIRedactionCodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from .db import db, ma
from .default_method_result import DefaultMethodResult
from datetime import datetime as datetime2
import logging

class OIRedactionCodes(db.Model):
__tablename__ = 'OIRedactionCodes'
# Defining the columns
redactioncodeid = db.Column(db.Integer, primary_key=True,autoincrement=True)
redactioncode = db.Column(db.String(255), unique=False, nullable=False)
description = db.Column(db.String(255), unique=False, nullable=False)
sortorder = db.Column(db.String(100), unique=False, nullable=True)
isactive = db.Column(db.Boolean, unique=False, nullable=False)
createdby = db.Column(db.String(120), unique=False, nullable=True)
created_at = db.Column(db.DateTime, default=datetime2.now)
updatedby = db.Column(db.String(120), unique=False, nullable=True)
updated_at = db.Column(db.DateTime, nullable=True)

@classmethod
def getall(cls):
try:
oiredactioncode_schema = OIRedactionCodeSchema(many=True)
query = db.session.query(OIRedactionCodes).filter_by(isactive=True).order_by(OIRedactionCodes.sortorder.asc()).all()
return oiredactioncode_schema.dump(query)
except Exception as ex:
logging.error(ex)
finally:
db.session.close()

class OIRedactionCodeSchema(ma.Schema):
class Meta:
fields = ('redactioncodeid', 'redactioncode', 'description','sortorder')
17 changes: 17 additions & 0 deletions api/reviewer_api/models/RedactionLayers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ def getredlineredactionlayer(cls):
finally:
db.session.close()


@classmethod
def getredactionlayerbyid(cls,layerid):
try:
layer_schema = RedactionLayerSchema(many=False)
query = (
db.session.query(RedactionLayer)
.filter_by(isactive=True, redactionlayerid=layerid)
.order_by(RedactionLayer.sortorder.desc())
.first()
)
return layer_schema.dump(query)
except Exception as ex:
logging.error(ex)
finally:
db.session.close()

@classmethod
def getlayers(cls):
try:
Expand Down
3 changes: 2 additions & 1 deletion api/reviewer_api/resources/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ def get(requestid):
"requesttype": jsonobj["requestType"],
"validoipcreviewlayer": documentservice().validate_oipcreviewlayer(jsonobj, requestid),
"outstandingbalance": outstandingbalance,
"balancefeeoverrodforrequest": balancefeeoverrodforrequest
"balancefeeoverrodforrequest": balancefeeoverrodforrequest,
"requeststate":jsonobj["currentState"]
}
documentdivisionslist,result = documentservice().getdocuments(requestid, requestinfo["bcgovcode"])
return json.dumps({"requeststatuslabel": jsonobj["requeststatuslabel"], "documents": result, "requestnumber":jsonobj["axisRequestId"], "requestinfo":requestinfo, "documentdivisions":documentdivisionslist}), 200
Expand Down
8 changes: 4 additions & 4 deletions api/reviewer_api/resources/foiflowmasterdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,14 @@ def post(ministryrequestid, redactionlayer="redline", layertype="redline"):


@cors_preflight("POST,OPTIONS")
@API.route("/foiflow/oss/presigned/responsepackage/<int:ministryrequestid>")
@API.route("/foiflow/oss/presigned/<int:ministryrequestid>/<redactionlayer>")
class FOIFlowS3PresignedResponsePackage(Resource):
@staticmethod
@TRACER.trace()
@cross_origin(origins=allowedorigins())
@auth.require
@auth.ismemberofgroups(getrequiredmemberships())
def post(ministryrequestid):
def post(ministryrequestid, redactionlayer="responsepackage"):
try:
data = request.get_json()
documentmapper = redactionservice().getdocumentmapper(
Expand All @@ -356,8 +356,8 @@ def post(ministryrequestid):
# generate save url for stitched file
filepathlist = data["filepath"].split("/")[4:]
filename = filepathlist[0]
filepath_put = "{0}/responsepackage/{1}.pdf".format(
filepathlist[0], filename
filepath_put = "{0}/{2}/{1}.pdf".format(
filepathlist[0], filename, redactionlayer
)

# filename_put, file_extension_put = os.path.splitext(filepath_put)
Expand Down
1 change: 0 additions & 1 deletion api/reviewer_api/schemas/finalpackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class FinalPackageSchema(Schema):
)
summarydocuments = fields.Nested(SummarySchema, allow_none=True)
redactionlayerid = fields.Int(data_key="redactionlayerid", allow_none=False)
pdfstitchjobattributes = fields.Nested(FeeOverrideSchema, allow_none=True, many=False)
requesttype = fields.Str(data_key="requesttype", allow_none=False)
pdfstitchjobattributes = fields.Nested(FeeOverrideSchema, allow_none=True, many=False)

Expand Down
Loading
Loading