Skip to content

Commit

Permalink
Merge pull request #131 from open-template-hub/develop
Browse files Browse the repository at this point in the history
Release/sonar fix
  • Loading branch information
furknyavuz authored Jun 27, 2022
2 parents 24865a5 + f749b81 commit 114be25
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 64 deletions.
5 changes: 1 addition & 4 deletions app/consumer/auth-queue.consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ export class AuthQueueConsumer implements QueueConsumer {
private channel: any;
private ctxArgs: ContextArgs = {} as ContextArgs;

constructor() {
}

init = ( channel: string, ctxArgs: ContextArgs ) => {
this.channel = channel;
this.ctxArgs = ctxArgs;
Expand All @@ -24,7 +21,7 @@ export class AuthQueueConsumer implements QueueConsumer {
let requeue = false;

if ( message.example ) {
var exampleHook = async () => {
const exampleHook = async () => {
console.log( 'Auth server example' );
};

Expand Down
65 changes: 33 additions & 32 deletions app/controller/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ import { UserRepository } from '../repository/user.repository';
import { TwoFactorCodeController } from './two-factor.controller';

export class AuthController {
constructor(
private environment = new Environment(),
private tokenUtil: TokenUtil = new TokenUtil( environment.args() )
) {
/* intentionally blank */

environment: Environment;
tokenUtil: TokenUtil;

constructor() {
this.environment = new Environment();
this.tokenUtil = new TokenUtil( this.environment.args() );
}

/**
Expand Down Expand Up @@ -131,8 +133,8 @@ export class AuthController {
let dbUser = await userRepository.findUserByUsernameOrEmail( username );

// if user is not admin and origin is related with admin clients, do not permit to process
if(dbUser?.role && dbUser.role !== UserRole.ADMIN && process.env.ADMIN_CLIENT_URLS?.includes(origin)) {
let e = new Error("Bad Credentials") as HttpError;
if ( dbUser?.role && dbUser.role !== UserRole.ADMIN && process.env.ADMIN_CLIENT_URLS?.includes( origin ) ) {
let e = new Error( 'Bad Credentials' ) as HttpError;
e.responseCode = ResponseCode.FORBIDDEN;
throw e;
}
Expand Down Expand Up @@ -223,7 +225,6 @@ export class AuthController {
verify = async (
db: PostgreSqlProvider,
token: string,
languageCode?: string
) => {
const user: any = this.tokenUtil.verifyVerificationToken( token );

Expand Down Expand Up @@ -372,48 +373,48 @@ export class AuthController {
}

getUsers = async (
db: PostgreSqlProvider,
role?: string,
verified?: any,
oauth?: any,
twoFA?: any,
username?: string,
offset?: number,
limit?: number
db: PostgreSqlProvider,
role?: string,
verified?: any,
oauth?: any,
twoFA?: any,
username?: string,
offset?: number,
limit?: number
) => {
const userRepository = new UserRepository(db);
const userRepository = new UserRepository( db );

if(role === 'All') {
if ( role === 'All' ) {
role = '';
}

if(verified === 'true') {
verified = true
} else if(verified === 'false') {
verified = false
if ( verified === 'true' ) {
verified = true;
} else if ( verified === 'false' ) {
verified = false;
}

if(twoFA === 'true') {
twoFA = true
} else if(twoFA === 'false') {
twoFA = false
if ( twoFA === 'true' ) {
twoFA = true;
} else if ( twoFA === 'false' ) {
twoFA = false;
}

if(!offset) {
if ( !offset ) {
offset = 0;
}

if(!limit) {
if ( !limit ) {
limit = 20;
}

let users: any[] = []
let users: any[] = [];
let count: any;

users = await userRepository.getAllUsers(role ?? '', verified, twoFA, oauth, username ?? '', offset, limit);
count = +(await userRepository.getAllUsersCount(role ?? '', verified, twoFA, oauth, username ?? '')).count ?? 0;
users = await userRepository.getAllUsers( role ?? '', verified, twoFA, oauth, username ?? '', offset, limit );
count = +( await userRepository.getAllUsersCount( role ?? '', verified, twoFA, oauth, username ?? '' ) ).count ?? 0;

return { users, meta: { offset, limit, count } };
}
};
}

20 changes: 13 additions & 7 deletions app/controller/social-login.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ import { UserRepository } from '../repository/user.repository';
import { TwoFactorCodeController } from './two-factor.controller';

export class SocialLoginController {
constructor(
private builder = new BuilderUtil(),
private parser = new ParserUtil(),
private environment = new Environment(),
private encryptionUtil = new EncryptionUtil( environment.args() ),
private tokenUtil: TokenUtil = new TokenUtil( environment.args() )
) {

builder: BuilderUtil;
parser: ParserUtil;
environment: Environment;
encryptionUtil: EncryptionUtil;
tokenUtil: TokenUtil;

constructor() {
this.builder = new BuilderUtil();
this.parser = new ParserUtil();
this.environment = new Environment();
this.encryptionUtil = new EncryptionUtil( this.environment.args() );
this.tokenUtil = new TokenUtil( this.environment.args() );
}

/**
Expand Down
15 changes: 4 additions & 11 deletions app/controller/two-factor.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
SmsActionType,
TokenUtil,
TwoFactorCodeRequestParams,
User
} from '@open-template-hub/common';
import crypto from 'crypto';
import { Environment } from '../../environment';
Expand All @@ -18,10 +17,10 @@ import { UserRepository } from '../repository/user.repository';
import { AuthController } from './auth.controller';

export class TwoFactorCodeController {
constructor(
private environment = new Environment()
) {
// intentionally blank

environment: Environment;
constructor() {
this.environment = new Environment();
}

request = async (
Expand Down Expand Up @@ -94,7 +93,6 @@ export class TwoFactorCodeController {

loginVerify = async (
db: PostgreSqlProvider,
messageQueueProvider: MessageQueueProvider,
code: string,
preAuthToken: string
) => {
Expand All @@ -115,11 +113,6 @@ export class TwoFactorCodeController {
const userRepository = new UserRepository( db );
let dbUser = await userRepository.findUserByUsernameOrEmail( decrpytedPreAuthToken.username as string );

const user = {
username: dbUser.username,
password: dbUser.password,
} as User;

const authController = new AuthController();
return authController.twoFactorVerifiedLogin( db, dbUser );
};
Expand Down
10 changes: 5 additions & 5 deletions app/route/auth.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ router.delete(
router.get(
subRoutes.submittedPhoneNumber,
authorizedBy( [ UserRole.ADMIN, UserRole.DEFAULT ] ),
async ( req: Request, res: Response ) => {
async ( _req: Request, res: Response ) => {
const authController = new AuthController();
const context = res.locals.ctx;
const submittedPhoneNumber = await authController.getSubmittedPhoneNumber(
Expand All @@ -173,7 +173,7 @@ router.get(
router.delete(
subRoutes.submittedPhoneNumber,
authorizedBy( [ UserRole.ADMIN, UserRole.DEFAULT ] ),
async ( req: Request, res: Response ) => {
async ( _req: Request, res: Response ) => {
const authController = new AuthController();
const context = res.locals.ctx;
await authController.deleteSubmittedPhoneNumber(
Expand All @@ -187,10 +187,10 @@ router.delete(
router.get(
subRoutes.users,
authorizedBy([UserRole.ADMIN, UserRole.DEFAULT]),
async(req: Request, res: Response) => {
async(req: Request, res: Response) => {
const authController = new AuthController();
const context = res.locals.ctx;

const users = await authController.getUsers(
context.postgresql_provider,
req.query.role as string,
Expand All @@ -204,4 +204,4 @@ router.get(

res.status(ResponseCode.OK).json(users);
}
)
)
2 changes: 1 addition & 1 deletion app/route/index.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export namespace Routes {
applicationName: 'AuthServer',
} as MountAssets;

var routes: Array<Route> = [];
const routes: Array<Route> = [];

routes.push( { name: subRoutes.auth, router: authRouter } );
routes.push( { name: subRoutes.info, router: infoRouter } );
Expand Down
2 changes: 1 addition & 1 deletion app/route/info.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const infoController = new InfoController();
router.get(
subRoutes.me,
authorizedBy( [ UserRole.ADMIN, UserRole.DEFAULT ] ),
async ( req: Request, res: Response ) => {
async ( _req: Request, res: Response ) => {
// gets user info
const context = res.locals.ctx;
const response = await infoController.me(
Expand Down
2 changes: 1 addition & 1 deletion app/route/monitor.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const subRoutes = {

export const router = Router();

router.get( subRoutes.alive, async ( req: Request, res: Response ) => {
router.get( subRoutes.alive, async ( _req: Request, res: Response ) => {
// check system is alive
res.status( ResponseCode.OK ).json( { version } );
} );
1 change: 0 additions & 1 deletion app/route/two-factor-code.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ router.post( subRoutes.loginVerify, async ( req: Request, res: Response ) => {

const loginVerifyResponse = await twoFactorCodeController.loginVerify(
context.postgresql_provider,
context.message_queue_provider,
req.body.code,
req.body.preAuthToken
);
Expand Down
14 changes: 13 additions & 1 deletion dependency-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const lines = outdatedCmd.stdout.toString().split( '\n' );

const columnIndexes = [ 0, 0, 0, 0 ];

let indexOfDependedBy = -1;

console.log(
'<p align="center">\n' +
' <a href="https://opentemplatehub.com">\n' +
Expand Down Expand Up @@ -41,7 +43,17 @@ for ( const line of lines ) {

modifiedLine += '| ';

for ( let part of stringParts ) {
for ( let i = 0; i < stringParts.length; ++i ) {
const part = stringParts[ i ];

if ( lines.indexOf( line ) === 0 && i < stringParts.length - 1 && stringParts[ i + 1 ] === 'Depended' ) {
indexOfDependedBy = i;
}

if ( indexOfDependedBy !== -1 && i >= indexOfDependedBy ) {
continue;
}

if ( part.match( /\s+/ ) ) {
modifiedLine += ' | ';
} else {
Expand Down

0 comments on commit 114be25

Please sign in to comment.