Skip to content

Commit

Permalink
Optional chain useless var assignment (NUWCDIVNPT#1181)
Browse files Browse the repository at this point in the history
* use optional chain expression; remove unused variable

* revert to one level up for cert

* missing paren

* remove unused variable & comment

* more optional chaining and unused vars stuff

* revert changes per PR comment

* remove comment

* reomve comment

---------

Co-authored-by: Rajesh Shrestha <rshrestha@rite-solutions.com>


Merging with test coverage workflow failure; changes do not affect coverage, all other tests passed
  • Loading branch information
rajesh-shres authored Jan 16, 2024
1 parent 82dd0ca commit 30a35ac
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 78 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ clients/extjs/js/keycloak.json
.gitignore
newman/
/docs/_build/doctrees/

# macOS file
.DS_Store
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Copyright 2020-2024 Christopher Daley, cdaley@rite-solutions.com
- Copyright 2021 Russell Johnson, russell.d.johnson@saic.com
- Copyright 2023-2024 Mathew Ferreira, mferreira@rite-solutions.com
- Copyright 2024 Rajesh Shrestha, rshrestha@rite-solutions.com
- _Add the copyright date, your name, and email address here. (PLEASE KEEP THIS LINE)_

## Note for U.S. Federal Employees
Expand Down
16 changes: 9 additions & 7 deletions api/source/controllers/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ module.exports.getAsset = async function getAsset (req, res, next) {
if (!response) {
throw new SmError.PrivilegeError()
}
// If there is a response, check if the request included the stigGrants projection
if (projection && projection.includes('stigGrants')) {

// If there is a response and the request included the stigGrants projection
if (projection?.includes('stigGrants')) {
// Check if the stigGrants projection is forbidden
if (!elevate) {
const collectionGrant = req.userObject.collectionGrants.find( g => g.collection.collectionId === response.collection.collectionId )
Expand Down Expand Up @@ -227,8 +227,9 @@ module.exports.getAssets = async function getAssets (req, res, next) {
const collectionGrant = req.userObject.collectionGrants.find( g => g.collection.collectionId === collectionId )

if ( collectionGrant || elevate ) {
// Check if the request includes the stigGrants projection
if (projection && projection.includes('stigGrants')) {

// If there is a response and the request included the stigGrants projection
if (projection?.includes('stigGrants')) {
// Check if the stigGrants projection is forbidden
if (!elevate) {
if (collectionGrant?.accessLevel < 3) {
Expand Down Expand Up @@ -761,7 +762,8 @@ module.exports.putAssetMetadataValue = async function (req, res, next) {
let assetId = await getAssetIdAndCheckPermission(req)
let key = req.params.key
let value = req.body
let result = await AssetService.putAssetMetadataValue(assetId, key, value)

await AssetService.putAssetMetadataValue(assetId, key, value)
res.status(204).send()
}
catch (err) {
Expand All @@ -775,7 +777,7 @@ module.exports.deleteAssetMetadataKey = async function (req, res, next) {
let assetId = await getAssetIdAndCheckPermission(req)
let key = req.params.key

let result = await AssetService.deleteAssetMetadataKey(assetId, key, req.userObject)
await AssetService.deleteAssetMetadataKey(assetId, key, req.userObject)
res.status(204).send()
}
catch (err) {
Expand Down
6 changes: 3 additions & 3 deletions api/source/controllers/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ module.exports.setStigAssetsByCollectionUser = async function setStigAssetsByCol
if ( collectionGrant?.accessLevel >= 3 ) {
const collectionResponse = await CollectionService.getCollection(collectionId, ['grants'], false, req.userObject )
if (collectionResponse.grants.filter( grant => grant.accessLevel === 1 && grant.user.userId === userId).length > 0) {
const setResponse = await CollectionService.setStigAssetsByCollectionUser(collectionId, userId, stigAssets, res.svcStatus )
await CollectionService.setStigAssetsByCollectionUser(collectionId, userId, stigAssets, res.svcStatus )
const getResponse = await CollectionService.getStigAssetsByCollectionUser(collectionId, userId, req.userObject )
res.json(getResponse)
}
Expand Down Expand Up @@ -476,7 +476,7 @@ module.exports.putCollectionMetadataValue = async function (req, res, next) {
let collectionId = getCollectionIdAndCheckPermission(req)
let key = req.params.key
let value = req.body
let result = await CollectionService.putCollectionMetadataValue(collectionId, key, value)
await CollectionService.putCollectionMetadataValue(collectionId, key, value)
res.status(204).send()
}
catch (err) {
Expand All @@ -488,7 +488,7 @@ module.exports.deleteCollectionMetadataKey = async function (req, res, next) {
try {
let collectionId = getCollectionIdAndCheckPermission(req)
let key = req.params.key
let result = await CollectionService.deleteCollectionMetadataKey(collectionId, key, req.userObject)
await CollectionService.deleteCollectionMetadataKey(collectionId, key, req.userObject)
res.status(204).send()
}
catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion api/source/controllers/Operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module.exports.replaceAppData = async function replaceAppData (req, res, next) {
appdata = req.body
}
let options = []
let response = await OperationService.replaceAppData(options, appdata, req.userObject, res )
await OperationService.replaceAppData(options, appdata, req.userObject, res )
}
else {
throw new SmError.PrivilegeError()
Expand Down
7 changes: 4 additions & 3 deletions api/source/controllers/Review.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ module.exports.putReviewMetadataValue = async function (req, res, next) {
if ( collectionGrant ) {
const userHasRule = await ReviewService.checkRuleByAssetUser( ruleId, assetId, req.userObject )
if (userHasRule) {
let response = await ReviewService.putReviewMetadataValue( assetId, ruleId, key, value)
await ReviewService.putReviewMetadataValue( assetId, ruleId, key, value)
res.status(204).send()
}
else {
Expand All @@ -369,7 +369,7 @@ module.exports.deleteReviewMetadataKey = async function (req, res, next) {
if ( collectionGrant ) {
const userHasRule = await ReviewService.checkRuleByAssetUser( ruleId, assetId, req.userObject )
if (userHasRule) {
let response = await ReviewService.deleteReviewMetadataKey( assetId, ruleId, key, req.userObject)
await ReviewService.deleteReviewMetadataKey( assetId, ruleId, key, req.userObject)
res.status(204).send()
}
else {
Expand All @@ -387,7 +387,8 @@ module.exports.deleteReviewMetadataKey = async function (req, res, next) {

module.exports.postReviewBatch = async function (req, res, next) {
try {
const { performance } = require('node:perf_hooks');

//const { performance } = require('node:perf_hooks');

const collectionId = Collection.getCollectionIdAndCheckPermission(req, Security.ACCESS_LEVEL.Restricted)
const collectionGrant = req.userObject.collectionGrants.find( g => g.collection.collectionId === collectionId )
Expand Down
6 changes: 1 addition & 5 deletions api/source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,8 @@ const STIGMAN = {

async function startServer(app) {
let db = require(`./service/utils`)
let isNewDb
try {
let authReturn
;[authReturn, isNewDb] = await Promise.all([auth.initializeAuth(), db.initializeDatabase()])
await Promise.all([auth.initializeAuth(), db.initializeDatabase()])
}
catch (e) {
logger.writeError('index', 'shutdown', {message:'Failed to setup dependencies', error: serializeError(e)});
Expand Down Expand Up @@ -257,7 +255,6 @@ async function startServer(app) {
function modulePathResolver( handlersPath, route, apiDoc ) {
const pathKey = route.openApiRoute.substring(route.basePath.length);
const schema = apiDoc.paths[pathKey][route.method.toLowerCase()];
// const [controller, method] = schema['operationId'].split('.');
const controller = schema.tags[0]
const method = schema['operationId']
const modulePath = path.join(handlersPath, controller);
Expand Down Expand Up @@ -285,5 +282,4 @@ function buildResponseValidationConfig() {
else {
return false
}

}
2 changes: 1 addition & 1 deletion api/source/service/AssetService.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ exports.cklbFromAssetStigs = async function cklbFromAssetStigs (assetId, stigs)
cklb.target_data.target_type = resultGetAsset[0].noncomputing ? 'Non-Computing' : 'Computing'
cklb.target_data.role = resultGetAsset[0].metadata.cklRole ?? 'None'
cklb.target_data.technology_area = resultGetAsset[0].metadata.cklTechArea ?? ''
cklb.target_data.is_web_database = resultGetAsset[0].metadata.cklHostName ? true : false
cklb.target_data.is_web_database = !!resultGetAsset[0].metadata.cklHostName
cklb.target_data.web_db_site = resultGetAsset[0].metadata.cklWebDbSite ?? ''
cklb.target_data.web_db_instance = resultGetAsset[0].metadata.cklWebDbInstance ?? ''

Expand Down
11 changes: 6 additions & 5 deletions api/source/service/CollectionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ exports.setStigAssetsByCollectionUser = async function(collectionId, userId, sti
}
let sqlInsertSaIds = `INSERT IGNORE INTO user_stig_asset_map (userId, saId) SELECT ?, saId FROM stig_asset_map WHERE `
sqlInsertSaIds += predicatesInsertSaIds.join('\nOR\n')
let [result] = await connection.execute(sqlInsertSaIds, bindsInsertSaIds)
await connection.execute(sqlInsertSaIds, bindsInsertSaIds)
}
await connection.commit()
}
Expand Down Expand Up @@ -1015,7 +1015,7 @@ exports.patchCollectionMetadata = async function ( collectionId, metadata ) {
where
collectionId = ?`
binds.push(JSON.stringify(metadata), collectionId)
let [rows] = await dbUtils.pool.query(sql, binds)
await dbUtils.pool.query(sql, binds)
return true
}

Expand All @@ -1029,7 +1029,7 @@ exports.putCollectionMetadata = async function ( collectionId, metadata ) {
where
collectionId = ?`
binds.push(JSON.stringify(metadata), collectionId)
let [rows] = await dbUtils.pool.query(sql, binds)
await dbUtils.pool.query(sql, binds)
return true
}

Expand Down Expand Up @@ -1223,8 +1223,9 @@ exports.getReviewHistoryStatsByCollection = async function (collectionId, startD
}

let sql = 'SELECT COUNT(*) as collectionHistoryEntryCount, MIN(rh.touchTs) as oldestHistoryEntryDate'

if (projection && projection.includes('asset')) {

// If there is a response and the request included the asset projection
if (projection?.includes('asset')) {
sql += `, coalesce(
(SELECT json_arrayagg(
json_object(
Expand Down
4 changes: 2 additions & 2 deletions api/source/service/MetricsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ module.exports.queryMetrics = async function ({
groupBy,
orderBy
})

let [rows, fields] = await dbUtils.pool.query(
let [ rows ] = await dbUtils.pool.query(
query,
[...cteProps.predicates.binds, ...predicates.binds]
)
Expand Down
17 changes: 1 addition & 16 deletions api/source/service/OperationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ exports.replaceAppData = async function (importOpts, appData, userObject, res )
])
}
for (const pin of c.stigs ?? []) {
if (pin.revisionPinned == true){
if (pin.revisionPinned){
let [input, version, release] = /V(\d+)R(\d+(\.\d+)?)/.exec(pin.revisionStr)
dml.collectionPins.insertBinds.push([
parseInt(c.collectionId),
Expand Down Expand Up @@ -511,21 +511,7 @@ exports.replaceAppData = async function (importOpts, appData, userObject, res )
stats[table].insert = `${result.affectedRows} in ${hrend[0]}s ${hrend[1] / 1000000}ms`
}
}

// // Stats
// res.write('Calculating status statistics\n')
// hrstart = process.hrtime();
// const statusStats = await dbUtils.updateStatsAssetStig( connection, {} )
// hrend = process.hrtime(hrstart)
// stats.stats = `${statusStats.affectedRows} in ${hrend[0]}s ${hrend[1] / 1000000}ms`

// // Commit
// hrstart = process.hrtime()
// res.write(`Starting commit\n`)
// await connection.query('COMMIT')
res.write(`Commit successful\n`)
// hrend = process.hrtime(hrstart)
// stats.commit = `${result.affectedRows} in ${hrend[0]}s ${hrend[1] / 1000000}ms`

// Stats
res.write('Calculating status statistics\n')
Expand Down Expand Up @@ -614,7 +600,6 @@ exports.getDetails = async function() {
dbUtils.pool.query(sqlCollectionAssetStigs)
])

const nameValuesReducer = (obj, item) => (obj[item.Variable_name] = item.Value, obj)
const schemaReducer = (obj, item) => (obj[item.tableName] = item, obj)

return ({
Expand Down
6 changes: 3 additions & 3 deletions api/source/service/ReviewService.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ from
await connection.query(sqlTempTable)

let validationErrors = []
let [table] = await connection.query('select * from validated_reviews')

let [counts] = await connection.query(`select
coalesce(sum(case when error is not null then 1 else 0 end),0) as failedValidations,
coalesce(sum(case when error is null and reviewId is null then 1 else 0 end),0) as inserts,
Expand Down Expand Up @@ -1420,7 +1420,7 @@ exports.patchReviewMetadata = async function ( assetId, ruleId, metadata ) {
review.assetId = ?
and rvcd.ruleId = ?`
binds.push(JSON.stringify(metadata), assetId, ruleId)
let [rows] = await dbUtils.pool.query(sql, binds)
await dbUtils.pool.query(sql, binds)
return true
}

Expand All @@ -1436,7 +1436,7 @@ exports.putReviewMetadata = async function ( assetId, ruleId, metadata ) {
review.assetId = ?
and rvcd.ruleId = ?`
binds.push(JSON.stringify(metadata), assetId, ruleId)
let [rows] = await dbUtils.pool.query(sql, binds)
await dbUtils.pool.query(sql, binds)
return true
}

Expand Down
Loading

0 comments on commit 30a35ac

Please sign in to comment.