Skip to content

Commit

Permalink
Emergency Release 1.59.1 (#2258)
Browse files Browse the repository at this point in the history
* add emergency release-1.59.1

* add pull_request events

* Update package.json

* Transfer fix (#2244)

* fix: removes unecessary data from transfer

* fix: new user serializer passes only basic user info to frontend
-get history modified so that approved and disapproved statuses created by government are  excluded so that communications/status changes within government are not shown in network tab

* removes id from user basic serializer

* more fixes

* small change + tests

* Update version to be 1.59.1 in package.json

---------

Co-authored-by: emi-hi <[email protected]>
Co-authored-by: Kuan Fan <[email protected]>

* Update emergency-release-build-1.59.1.yaml

---------

Co-authored-by: tim738745 <[email protected]>
Co-authored-by: emi-hi <[email protected]>
  • Loading branch information
3 people authored Sep 17, 2024
1 parent d5db7e5 commit 3543d4a
Show file tree
Hide file tree
Showing 12 changed files with 320 additions and 33 deletions.
185 changes: 185 additions & 0 deletions .github/workflows/emergency-release-build-1.59.1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
## For each release, please update the value of workflow name, branches and PR_NUMBER
## Also update frontend/package.json version

name: Emergency Release Build 1.59.1

on:
workflow_dispatch:

env:
## The pull request number of the Tracking pull request to merge the release branch to main
PR_NUMBER: 2244
VERSION: 1.59.1
GIT_URL: https://github.com/bcgov/zeva.git
TOOLS_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-tools
DEV_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-dev
TEST_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-test
PROD_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-prod

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
# call-unit-test:
# uses: ./.github/workflows/unit-test-template.yaml
# with:
# pr-number: 2244

build:
name: Build ZEVA on Openshift
runs-on: ubuntu-latest
timeout-minutes: 60
# needs: call-unit-test

steps:
- name: Check out repository
uses: actions/[email protected]
with:
ref: refs/pull/${{ env.PR_NUMBER }}/head

- name: Log in to Openshift
uses: redhat-actions/[email protected]
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
insecure_skip_tls_verify: true
namespace: ${{ env.TOOLS_NAMESPACE }}

- name: Build ZEVA Backend
run: |
cd openshift/templates/backend
oc process -f ./backend-bc.yaml NAME=zeva SUFFIX=-build-${{ env.PR_NUMBER }} VERSION=build-${{ env.VERSION }}-${{ env.PR_NUMBER }} GIT_URL=${{ env.GIT_URL }} GIT_REF=refs/pull/${{ env.PR_NUMBER }}/head | oc apply --wait=true -f - -n ${{ env.TOOLS_NAMESPACE }}
oc start-build --wait=true zeva-backend-build-${{ env.PR_NUMBER }}
- name: Build ZEVA Frontend
run: |
cd openshift/templates/frontend
oc process -f ./frontend-bc-docker.yaml NAME=zeva SUFFIX=-build-${{ env.PR_NUMBER }} VERSION=build-${{ env.VERSION }}-${{ env.PR_NUMBER }} GIT_URL=${{ env.GIT_URL }} GIT_REF=refs/pull/${{ env.PR_NUMBER }}/head | oc apply --wait=true -f - -n ${{ env.TOOLS_NAMESPACE }}
oc start-build --wait=true zeva-frontend-build-${{ env.PR_NUMBER }}
deploy-on-test:
name: Deploy ZEVA on Test
runs-on: ubuntu-latest
timeout-minutes: 60
needs: build

steps:
- name: Check out repository
uses: actions/[email protected]
with:
ref: refs/pull/${{ env.PR_NUMBER }}/head

- name: Log in to Openshift
uses: redhat-actions/[email protected]
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
insecure_skip_tls_verify: true
namespace: ${{ env.TOOLS_NAMESPACE }}

- name: Ask for approval for ZEVA Test deployment
uses: trstringer/[email protected]
with:
secret: ${{ github.TOKEN }}
approvers: AlexZorkin,emi-hi,tim738745,kuanfandevops,prv-proton
minimum-approvals: 1
issue-title: "ZEVA ${{ env.VERSION }} Test Deployment"

- name: Tag Backend Image from tools to Test
run: |
oc tag ${{ env.TOOLS_NAMESPACE }}/zeva-backend:build-${{ env.VERSION }}-${{ env.PR_NUMBER }} ${{ env.TEST_NAMESPACE }}/zeva-backend:test-${{ env.VERSION }}
- name: Tag Frontend Image from tools to Test
run: |
oc tag ${{ env.TOOLS_NAMESPACE }}/zeva-frontend:build-${{ env.VERSION }}-${{ env.PR_NUMBER }} ${{ env.TEST_NAMESPACE }}/zeva-frontend:test-${{ env.VERSION }}
# helm status will show an error if the helm release doesn't exist. The error will be ignored.
- name: Deploy zeva-frontend on Test
shell: bash {0}
run: |
cd charts/zeva-apps/charts/zeva-frontend
helm status -n ${{ env.TEST_NAMESPACE }} zeva-frontend-test
if [ $? -eq 0 ]; then
echo "zeva-frontend-test release exists already"
helm upgrade --install --set frontendImageTagname=test-${{ env.VERSION }},openshiftLicensePlate=${{ secrets.OPENSHIFT_NAMESPACE_PLATE }} -n ${{ env.TEST_NAMESPACE }} -f ./values-test.yaml zeva-frontend-test .
else
echo "zeva-frontend-test release does not exist"
helm install --set frontendImageTagname=test-${{ env.VERSION }},openshiftLicensePlate=${{ secrets.OPENSHIFT_NAMESPACE_PLATE }} -n ${{ env.TEST_NAMESPACE }} -f ./values-test.yaml zeva-frontend-test .
fi
# helm status will show an error if the helm release doesn't exist. The error will be ignored.
- name: Deply zeva-backend on Test
shell: bash {0}
run: |
cd charts/zeva-apps/charts/zeva-backend
helm status -n ${{ env.TEST_NAMESPACE }} zeva-backend-test
if [ $? -eq 0 ]; then
echo "zeva-backend-test release exists already"
helm upgrade --set backendImageTagname=test-${{ env.VERSION }} -n ${{ env.TEST_NAMESPACE }} -f ./values-test.yaml zeva-backend-test .
else
echo "zeva-backend-test release does not exist"
helm install --set backendImageTagname=test-${{ env.VERSION }} -n ${{ env.TEST_NAMESPACE }} -f ./values-test.yaml zeva-backend-test .
fi
deploy-on-prod:
name: Deploy ZEVA on Prod
runs-on: ubuntu-latest
timeout-minutes: 60
needs: deploy-on-test

steps:
- name: Check out repository
uses: actions/[email protected]
with:
ref: refs/pull/${{ env.PR_NUMBER }}/head

- name: Log in to Openshift
uses: redhat-actions/[email protected]
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
insecure_skip_tls_verify: true
namespace: ${{ env.TOOLS_NAMESPACE }}

- name: Ask for approval for ZEVA Prod deployment
uses: trstringer/[email protected]
with:
secret: ${{ github.TOKEN }}
approvers: AlexZorkin,kuanfandevops,tim738745,emi-hi
minimum-approvals: 1
issue-title: "ZEVA ${{ env.VERSION }} Prod Deployment"

- name: Tag Frontend Image from tools to Prod
run: |
oc tag ${{ env.TOOLS_NAMESPACE }}/zeva-frontend:build-${{ env.VERSION }}-${{ env.PR_NUMBER }} ${{ env.PROD_NAMESPACE }}/zeva-frontend:prod-${{ env.VERSION }}
- name: Tag Backend Image from tools to Prod
run: |
oc tag ${{ env.TOOLS_NAMESPACE }}/zeva-backend:build-${{ env.VERSION }}-${{ env.PR_NUMBER }} ${{ env.PROD_NAMESPACE }}/zeva-backend:prod-${{ env.VERSION }}
- name: Deply zeva-frontend on Prod
shell: bash {0}
run: |
cd charts/zeva-apps/charts/zeva-frontend
helm status -n ${{ env.PROD_NAMESPACE }} zeva-frontend-prod
if [ $? -eq 0 ]; then
echo "zeva-frontend-prod release exists already"
helm upgrade --set frontendImageTagname=prod-${{ env.VERSION }},openshiftLicensePlate=${{ secrets.OPENSHIFT_NAMESPACE_PLATE }} -n ${{ env.PROD_NAMESPACE }} -f ./values-prod.yaml zeva-frontend-prod .
else
echo "zeva-frontend-prod release does not exist"
helm install --set frontendImageTagname=prod-${{ env.VERSION }},openshiftLicensePlate=${{ secrets.OPENSHIFT_NAMESPACE_PLATE }} -n ${{ env.PROD_NAMESPACE }} -f ./values-prod.yaml zeva-frontend-prod .
fi
- name: Deply zeva-backend on Prod
shell: bash {0}
run: |
cd charts/zeva-apps/charts/zeva-backend
helm status -n ${{ env.PROD_NAMESPACE }} zeva-backend-prod
if [ $? -eq 0 ]; then
echo "zeva-backend-prod release exists already"
helm upgrade --set backendImageTagname=prod-${{ env.VERSION }} -n ${{ env.PROD_NAMESPACE }} -f ./values-prod.yaml zeva-backend-prod .
else
echo "zeva-backend-prod release does not exist"
helm install --set backendImageTagname=prod-${{ env.VERSION }} -n ${{ env.PROD_NAMESPACE }} -f ./values-prod.yaml zeva-backend-prod .
fi
31 changes: 21 additions & 10 deletions backend/api/serializers/credit_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
CreditTransferCommentSerializer
from api.serializers.credit_transfer_content import \
CreditTransferContentSerializer, CreditTransferContentSaveSerializer
from api.serializers.user import MemberSerializer, UserSerializer
from api.serializers.organization import OrganizationSerializer
from api.serializers.user import UserBasicSerializer
from api.serializers.organization import OrganizationNameSerializer, OrganizationSerializer
from api.services.credit_transaction import calculate_insufficient_credits
from api.services.send_email import notifications_credit_transfers

Expand All @@ -29,15 +29,15 @@ def get_update_user(self, obj):
user_profile = UserProfile.objects.filter(username=obj.update_user)

if user_profile.exists():
serializer = MemberSerializer(user_profile.first(), read_only=True)
serializer = UserBasicSerializer(user_profile.first(), read_only=True)
return serializer.data

return obj.update_user

def get_create_user(self, obj):
user_profile = UserProfile.objects.filter(username=obj.create_user)
if user_profile.exists():
serializer = UserSerializer(user_profile.first(), read_only=True)
serializer = UserBasicSerializer(user_profile.first(), read_only=True)
return serializer.data
return obj.create_user

Expand All @@ -47,6 +47,8 @@ def get_history(self, obj):
history = CreditTransferHistory.objects.filter(
transfer_id=obj.id)
else:
create_user_subquery = UserProfile.objects.filter(organization__is_government=True).values_list('username', flat=True)

history = CreditTransferHistory.objects.filter(
transfer_id=obj.id,
status__in=[
Expand All @@ -58,8 +60,8 @@ def get_history(self, obj):
CreditTransferStatuses.RESCIND_PRE_APPROVAL,
CreditTransferStatuses.REJECTED,
CreditTransferStatuses.VALIDATED
])
serializer = CreditTransferHistorySerializer(history, many=True, read_only=True)
]).exclude(create_user__in=create_user_subquery, status__in=[CreditTransferStatuses.APPROVED, CreditTransferStatuses.DISAPPROVED,])
serializer = CreditTransferHistorySerializer(history, many=True, read_only=True, context={'request': request})
return serializer.data


Expand Down Expand Up @@ -97,11 +99,11 @@ class CreditTransferListSerializer(
CreditTransferBaseSerializer
):
history = SerializerMethodField()
credit_to = OrganizationSerializer()
credit_to = OrganizationNameSerializer()
credit_transfer_content = CreditTransferContentSerializer(
many=True, read_only=True
)
debit_from = OrganizationSerializer()
debit_from = OrganizationNameSerializer()
status = SerializerMethodField()
update_user = SerializerMethodField()

Expand All @@ -128,11 +130,11 @@ class CreditTransferSerializer(
CreditTransferBaseSerializer
):
history = SerializerMethodField()
credit_to = OrganizationSerializer()
credit_to = OrganizationNameSerializer()
credit_transfer_content = CreditTransferContentSerializer(
many=True, read_only=True
)
debit_from = OrganizationSerializer()
debit_from = OrganizationNameSerializer()
status = SerializerMethodField()
update_user = SerializerMethodField()
sufficient_credits = SerializerMethodField()
Expand Down Expand Up @@ -198,6 +200,15 @@ class Meta:
)


class CreditTransferOrganizationBalancesSerializer(ModelSerializer):
credit_to = OrganizationSerializer()
debit_from = OrganizationSerializer()

class Meta:
model = CreditTransfer
fields = ('credit_to', 'debit_from')


class CreditTransferSaveSerializer(ModelSerializer):
"""
Serializer to create a transfer
Expand Down
10 changes: 10 additions & 0 deletions backend/api/serializers/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
OrganizationLDVSalesSerializer
from api.models.model_year import ModelYear

class OrganizationNameSerializer(serializers.ModelSerializer):
"""
Serializer for passing just the necessary info for credit transfers etc
"""
class Meta:
model = Organization
fields = (
'id', 'name', 'short_name', 'is_government'
)


class OrganizationSerializer(serializers.ModelSerializer):
"""
Expand Down
13 changes: 12 additions & 1 deletion backend/api/serializers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from api.models.role import Role
from api.models.user_profile import UserProfile
from api.services.user import update_roles, create_default_user_notification_settings
from .organization import OrganizationSerializer
from .organization import OrganizationSerializer, OrganizationNameSerializer
from .permission import PermissionSerializer
from .role import RoleSerializer

Expand All @@ -30,6 +30,17 @@ class Meta:
)


class UserBasicSerializer(serializers.ModelSerializer):
"""
Serializer for the basic details of a user
"""
organization = OrganizationNameSerializer(read_only=True)
class Meta:
model = UserProfile
fields = (
'display_name', 'organization'
)

class UserSerializer(serializers.ModelSerializer):
"""
Serializer for the full details of the User
Expand Down
Loading

0 comments on commit 3543d4a

Please sign in to comment.