Skip to content

Commit

Permalink
Tracking pull request to merge release-1.18.0 to master - Sprint 28 (…
Browse files Browse the repository at this point in the history
…Bunsen) (#510)
  • Loading branch information
kuanfandevops authored Jan 28, 2021
1 parent 8fb1172 commit f9f4d3c
Show file tree
Hide file tree
Showing 73 changed files with 1,733 additions and 565 deletions.
13 changes: 8 additions & 5 deletions .pipeline/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const phases = {
ssoName:'dev.oidc.gov.bc.ca', phase: 'dev' , changeId:`${changeId}`, suffix: `-dev-${changeId}`,
instance: `${name}-dev-${changeId}` , version:`${version}-${changeId}`, tag:`dev-${version}-${changeId}`,
host: `zeva-dev-${changeId}.${ocpName}.gov.bc.ca`, djangoDebug: 'True', logoutHostName: 'logontest.gov.bc.ca',
frontendCpuRequest: '100m', frontendCpuLimit: '700m', frontendMemoryRequest: '300M', frontendMemoryLimit: '4G', frontendReplicas: 1, creditTransferEnabled: 'true',
frontendCpuRequest: '100m', frontendCpuLimit: '700m', frontendMemoryRequest: '300M', frontendMemoryLimit: '4G', frontendReplicas: 1,
creditTransfersEnabled: 'true', creditTransactionsEnabled: 'true', initiativeAgreementsEnabled: 'true', modelYearReportEnabled: 'true', purchaseRequestsEnabled: 'true', notificationsEnabled: 'true', complianceReportEnabled: 'true', rolesEnabled: 'true',
backendCpuRequest: '300m', backendCpuLimit: '600m', backendMemoryRequest: '1G', backendMemoryLimit: '2G', backendHealthCheckDelay: 30, backendHost: `zeva-backend-dev-${changeId}.${ocpName}.gov.bc.ca`, backendReplicas: 1,
minioCpuRequest: '100m', minioCpuLimit: '200m', minioMemoryRequest: '200M', minioMemoryLimit: '500M', minioPvcSize: '1G',
schemaspyCpuRequest: '50m', schemaspyCpuLimit: '200m', schemaspyMemoryRequest: '150M', schemaspyMemoryLimit: '300M', schemaspyHealthCheckDelay: 160,
Expand All @@ -31,8 +32,9 @@ const phases = {
ssoName:'test.oidc.gov.bc.ca', phase: 'test' , changeId:`${changeId}`, suffix: `-test`,
instance: `${name}-test`, version:`${version}`, tag:`test-${version}`,
host: `zeva-test.${ocpName}.gov.bc.ca`, djangoDebug: 'False', logoutHostName: 'logontest.gov.bc.ca',
frontendCpuRequest: '300m', frontendCpuLimit: '600m', frontendMemoryRequest: '500M', frontendMemoryLimit: '1G', frontendReplicas: 2, frontendMinReplicas: 2, frontendMaxReplicas: 5, creditTransferEnabled: 'true',
backendCpuRequest: '100m', backendCpuLimit: '500m', backendMemoryRequest: '500M', backendMemoryLimit: '2G', backendHealthCheckDelay: 30, backendReplicas: 1, backendMinReplicas: 2, backendMaxReplicas: 5, backendHost: `zeva-backend-test.${ocpName}.gov.bc.ca`,
frontendCpuRequest: '300m', frontendCpuLimit: '600m', frontendMemoryRequest: '500M', frontendMemoryLimit: '1G', frontendReplicas: 2, frontendMinReplicas: 2, frontendMaxReplicas: 5,
creditTransfersEnabled: 'true', creditTransactionsEnabled: 'true', initiativeAgreementsEnabled: 'false', modelYearReportEnabled: 'false', purchaseRequestsEnabled: 'false', notificationsEnabled: 'true', complianceReportEnabled: 'true', rolesEnabled: 'false',
backendCpuRequest: '100m', backendCpuLimit: '500m', backendMemoryRequest: '500M', backendMemoryLimit: '2G', backendHealthCheckDelay: 30, backendReplicas: 2, backendMinReplicas: 2, backendMaxReplicas: 5, backendHost: `zeva-backend-test.${ocpName}.gov.bc.ca`,
minioCpuRequest: '100m', minioCpuLimit: '300m', minioMemoryRequest: '500M', minioMemoryLimit: '700M', minioPvcSize: '3G',
schemaspyCpuRequest: '20m', schemaspyCpuLimit: '200m', schemaspyMemoryRequest: '150M', schemaspyMemoryLimit: '300M', schemaspyHealthCheckDelay: 160,
rabbitmqCpuRequest: '250m', rabbitmqCpuLimit: '700m', rabbitmqMemoryRequest: '500M', rabbitmqMemoryLimit: '700M', rabbitmqPvcSize: '1G', rabbitmqReplica: 2, rabbitmqPostStartSleep: 120, storageClass: 'netapp-block-standard',
Expand All @@ -42,8 +44,9 @@ const phases = {
ssoName:'oidc.gov.bc.ca', phase: 'prod' , changeId:`${changeId}`, suffix: `-prod`,
instance: `${name}-prod`, version:`${version}`, tag:`prod-${version}`,
host: 'zeroemissionvehicles.gov.bc.ca', djangoDebug: 'False', logoutHostName: 'logon7.gov.bc.ca',
frontendCpuRequest: '300m', frontendCpuLimit: '600m', frontendMemoryRequest: '1G', frontendMemoryLimit: '2G', frontendReplicas: 2, frontendMinReplicas: 2, frontendMaxReplicas: 5, creditTransferEnabled: 'false',
backendCpuRequest: '200m', backendCpuLimit: '700m', backendMemoryRequest: '1G', backendMemoryLimit: '2G', backendHealthCheckDelay: 30, backendReplicas: 1, backendMinReplicas: 2, backendMaxReplicas: 5, backendHost: `zeva-backend-prod.${ocpName}.gov.bc.ca`,
frontendCpuRequest: '300m', frontendCpuLimit: '600m', frontendMemoryRequest: '1G', frontendMemoryLimit: '2G', frontendReplicas: 2, frontendMinReplicas: 2, frontendMaxReplicas: 5,
creditTransfersEnabled: 'true', creditTransactionsEnabled: 'true', initiativeAgreementsEnabled: 'false', modelYearReportEnabled: 'false', purchaseRequestsEnabled: 'false', notificationsEnabled: 'false', complianceReportEnabled: 'false', rolesEnabled: 'false',
backendCpuRequest: '200m', backendCpuLimit: '700m', backendMemoryRequest: '1G', backendMemoryLimit: '2G', backendHealthCheckDelay: 30, backendReplicas: 2, backendMinReplicas: 2, backendMaxReplicas: 5, backendHost: `zeva-backend-prod.${ocpName}.gov.bc.ca`,
minioCpuRequest: '100m', minioCpuLimit: '300m', minioMemoryRequest: '500M', minioMemoryLimit: '700M', minioPvcSize: '3G',
schemaspyCpuRequest: '50m', schemaspyCpuLimit: '400m', schemaspyMemoryRequest: '150M', schemaspyMemoryLimit: '300M', schemaspyHealthCheckDelay: 160,
rabbitmqCpuRequest: '250m', rabbitmqCpuLimit: '700m', rabbitmqMemoryRequest: '500M', rabbitmqMemoryLimit: '1G', rabbitmqPvcSize: '5G', rabbitmqReplica: 2, rabbitmqPostStartSleep: 120, storageClass: 'netapp-block-standard',
Expand Down
37 changes: 14 additions & 23 deletions .pipeline/lib/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ module.exports = settings => {
}
}))
}
/**** open this block, it will only deploy network security policies
console.log("will return22")
oc.applyRecommendedLabels(
objects,
phases[phase].name,
phase,
`${changeId}`,
phases[phase].instance,
);
oc.importImageStreams(objects, phases[phase].tag, phases.build.namespace, phases.build.tag);
oc.applyAndDeploy(objects, phases[phase].instance);
return;
console.log("you should not see this");
*/

// create configs
if(phase === 'dev') {
Expand Down Expand Up @@ -148,15 +134,20 @@ module.exports = settings => {
*/

// deploy frontend configmap
if(phase === 'dev') {
objects = objects.concat(oc.processDeploymentTemplate(`${templatesLocalBaseUrl}/templates/frontend/frontend-configmap.yaml`, {
'param': {
'NAME': phases[phase].name,
'SUFFIX': phases[phase].suffix,
'CREDIT_TRANSFER_ENABLED': phases[phase].creditTransferEnabled
}
}))
}
objects = objects.concat(oc.processDeploymentTemplate(`${templatesLocalBaseUrl}/templates/frontend/frontend-configmap.yaml`, {
'param': {
'NAME': phases[phase].name,
'SUFFIX': phases[phase].suffix,
'CREDIT_TRANSFERS_ENABLED': phases[phase].creditTransfersEnabled,
'CREDIT_TRANSACTIONS_ENABLED': phases[phase].creditTransactionsEnabled,
'INITIATIVE_AGREEMENTS_ENABLED': phases[phase].initiativeAgreementsEnabled,
'MODEL_YEAR_REPORT_ENABLED': phases[phase].modelYearReportEnabled,
'PURCHASE_REQUESTS_ENABLED': phases[phase].purchaseRequestsEnabled,
'NOTIFICATIONS_ENABLED': phases[phase].notificationsEnabled,
'COMPLIANCE_REPORT_ENABLED': phases[phase].complianceReportEnabled,
'ROLES_ENABLED': phases[phase].rolesEnabled
}
}))

// deploy frontend
objects = objects.concat(oc.processDeploymentTemplate(`${templatesLocalBaseUrl}/templates/frontend/frontend-dc.yaml`, {
Expand Down
82 changes: 82 additions & 0 deletions backend/api/fixtures/operational/0018_update_notifications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from django.db import transaction

from api.management.data_script import OperationalDataScript
from api.models.notification import Notification
from api.models.permission import Permission
from api.authorities import REQUIRED_AUTHORITIES


class UpdateNotifications(OperationalDataScript):
"""
Update the Notifications
"""
is_revertable = False
comment = 'Update the Notifications'

def check_run_preconditions(self):
return True

def add_notifications(self):

Notification.objects.get_or_create(
notification_code="CREDIT_TRANSFER_SUBMITTED",
permission=Permission.objects.get(permission_code="CREATE_CREDIT_TRANSFERS"),
defaults={
'name': 'Credit Transfer to Review',
'description': "when supplier submits a credit transfer"
}
)
Notification.objects.get_or_create(
notification_code="CREDIT_TRANSFER_RESCINDED_PARTNER",
permission=Permission.objects.get(permission_code="CREATE_CREDIT_TRANSFERS"),
defaults={
'name': 'Credit Transfer Rescinded by Transfer Partner',
'description': "when transfer partner rescind a credit transfer"
}
)
Notification.objects.get_or_create(
notification_code="CREDIT_TRANSFER_REJECTED_PARTNER",
permission=Permission.objects.get(permission_code="CREATE_CREDIT_TRANSFERS"),
defaults={
'name': 'Credit Transfer Rejected by Transfer Partner',
'description': "when transfer partner reject a credit transfer"
}
)
Notification.objects.get_or_create(
notification_code="ZEV_MODEL_RANGE_REPORT_TEST_RESULT_REQUESTED",
permission=Permission.objects.get(permission_code="CREATE_ZEV"),
defaults={
'name': 'ZEV Model Request for Range Change / Test Results',
'description': "when government request range report or test results for a zev model"
}
)
Notification.objects.get_or_create(
notification_code="CREDIT_TRANSFER_RESCINDED",
permission=Permission.objects.get(permission_code="RECOMMEND_CREDIT_TRANSFER"),
defaults={
'name': 'Credit Transfer Rescinded by Supplier',
'description': "when supplier rescinds transfer"
}
)

def delete_notifications(self):
notifications_to_be_deleted = [
'ZEV_MODEL_RANGE_REPORT_REQUESTED',
'ZEV_MODEL_TEST_RESULTS_REQUESTED',
'CREDIT_TRANSFER_RESCIND_PARTNER',
'CREDIT_TRANSFER_REJECT_PARTNER',
'CREDIT_TRANSFER_RESCIND'
]
Notification.objects.filter(
notification_code__in=notifications_to_be_deleted
).delete()

@transaction.atomic
def run(self):
self.delete_notifications()
self.add_notifications()

print('Updated Notifications')


script_class = UpdateNotifications
35 changes: 35 additions & 0 deletions backend/api/migrations/0085_salesevidence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 3.0.3 on 2021-01-20 16:53

import db_comments.model_mixins
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('api', '0084_notification_notificationsubscription'),
]

operations = [
migrations.CreateModel(
name='SalesEvidence',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)),
('create_user', models.CharField(default='SYSTEM', max_length=130)),
('update_timestamp', models.DateTimeField(auto_now=True, null=True)),
('update_user', models.CharField(max_length=130, null=True)),
('filename', models.CharField(max_length=260)),
('minio_object_name', models.CharField(max_length=32)),
('size', models.BigIntegerField(default=0)),
('mime_type', models.CharField(blank=True, max_length=255, null=True)),
('is_removed', models.BooleanField(default=False)),
('submission', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='sales_evidence', to='api.SalesSubmission')),
],
options={
'db_table': 'sale_submission_file_attachment',
},
bases=(models.Model, db_comments.model_mixins.DBComments),
),
]
17 changes: 17 additions & 0 deletions backend/api/migrations/0086_auto_20210120_1318.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.0.3 on 2021-01-20 21:18

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('api', '0085_salesevidence'),
]

operations = [
migrations.AlterModelTable(
name='salesevidence',
table='sales_submission_evidence',
),
]
1 change: 1 addition & 0 deletions backend/api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@
from . import icbc_vehicle
from . import icbc_upload_date
from . import notification, notification_subscription
from . import sales_evidence
47 changes: 47 additions & 0 deletions backend/api/models/sales_evidence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from django.db import models
from auditable.models import Auditable


class SalesEvidence(Auditable):
"""
Attachment information for the sale submission.
"""
submission = models.ForeignKey(
'SalesSubmission',
null=False,
related_name='sales_evidence',
on_delete=models.PROTECT
)
filename = models.CharField(
max_length=260,
db_comment="Filename from when it was in the user's system."
)
minio_object_name = models.CharField(
blank=False,
max_length=32,
null=False,
db_comment="Object name in minio (UUID as a 32 hexadecimal string)."
)
size = models.BigIntegerField(
default=0,
null=False,
db_comment="Size of the file in bytes."
)
mime_type = models.CharField(
blank=True,
max_length=255,
null=True,
db_comment="Mime type information of the file. "
"(eg. application/pdf, image/gif, image/png, etc)"
)
is_removed = models.BooleanField(
default=False,
db_comment="Whether it was marked as deleted"
)

class Meta:
db_table = 'sales_submission_evidence'

db_table_comment = "Attachment information for the sale submission." \
"Contains information such as mime type, file size, " \
"and minio URL."
31 changes: 31 additions & 0 deletions backend/api/permissions/upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from rest_framework import permissions


class UploadPermissions(permissions.BasePermission):
"""Used by Viewset to check permissions for API requests"""

def has_permission(self, request, view):
if request.user.is_government:
return True

return request.user.has_perm('CREATE_SALES') or \
request.user.has_perm('SUBMIT_SALES') or \
request.user.has_perm('EDIT_SALES') or \
request.user.has_perm('CREATE_ZEV') or \
request.user.has_perm('EDIT_ZEV') or \
request.user.has_perm('SUBMIT_ZEV')

def has_object_permission(self, request, view, obj):
"""Check permissions When an object does exist (PUT, GET)"""
if request.user.is_government:
return True

if request.user.has_perm('CREATE_SALES') or \
request.user.has_perm('SUBMIT_SALES') or \
request.user.has_perm('EDIT_SALES') or \
request.user.has_perm('CREATE_ZEV') or \
request.user.has_perm('EDIT_ZEV') or \
request.user.has_perm('SUBMIT_ZEV'):
return True

return False
40 changes: 40 additions & 0 deletions backend/api/permissions/vehicle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from rest_framework import permissions


class VehiclePermissions(permissions.BasePermission):
"""Used by Viewset to check permissions for API requests"""

def has_permission(self, request, view):
"""Check permissions When an object does not yet exist (POST)"""
# Fallback to has_object_permission unless it's a POST
if request.method != 'POST':
return True

if request.user.is_government:
return request.user.has_perm('REQUEST_ZEV_CHANGES') or \
request.user.has_perm('VALIDATE_ZEV')

return request.user.has_perm('CREATE_ZEV') or \
request.user.has_perm('SUBMIT_ZEV') or \
request.user.has_perm('EDIT_ZEV')

def has_object_permission(self, request, view, obj):
"""Check permissions When an object does exist (PUT, GET)"""
if request.user.has_perm('REQUEST_ZEV_CHANGES') or \
request.user.has_perm('VALIDATE_ZEV'):
return True

if obj.organization_id == request.user.organization_id:
if request.method in permissions.SAFE_METHODS:
return True

if request.user.has_perm('CREATE_ZEV') or \
request.user.has_perm('SUBMIT_ZEV') or \
request.user.has_perm('EDIT_ZEV'):
return True

if request.method == 'GET' and \
request.user.has_perm('VIEW_ZEV'):
return True

return False
3 changes: 3 additions & 0 deletions backend/api/serializers/credit_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from api.models.organization import Organization
from api.services.credit_transfer import aggregate_credit_transfer_details
from api.services.credit_transaction import calculate_insufficient_credits
from api.services.send_email import notifications_credit_transfers
from decimal import Decimal


Expand Down Expand Up @@ -347,6 +348,8 @@ def create(self, validated_data):
signing_authority_assertion_id=confirmation
)

notifications_credit_transfers(credit_transfer)

serializer = CreditTransferSerializer(
credit_transfer, read_only=True,
context={
Expand Down
Loading

0 comments on commit f9f4d3c

Please sign in to comment.