Skip to content

Commit

Permalink
Tracking pull request to merge release-1.28.0 to main (#722)
Browse files Browse the repository at this point in the history
* fix: 702 - parsing decrypted file (#723)

* feat: 693 - delete legacy applications (#726)

* feat: 693 - delete legacy applications

* small change

---------

Co-authored-by: tim738745 <98717409+tim738745@users.noreply.github.com>
  • Loading branch information
kuanfandevops and tim738745 authored Jul 2, 2024
1 parent 3d3e01d commit 1b1b069
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dev-cicd.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## For each release, the value of workflow name, branches and PR_NUMBER need to be adjusted accordingly

name: ITVR Dev release-1.27.0
name: ITVR Dev release-1.28.0

on:
pull_request:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release-build.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: ITVR release-1.27.0
name: ITVR release-1.28.0

on:
workflow_dispatch:
inputs:
pull_request:
description: "Tracking pull request number"
required: true
default: 713
default: 722
release_branch:
description: "The name of the release branch"
required: true
default: release-1.27.0
default: release-1.28.0

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
79 changes: 79 additions & 0 deletions django/api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
DriverLicenceEditableGoElectricRebateApplication,
ChangeRedeemedGoElectricRebateApplication,
ExpiredGoElectricRebateApplication,
LegacyGoElectricRebateApplication,
)
from .models.household_member import HouseholdMember
from .models.go_electric_rebate import GoElectricRebate
Expand Down Expand Up @@ -590,3 +591,81 @@ def response_change(self, request, obj):
else:
raise Exception("There exists an associated Go Elecric Rebate!")
return ret


@admin.register(LegacyGoElectricRebateApplication)
class LegacyGoElectricRebateApplicationAdmin(ITVRModelAdminStringent):

def has_delete_permission(self, request, obj=None):
return admin.ModelAdmin.has_delete_permission(self, request, obj)

search_fields = ["drivers_licence", "id"]
exclude = (
"sin",
"doc1",
"doc2",
"user",
"spouse_email",
"status",
"address",
"city",
"postal_code",
"application_type",
"doc1_tag",
"doc2_tag",
"consent_personal",
"consent_tax",
"reason_for_decline",
)
readonly_fields = (
"id",
"last_name",
"first_name",
"middle_names",
"status",
"email",
"user_is_bcsc",
"drivers_licence",
"date_of_birth",
"tax_year",
"is_legacy",
"confirmation_email_success",
"spouse_email_success",
"created",
"approved_on",
"not_approved_on",
)

def get_queryset(self, request):
return GoElectricRebateApplication.objects.filter(is_legacy=True)

def render_delete_form(self, request, context):
new_perms_lacking = set()
perms_lacking = context.get("perms_lacking")
if perms_lacking is not None:
for p in perms_lacking:
if p != "go electric rebate application":
new_perms_lacking.add(p)
context["perms_lacking"] = new_perms_lacking
return super().render_delete_form(request, context)

def get_deleted_objects(self, objs, request):
(
deleted_objects,
model_count,
perms_needed,
protected,
) = super().get_deleted_objects(objs, request)

new_perms_needed = set()
if perms_needed is not None:
for p in perms_needed:
if p != "go electric rebate application":
new_perms_needed.add(p)

return (
deleted_objects,
model_count,
new_perms_needed,
protected,
)
25 changes: 25 additions & 0 deletions django/api/migrations/0022_legacygoelectricrebateapplication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.0.9 on 2024-06-20 18:31

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('api', '0021_expiredgoelectricrebateapplication'),
]

operations = [
migrations.CreateModel(
name='LegacyGoElectricRebateApplication',
fields=[
],
options={
'ordering': ['-modified'],
'proxy': True,
'indexes': [],
'constraints': [],
},
bases=('api.goelectricrebateapplication',),
),
]
14 changes: 13 additions & 1 deletion django/api/models/go_electric_rebate_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ class Status(TextChoices):
city = CharField(max_length=250, unique=False, null=True)
postal_code = CharField(max_length=6, unique=False, blank=True, null=True)
drivers_licence = CharField(
max_length=8, unique=False, validators=[MinLengthValidator(7), validate_drivers_licence]
max_length=8,
unique=False,
validators=[MinLengthValidator(7), validate_drivers_licence],
)
date_of_birth = DateField(validators=[validate_driving_age], null=True)
tax_year = IntegerField(null=True)
Expand Down Expand Up @@ -299,3 +301,13 @@ class Meta:
@classproperty
def admin_label(cls):
return "Extend Expiry Dates"


class LegacyGoElectricRebateApplication(GoElectricRebateApplication):
class Meta:
proxy = True
ordering = ["-modified"]

@classproperty
def admin_label(cls):
return "Delete Legacy Applications"
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{% get_jazzmin_ui_tweaks as jazzmin_ui %}
{% load static %}
{% block submit-row %}
<!-- <script src="{% static 'edit_dl_handler.js' %}"></script> -->
<div class="card card-primary card-outline">
<div class="card-header">
<h3 class="card-title">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% extends "admin/api/change_form.html" %} {% load i18n admin_urls jazzmin %} {%
get_jazzmin_ui_tweaks as jazzmin_ui %}

{% block itvr_subheader %}{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends "admin/api/change_list.html" %}
{% load i18n admin_urls static admin_list jazzmin %} {%

{% block content_title %} Delete Legacy Applications {% endblock %}
{% block itvr_subtitle %} Delete Legacy Applications {% endblock %}
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "1.27.0",
"version": "1.28.0",
"private": true,
"dependencies": {
"@date-io/date-fns": "^2.14.0",
Expand Down
84 changes: 15 additions & 69 deletions spring/src/main/java/com/cra/service/DecryptService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,92 +2,38 @@

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import javax.mail.Part;
import javax.mail.internet.MimeBodyPart;

import org.springframework.stereotype.Service;

import com.entrust.toolkit.User;
import iaik.smime.SMimeEncrypted;
import iaik.smime.SMimeSigned;
import iaik.smime.SMimeCompressed;
import iaik.asn1.DerInputStream;
import iaik.asn1.SEQUENCE;
import iaik.asn1.CON_SPEC;
import iaik.asn1.OCTET_STRING;

@Service
public class DecryptService {

public String decrypt(User user, byte[] data) throws Exception {
InputStream inputStream = new ByteArrayInputStream(data);
SMimeEncrypted sMimeEncrypted = new SMimeEncrypted(inputStream);
sMimeEncrypted.decryptSymmetricKey(user);
Part p;
InputStream contentStream;

Part p = (Part) new MimeBodyPart(sMimeEncrypted.getInputStream());
InputStream contentStream = (InputStream) p.getContent();
contentStream = new ByteArrayInputStream(data);
SMimeEncrypted encrypted = new SMimeEncrypted(contentStream);
encrypted.decryptSymmetricKey(user);
p = new MimeBodyPart(encrypted.getInputStream());
contentStream = (InputStream) p.getContent();

// the line below reads the signature part from the message into a SMimeSigned
// object:
SMimeSigned signed = new SMimeSigned(contentStream);
System.out
.println("number of signers associated with file we're decrypting: " + signed.getSignerInfos().length);
// todo: see if there are signers using "signed.getSignerInfos().length"; if so,
// check the signature

// now we take the unread part of content:
Part q = (Part) new MimeBodyPart(contentStream);
InputStream refinedContentStream = (InputStream) q.getContent();

DerInputStream dis = new DerInputStream(refinedContentStream);
// next tag may be 4, meaning octet string
// after that is 16, which means sequence
// after that is 6, which means object id
// after that is 0, which means we've reached the end
// let's read the sequence, which is of type CMS compressedData
// to do so, we have to read the octet string first, if present:
if (dis.nextTag() == 4) {
dis.readOctetString();
}

// SMimeCompressed reads from dis where we left off, which is the sequence
SMimeCompressed sMimeCompressed = new SMimeCompressed(dis);

// if we write SMimeCompressed to a file right now, we get the headers at the
// top, e.g.:
// MIME-Version: 1.0
// Content-Type: text/plain;
// charset="US-ASCII";
// name=ABCVR00085
// Content-Transfer-Encoding: 7bit
// Content-Disposition: attachment;
// filename=ABCVR00085

// have to find a way to remove this...
// try:

// calling toASN1Object decompresses the data (I think...)
SEQUENCE sequence = (SEQUENCE) sMimeCompressed.toASN1Object();
// there are 2 components
// the first component is an object id, second is con_spec:
CON_SPEC a = (CON_SPEC) sequence.getComponentAt(1);
// a has exactly one component:
SEQUENCE b = (SEQUENCE) a.getComponentAt(0);
// b has 3 components:
// b's first component is an integer, 2nd and 3rd are sequences
// let's look at the third one:
SEQUENCE c = (SEQUENCE) b.getComponentAt(2);
// c has two components:
// first is object id, second is CON_SPEC:
CON_SPEC d = (CON_SPEC) c.getComponentAt(1);
// d has exactly one component, and it is an octet_string:
OCTET_STRING e = (OCTET_STRING) d.getComponentAt(0);
byte[] value = e.getWholeValue();
InputStream resultStream = new ByteArrayInputStream(value);
p = new MimeBodyPart(signed.getInputStream());
contentStream = (InputStream) p.getContent();

// WILL THE FILES WE RECEIVE ALWAYS HAVE THIS STRUCTURE???
SMimeCompressed compressed = new SMimeCompressed(contentStream);
p = new MimeBodyPart(compressed.getInputStream());
String result = (String) p.getContent();

Part r = (Part) new MimeBodyPart(resultStream);
String text = (String) r.getContent();
return text;
return result;
}
}

0 comments on commit 1b1b069

Please sign in to comment.