Skip to content

Commit

Permalink
Merge pull request #34 from NSWC-Crane/CHRIS_DEV
Browse files Browse the repository at this point in the history
General improvements and bug fixes
  • Loading branch information
crodriguez6497 authored Feb 7, 2024
2 parents 994d28e + e105a5a commit 3c56b94
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 176 deletions.
110 changes: 55 additions & 55 deletions Api/Services/mysql/permissionsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,59 +133,6 @@ exports.getPermissions_UserCollection = async function getPermissions_UserCollec
}

exports.postPermission = async function postPermission(req, res, next) {
// res.status(201).json({ message: "postPermission (Service) Method called successfully" });
// console.log("postPermission req.body: ", req.body)
if (!req.body.userId) {
console.info('postPermissions userId not provided.');
return next({
status: 422,
errors: {
userId: 'is required',
}
});
}

if (!req.body.collectionId) {
console.info('postPermissions collectionId not provided.');
return next({
status: 422,
errors: {
collectionId: 'is required',
}
});
}

if (!req.body.canOwn) req.body.canOwn = 0;
if (!req.body.canMaintain) req.body.canMaintain = 0;
if (!req.body.canApprove) req.body.canApprove = 0;
if (!req.body.canView) req.body.canView = 1;

try {
let connection
connection = await dbUtils.pool.getConnection()

let sql_query = `INSERT INTO poamtracking.collectionpermissions (userId, collectionId, canOwn, canMaintain, canApprove, canView) values (?, ?, ?, ?, ?, ?)`

await connection.query(sql_query, [req.body.userId, req.body.collectionId, req.body.canOwn, req.body.canMaintain, req.body.canApprove, req.body.canView])
await connection.release()

const message = new Object()
message.userId = req.body.userId
message.collectionId = req.body.collectionId
message.canOwn = req.body.canOwn
message.canMaintain = req.body.canMaintain
message.canApprove = req.body.canApprove
message.canView = req.body.canView
return(message)
}
catch (error) {
let errorResponse = { null: "null" }
await connection.release()
return errorResponse;
}
}

exports.putPermission = async function putPermission(req, res, next) {
// res.status(201).json({ message: "putPermission (Service) Method called successfully" });
// console.log("postPermission req.body: ", req.body)
if (!req.body.userId) {
Expand All @@ -199,11 +146,11 @@ exports.putPermission = async function putPermission(req, res, next) {
}

if (!req.body.collectionId) {
console.info('postPermissions collectionId not provided.');
console.info('postPermission collectionId not provided.');
return next({
status: 422,
errors: {
collectionId: 'is required',
oldCollectionId: 'is required',
}
});
}
Expand Down Expand Up @@ -239,6 +186,59 @@ exports.putPermission = async function putPermission(req, res, next) {
}
}

exports.putPermission = async function putPermission(req, res, next) {
// res.status(201).json({ message: "postPermission (Service) Method called successfully" });
// console.log("postPermission req.body: ", req.body)
if (!req.body.userId) {
console.info('postPermissions userId not provided.');
return next({
status: 422,
errors: {
userId: 'is required',
}
});
}

if (!req.body.oldCollectionId) {
console.info('putPermissions oldCollectionId not provided.');
return next({
status: 422,
errors: {
collectionId: 'is required',
}
});
}

if (!req.body.canOwn) req.body.canOwn = 0;
if (!req.body.canMaintain) req.body.canMaintain = 0;
if (!req.body.canApprove) req.body.canApprove = 0;
if (!req.body.canView) req.body.canView = 1;

try {
let connection
connection = await dbUtils.pool.getConnection()

let sql_query = "UPDATE poamtracking.collectionpermissions SET collectionId= ?, canOwn= ?, canMaintain= ?, canApprove= ?, canView= ? WHERE userId = ? AND collectionId = ?;"
await connection.query(sql_query, [req.body.newCollectionId, req.body.canOwn, req.body.canMaintain, req.body.canApprove, req.body.canView, req.body.userId, req.body.oldCollectionId])

await connection.release()

const message = new Object()
message.userId = req.body.userId
message.collectionId = req.body.collectionId
message.canOwn = req.body.canOwn
message.canMaintain = req.body.canMaintain
message.canApprove = req.body.canApprove
message.canView = req.body.canView
return(message)
}
catch (error) {
let errorResponse = { null: "null" }
await connection.release()
return errorResponse;
}
}

exports.deletePermission = async function deletePermission(req, res, next) {
// res.status(201).json({ message: "deletePermission (Service) Method called successfully" });
if (!req.params.userId) {
Expand Down
39 changes: 37 additions & 2 deletions Api/specification/poam-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/user_Permissions'
$ref: '#/components/schemas/update_user_Permissions'
responses:
'200':
description: return the updated collection permission response
Expand All @@ -1270,7 +1270,7 @@ paths:
schema:
type: array
items:
$ref: '#/components/schemas/user_Permissions'
$ref: '#/components/schemas/update_user_Permissions'
default:
description: unexpected error
content:
Expand Down Expand Up @@ -3004,6 +3004,41 @@ components:
userEmail:
type: string

update_user_Permissions:
type: object
required:
- userId
- oldCollectionId
- newCollectionId
- canOwn
- canMaintain
- canApprove
- canView
additionalProperties: true
properties:
userId:
type: integer
oldCollectionId:
type: integer
newCollectionId:
type: integer
canOwn:
type: boolean
canMaintain:
type: boolean
canApprove:
type: boolean
canView:
type: boolean
firstName:
type: string
lastName:
type: string
fullName:
type: string
userEmail:
type: string

userCreateOrReplace:
required:
- userName
Expand Down
26 changes: 3 additions & 23 deletions Front End/poam-app/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,18 @@

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
//import { HomeComponent } from './pages/home/home.component';
//import { PagesComponent } from './pages/pages.component';
import { PoamDetailsComponent } from './pages/poam-processing/poam-details/poam-details.component';
import { PoamApproveComponent } from './pages/poam-processing/poam-approve/poam-approve.component';
import { NbAuthComponent, NbLoginComponent, NbRegisterComponent, NbLogoutComponent, NbRequestPasswordComponent, NbResetPasswordComponent } from '@nebular/auth';
import { AuthGuard } from './auth.guard'
import { AppComponent } from './app.component';
import { LoginComponent } from './pages/login/login.component';
import { LoginCallbackComponent } from './pages/login/loginCallback.component';
import { DoDConsentComponent } from './pages/dod-consent/dod-consent.component';


const routes: Routes = [
//{ path: 'home', canActivate: [AuthGuard], component: PagesComponent},
{
path: '', canActivate: [AuthGuard],
component: AppComponent, //LoginComponent, //AppComponent,
},
{
path: 'login',
component: LoginComponent,
},
{
path: 'callback',
component: LoginCallbackComponent, //AppComponent,
},
//{ path: 'home', canActivate: [AuthGuard], loadChildren: () => import('./pages/poam-processing/poams.module').then(m => m.PoamsModule) },
//{path: '', redirectTo: 'poam-processing', pathMatch: 'full'},
//{ path: '', loadChildren: () => import('./auth/auth.module').then(m => m.AuthModule)},
//{ path: 'auth', loadChildren: () => import('./auth/auth.module').then(m => m.AuthModule)},
// { path: 'pages', canActivate: [AuthGuard], loadChildren: () => import('./pages/pages.module').then(m => m.PagesModule)},

{ path: '', canActivate: [AuthGuard], component: AppComponent },
{ path: 'login', component: LoginComponent },
{ path: 'callback', component: LoginCallbackComponent },
{ path: 'consent', loadChildren: () => import('./pages/dod-consent/dod-consent.module').then(m => m.DoDConsentModule) },
{ path: 'approve', loadChildren: () => import('./pages/poam-processing/poam-approve/poam-approve.module').then(m => m.PoamApproveModule) },
{ path: 'asset-processing', canActivate: [AuthGuard], loadChildren: () => import('./pages/asset-processing/asset-processing.module').then(m => m.AssetProcessingModule) },
Expand Down
8 changes: 3 additions & 5 deletions Front End/poam-app/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
! CONDITIONS OF THE LICENSE.
!########################################################################
*/

import { TreeGridModule } from '@syncfusion/ej2-angular-treegrid';
import { APP_INITIALIZER, NgModule } from '@angular/core';
import { APP_BASE_HREF } from "@angular/common";
Expand All @@ -15,14 +16,13 @@ import { FormsModule } from '@angular/forms';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { PoamDetailsComponent } from './pages/poam-processing/poam-details/poam-details.component';
import { DoDConsentComponent } from './pages/dod-consent/dod-consent.component';
import { CoreModule } from '../app/@core/core.module';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NbActionsModule, NbCardModule, NbDialogModule, NbMenuModule, NbSidebarModule, NbLayoutModule, NbAlertModule, NbSelectModule, NbIconModule, NbSpinnerModule, NbThemeModule, NbStepperModule, NbCheckboxModule, NbButtonModule, NbInputModule, NbAccordionModule} from '@nebular/theme';
import { LoginComponent } from './pages/login/login.component';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { HttpClientModule } from '@angular/common/http';
import { NbPasswordAuthStrategy, NbAuthModule, NbAuthResult, NbAuthJWTToken, NbOAuth2AuthStrategy, NbOAuth2ResponseType, NbOAuth2GrantType, NbAuthOAuth2Token, } from '@nebular/auth';
import { NbAuthModule, NbOAuth2AuthStrategy, NbOAuth2ResponseType, NbOAuth2GrantType, NbAuthOAuth2Token, } from '@nebular/auth';
import { AuthGuard } from "./auth.guard";
import { NbSecurityModule } from '@nebular/security';
import { SharedModule } from './Shared/shared.module';
Expand Down Expand Up @@ -57,21 +57,19 @@ function initializeKeycloak(keycloak: KeycloakService) {
AppComponent,
LoginComponent,
PoamDetailsComponent,
//DoDConsentComponent
],
providers: [AuthGuard,
KeycloakService,
{ provide: APP_BASE_HREF, useValue: "/" },
//{ provide: APP_INITIALIZER, useFactory: initializeKeycloak, multi: true, deps: [KeycloakService]},
KeycloakService,
{ provide: APP_INITIALIZER, useFactory: initializeKeycloak, multi: true, deps: [KeycloakService] },
AuthGuard,
KcAuthService,
RoleProvider,
FileUploadService,
],
bootstrap: [AppComponent],
exports: [
// PoamDetailsComponent,
],
imports: [
TreeGridModule,
Expand Down
30 changes: 1 addition & 29 deletions Front End/poam-app/src/app/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,8 @@

import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
import { AuthService } from './auth';
import { tap } from 'rxjs/operators';
import { KeycloakAuthGuard, KeycloakService } from 'keycloak-angular';

// @Injectable()
// export class AuthGuard implements CanActivate {

// constructor(
// private authService: AuthService,
// private router: Router
// ) {}

// canActivate() {
// console.log("Can activate...")
// return this.authService.isAuthenticated()
// .pipe(
// tap(authenticated => {
// if (!authenticated) {
// console.log("Can activate navigating to login NOT authenticated")
// this.router.navigate(['login']);
// } else {

// //authenticated = !authenticated;
// console.log("authenticated: ", authenticated)
// }
// }),
// );
// }
// }

@Injectable({
providedIn: 'root'
})
Expand All @@ -58,4 +30,4 @@ isAccessAllowed(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Prom
resolve(granted);
})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,22 @@ export class AssetComponent implements OnInit {

updateLabelEditorConfig() {
let settings = this.assetLabelsSettings;
let labelListValues = this.labelList.map((label: any) => ({
title: label.labelName,
value: label.labelId
}));

if (settings.columns['labelId']?.editor?.type === 'list' && settings.columns['labelId'].editor.config) {
let editorConfig = settings.columns['labelId'].editor.config as ListEditorSettings;
editorConfig.list = labelListValues;
this.assetLabelsSettings = Object.assign({}, settings);
} else {
console.error('Editor configuration for labelId is not set or not of type list');
const labelPlaceholder = { title: 'Select a Label...', value: '' };
editorConfig.list = [
labelPlaceholder,
...this.labelList.map((label: any) => ({
title: label.labelName,
value: label.labelId
}))
];
}
this.assetLabelsSettings = Object.assign({}, settings);
}



setCollection(collectionId: any) {
this.collection = null;
this.tcollectionName = '';
Expand Down
Loading

0 comments on commit 3c56b94

Please sign in to comment.