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

555 it standards mobile type updates #560

Merged
merged 9 commits into from
Jan 13, 2025
4 changes: 3 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
"node_modules/bootstrap-table/dist/bootstrap-table.min.css",
"node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css",
"node_modules/@ng-select/ng-select/themes/default.theme.css",
"node_modules/@uswds/uswds/dist/css/uswds.css"
"node_modules/@uswds/uswds/dist/css/uswds.css",
"node_modules/primeng/resources/themes/lara-light-blue/theme.css",
"node_modules/primeng/resources/primeng.min.css"
],
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
Expand Down
5 changes: 5 additions & 0 deletions api/controllers/base.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
* @return {object} - query results as JSON
*/
function buildQuery(conn, query, msg, response, postProcessFunc = null) {
conn.query(query, (error, data) => {

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
if (error) {
console.log(`DB Query Error while executing ${msg}: `, error);
response.status(501).json({
Expand Down Expand Up @@ -120,6 +120,11 @@
else return content;
};

exports.setNullEmptyTextHandler = (content) => {
if(!content || content === 'NULL' || content === 'null') return null;
else return `"${content}"`;
}

const msgLog = (message, logger) => {
if (logger) {
logger.log(message);
Expand Down
151 changes: 124 additions & 27 deletions api/controllers/it-standards.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,63 +86,147 @@ exports.update = (req, res) => {
});
};

// Null any empty text fields
data.itStandDesc = ctrl.emptyTextFieldHandler(data.itStandDesc);
data.itStandAprvExp = ctrl.emptyTextFieldHandler(data.itStandAprvExp);
data.itStandRefDocs = ctrl.emptyTextFieldHandler(data.itStandRefDocs);
data.itStandApprovedVersions = ctrl.emptyTextFieldHandler(data.itStandApprovedVersions);
// Create string to update IT Standards Operating Systems
var osString = '';
var osToDelete = [];
var osToAdd = [];
if(data.itStandOperatingSystems && data.itStandOperatingSystems.length > 0) {
for(const osId of data.itStandOperatingSystems) {
if(!data.initialOS || (data.initialOS && data.initialOS.length === 0)) {
osToAdd.push(osId);
} else {
if(!data.initialOS.includes(osId)) {
osToAdd.push(osId);
}
}
}
}
if(data.initialOS && data.initialOS.length > 0) {
for(const osId of data.initialOS) {
if(!data.itStandOperatingSystems || (data.itStandOperatingSystems && data.itStandOperatingSystems.length === 0)) {
osToDelete.push(osId);
} else {
if(!data.itStandOperatingSystems.includes(osId)) {
osToDelete.push(osId);
}
}
}
}

if(osToDelete.length > 0) {
osToDelete.forEach(o => {
osString += `DELETE FROM zk_technology_operating_system WHERE obj_technology_Id=${req.params.id} AND obj_operating_system_Id=${o}; `;
});
}

data.tcManufacturer = ctrl.emptyTextFieldHandler(data.tcManufacturer);
data.tcSoftwareProduct = ctrl.emptyTextFieldHandler(data.tcSoftwareProduct);
data.tcSoftwareVersion = ctrl.emptyTextFieldHandler(data.tcSoftwareVersion);
data.tcSoftwareRelease = ctrl.emptyTextFieldHandler(data.tcSoftwareRelease);
data.tcManufacturerName = ctrl.emptyTextFieldHandler(data.tcManufacturerName);
data.tcSoftwareProductName = ctrl.emptyTextFieldHandler(data.tcSoftwareProductName);
data.tcSoftwareVersionName = ctrl.emptyTextFieldHandler(data.tcSoftwareVersionName);
data.tcSoftwareReleaseName = ctrl.emptyTextFieldHandler(data.tcSoftwareReleaseName);
data.tcEndOfLifeDate = ctrl.emptyTextFieldHandler(data.tcEndOfLifeDate);
if(osToAdd.length > 0) {
osToAdd.forEach(o => {
osString += `INSERT INTO zk_technology_operating_system (obj_operating_system_Id, obj_technology_Id) VALUES (${o}, ${req.params.id}); `;
});
}

// Create string to update IT Standards App Bundles
var appBundleString = '';
var appBundleToDelete = [];
var appBundleToAdd = [];
if(data.itStandMobileAppBundles && data.itStandMobileAppBundles.length > 0) {
for(const appId of data.itStandMobileAppBundles) {
if(!data.initialAppBundles || (data.initialAppBundles && data.initialAppBundles.length === 0)) {
appBundleToAdd.push(appId);
} else {
if(!data.initialAppBundles.find(({Name}) => Name === appId.Name)) {
appBundleToAdd.push(appId);
}
}
}
}
if(data.initialAppBundles.length > 0) {
for(const appId of data.initialAppBundles) {
if(!data.itStandMobileAppBundles || (data.itStandMobileAppBundles && data.itStandMobileAppBundles.length === 0)) {
appBundleToDelete.push(appId);
} else {
if(!data.itStandMobileAppBundles.find(({Name}) => Name === appId.Name)) {
appBundleToDelete.push(appId);
}
}
}
}

// Delete from app bundle table and match table
if(appBundleToDelete.length > 0) {
appBundleToDelete.forEach(a => {
appBundleString += `DELETE FROM zk_technology_app_bundle WHERE obj_technology_Id=${req.params.id} AND obj_technology_app_bundle_Id=${a.ID}; `;
appBundleString += `DELETE FROM obj_technology_app_bundle WHERE Id=${a.ID}; `;
});
}

data.itStandRITM = ctrl.setEmptyTextFieldHandler(data.itStandRITM);
// Add to app bundle table and the match table
if(appBundleToAdd.length > 0) {
appBundleToAdd.forEach(a => {
appBundleString += `INSERT INTO obj_technology_app_bundle (Keyname) VALUES ('${a.Name}'); `;
appBundleString += `INSERT INTO zk_technology_app_bundle (obj_technology_app_bundle_Id, obj_technology_Id) VALUES (LAST_INSERT_ID(), ${req.params.id}); `;
});
}

// Null any empty text fields
data.itStandDesc = ctrl.setNullEmptyTextHandler(data.itStandDesc);
data.itStandAprvExp = ctrl.setNullEmptyTextHandler(data.itStandAprvExp);
data.itStandRefDocs = ctrl.setNullEmptyTextHandler(data.itStandRefDocs);
data.itStandApprovedVersions = ctrl.setNullEmptyTextHandler(data.itStandApprovedVersions);

data.tcManufacturer = ctrl.setNullEmptyTextHandler(data.tcManufacturer);
data.tcSoftwareProduct = ctrl.setNullEmptyTextHandler(data.tcSoftwareProduct);
data.tcSoftwareVersion = ctrl.setNullEmptyTextHandler(data.tcSoftwareVersion);
data.tcSoftwareRelease = ctrl.setNullEmptyTextHandler(data.tcSoftwareRelease);
data.tcManufacturerName = ctrl.setNullEmptyTextHandler(data.tcManufacturerName);
data.tcSoftwareProductName = ctrl.setNullEmptyTextHandler(data.tcSoftwareProductName);
data.tcSoftwareVersionName = ctrl.setNullEmptyTextHandler(data.tcSoftwareVersionName);
data.tcSoftwareReleaseName = ctrl.setNullEmptyTextHandler(data.tcSoftwareReleaseName);
data.tcEndOfLifeDate = ctrl.setNullEmptyTextHandler(data.tcEndOfLifeDate);

data.itStandRITM = ctrl.setNullEmptyTextHandler(data.itStandRITM);

const endOfLifeDateFragment = getEolFragment(data.tcEndOfLifeDate);

var query = `SET FOREIGN_KEY_CHECKS=0;
UPDATE obj_technology
SET
Keyname = ${(!data.tcSoftwareReleaseName || data.tcSoftwareReleaseName === 'NULL') ? '"'+data.itStandName+'"' : ""},
Keyname = ${(!data.tcSoftwareReleaseName || data.tcSoftwareReleaseName === 'NULL') ? '"'+data.itStandName+'"' : null},
obj_technology_status_Id = ${data.itStandStatus},
Description = "${data.itStandDesc}",
Description = ${data.itStandDesc},
obj_standard_type_Id = ${data.itStandType},
obj_508_compliance_status_Id = ${data.itStand508},
Available_through_Myview = "${data.itStandMyView}",
Vendor_Standard_Organization = "${data.itStandVendorOrg}",
obj_deployment_type_Id = ${data.itStandDeployment},
Gold_Image = "${data.itStandGoldImg}",
attestation_required = "${data.itStandReqAtte}",
attestation_required = ${data.itStandReqAtte},
fedramp = "${data.itStandFedramp}",
open_source = "${data.itStandOpenSource}",
RITM = "${data.itStandRITM}",
RITM = ${data.itStandRITM},
Gold_Image_Comment = "${data.itStandGoldComment}",
attestation_link = "${data.itStandAtteLink}",
Approved_Status_Expiration_Date = ${data.itStandAprvExp},
Comments = "${data.itStandComments}",
Reference_documents = ${data.itStandRefDocs},
ChangeAudit = "${data.auditUser}",
ChangeDTG = NOW(),
manufacturer = "${data.tcManufacturer}",
manufacturer = ${data.tcManufacturer},
softwareProduct = ${data.tcSoftwareProduct},
softwareVersion = ${data.tcSoftwareVersion},
softwareRelease = ${data.tcSoftwareRelease},
manufacturerName = "${data.tcManufacturerName}",
softwareProductName = "${data.tcSoftwareProductName}",
softwareVersionName = "${data.tcSoftwareVersionName}",
softwareReleaseName = "${data.tcSoftwareReleaseName}",
manufacturerName = ${data.tcManufacturerName},
softwareProductName = ${data.tcSoftwareProductName},
softwareVersionName = ${data.tcSoftwareVersionName},
softwareReleaseName = ${data.tcSoftwareReleaseName},
endOfLifeDate = ${endOfLifeDateFragment},
approvedVersions = "${data.itStandApprovedVersions}"
approvedVersions = ${data.itStandApprovedVersions}
WHERE Id = ${req.params.id};
SET FOREIGN_KEY_CHECKS=1;
${catString}
${pocString}`;
${pocString}
${osString}
${appBundleString}`;

var logStatement = `insert into gear_log.event (Event, User, DTG) values ('update IT Standard: ${query.replace(/'/g, '')}', '${req.headers.requester}', now());`;
res = ctrl.sendQuery(query + ' ' + logStatement, 'update IT Standard', res); //removed sendQuery_cowboy reference
Expand Down Expand Up @@ -312,4 +396,17 @@ getEolFragment = (inputDate) => {
('0' + parsedDate.getDate()).slice(-2);

return `STR_TO_DATE('${convertedDate}', '%Y-%m-%d %T')`;
};
};

exports.getAllOperatingSystems = (req, res) => {
var query = fs.readFileSync(path.join(__dirname, queryPath, `GET/get_operating_systems.sql`)).toString();

res = ctrl.sendQuery(query, 'Operating Systems', res);
}

exports.getAppBundles = (req, res) => {
var query = fs.readFileSync(path.join(__dirname, queryPath, `GET/get_it-standard_app_bundles.sql`)).toString() +
` WHERE matchBundle.obj_technology_Id = ${req.params.id});`;

res = ctrl.sendQuery(query, 'App Bundles', res);
}
4 changes: 4 additions & 0 deletions api/models/it-standards-app-bundle.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class AppBundle {
public ID: number;
public Name: string;
}
4 changes: 4 additions & 0 deletions api/models/it-standards.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AppBundle } from "./it-standards-app-bundle.model";

export class ITStandards {
public ID: number = null;
public Name: string = null;
Expand Down Expand Up @@ -32,4 +34,6 @@ export class ITStandards {
public OldName: string = null;
public EndOfLifeDate: Date = null;
public ApprovedVersions: string = null;
public OperatingSystems: number[] = null;
public ApBundleIds: AppBundle[] = null;
}
4 changes: 4 additions & 0 deletions api/models/operating-systems.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class OperatingSystem {
public ID: number;
public Name: string;
}
5 changes: 5 additions & 0 deletions api/queries/GET/get_it-standard_app_bundles.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT appBundle.Id, appBundle.Keyname
FROM obj_technology_app_bundle AS appBundle
WHERE appBundle.Id IN
(SELECT matchBundle.obj_technology_app_bundle_Id
FROM zk_technology_app_bundle AS matchBundle
8 changes: 7 additions & 1 deletion api/queries/GET/get_it-standards.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ SELECT
GROUP_CONCAT(DISTINCT obj_standard_category.Keyname SEPARATOR ', ') AS Category,
tech.Keyname AS OldName,
DATE(tech.endOfLifeDate) AS EndOfLifeDate,
tech.approvedVersions AS ApprovedVersions
tech.approvedVersions AS ApprovedVersions,
GROUP_CONCAT(DISTINCT OS.Keyname SEPARATOR ', ') AS OperatingSystems,
GROUP_CONCAT(DISTINCT BUNDLE.Keyname SEPARATOR ', ') AS AppBundleIds
FROM obj_technology AS tech

LEFT JOIN obj_technology_status ON tech.obj_technology_status_Id = obj_technology_status.Id
Expand All @@ -51,3 +53,7 @@ LEFT JOIN obj_organization AS org ON poc.OrgCode = org.Org_Symbol
LEFT JOIN zk_technology_standard_category ON tech.Id = zk_technology_standard_category.obj_technology_Id
LEFT JOIN obj_standard_category ON zk_technology_standard_category.obj_standard_category_Id = obj_standard_category.Id
LEFT JOIN obj_attestation_status_type ON tech.attestation_required = obj_attestation_status_type.Id
LEFT JOIN zk_technology_operating_system ON tech.Id = zk_technology_operating_system.obj_technology_Id
LEFT JOIN obj_operating_system AS OS ON zk_technology_operating_system.obj_operating_system_Id = OS.Id
LEFT JOIN zk_technology_app_bundle ON tech.Id = zk_technology_app_bundle.obj_technology_Id
LEFT JOIN obj_technology_app_bundle AS BUNDLE ON zk_technology_app_bundle.obj_technology_app_bundle_Id = BUNDLE.Id
5 changes: 5 additions & 0 deletions api/queries/GET/get_operating_systems.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT
Id AS ID,
Keyname AS Name

FROM obj_operating_system;
6 changes: 6 additions & 0 deletions api/routes/it-standards.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@ router.route('/types')
router.route('/attestation_status_types')
.get(itsCtrl.findAttestationStatusTypes);

router.route('/operating_systems')
.get(itsCtrl.getAllOperatingSystems);

router.route('/app_bundles/:id')
.get(itsCtrl.getAppBundles);

module.exports = router;
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"path": "^0.12.7",
"path-to-regexp": "^0.1.10",
"pdfjs-dist": "^2.16.105",
"primeng": "^17.18.10",
"readline": "^1.3.0",
"rxjs": "~6.5.4",
"sqlstring": "^2.3.3",
Expand Down
10 changes: 10 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ const routes: Routes = [
component: ItStandardsComponent,
title: 'IT Standard',
},
{
path: 'it_standards/filtered/:deploymentType/:status',
component: ItStandardsComponent,
title: 'IT Standard',
},
{
path: 'it_standards/filtered/:deploymentType',
component: ItStandardsComponent,
title: 'IT Standard',
},

//{ path: 'artifacts', component: ArtifactsComponent, title: 'Artifacts' },
//{ path: 'ea_view', component: EAViewComponent, title: 'EA View' }, // We need to update the EA view to be more readable before publishing
Expand Down
4 changes: 4 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ import { YesNoPipe } from "./pipes/yesno.pipe";
import { SkipFocusPiechartDirective } from '@common/skip-focus-piechart.directive';
import { BannerComponent } from './components/banner/banner.component';

// PrimeNG Modules
import { MultiSelectModule } from 'primeng/multiselect';

@NgModule({ declarations: [
AppComponent,
TopNavbarComponent,
Expand Down Expand Up @@ -131,6 +134,7 @@ import { BannerComponent } from './components/banner/banner.component';
NgxChartsModule,
PdfViewerModule,
ReactiveFormsModule,
MultiSelectModule,
SidebarModule.forRoot()], providers: [Globals, provideHttpClient(withInterceptorsFromDi())] })
export class AppModule {
constructor() {}
Expand Down
Loading
Loading