Skip to content

Commit 7c6fc27

Browse files
fix(chore): fix sonar code smells (#86)
* fix(chore): fix sonar code smells resolving sonar code smells to improve quality gate GH-78 * fix(chore): fix sonar code smells Resolving sonar code smells to improve quality gate GH-78 * refactor(chore): fix sonar code smells and rebase GH-78 --------- Co-authored-by: Shubham P <[email protected]>
1 parent c4223d0 commit 7c6fc27

File tree

5 files changed

+41
-27
lines changed

5 files changed

+41
-27
lines changed

src/enhancer/spec-description-enhancer.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ export class DescSpecEnhancer implements OASEnhancer {
2020
modifySpec(spec: OpenAPIObject): OpenApiSpec {
2121
for (const controller of this.app.find(`${CoreBindings.CONTROLLERS}.*`)) {
2222
const ctor = controller.valueConstructor;
23-
if (ctor) {
24-
const endpoints = MetadataInspector.getAllMethodMetadata<RestEndpoint>(
25-
'openapi-v3:methods',
26-
ctor.prototype,
27-
);
28-
for (const route in endpoints) {
29-
const routeData = endpoints[route];
30-
if (
31-
routeData?.spec?.description &&
32-
!spec.paths[routeData.path][routeData.verb].description
33-
) {
34-
spec.paths[routeData.path][routeData.verb].description =
35-
routeData.spec.description;
36-
}
23+
if (!ctor) {
24+
continue;
25+
}
26+
const endpoints = MetadataInspector.getAllMethodMetadata<RestEndpoint>(
27+
'openapi-v3:methods',
28+
ctor.prototype,
29+
);
30+
for (const route in endpoints) {
31+
const routeData = endpoints[route];
32+
if (
33+
routeData?.spec?.description &&
34+
!spec.paths[routeData.path][routeData.verb].description
35+
) {
36+
spec.paths[routeData.path][routeData.verb].description =
37+
routeData.spec.description;
3738
}
3839
}
3940
}
40-
4141
return spec;
4242
}
4343
}

src/providers/authorization-action.provider.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,21 @@ export class AuthorizeActionProvider implements Provider<AuthorizeFn> {
2727

2828
if (request && this.checkIfAllowedAlways(request)) {
2929
return true;
30-
} else if (!metadata) {
30+
}
31+
32+
if (metadata) {
33+
if (metadata.permissions.indexOf('*') === 0) {
34+
// Return immediately with true, if allowed to all
35+
// This is for publicly open routes only
36+
return true;
37+
}
38+
} else {
3139
try {
3240
await this.requestContext.get(CoreBindings.CONTROLLER_METHOD_NAME);
3341
return false;
3442
} catch (error) {
3543
throw new HttpErrors.NotFound('API not found !');
3644
}
37-
} else if (metadata.permissions.indexOf('*') === 0) {
38-
// Return immediately with true, if allowed to all
39-
// This is for publicly open routes only
40-
return true;
4145
}
4246

4347
const permissionsToCheck = metadata.permissions;

src/providers/casbin-authorization-action.provider.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ export class CasbinAuthorizationProvider
4141

4242
if (request && this.checkIfAllowedAlways(request)) {
4343
return true;
44-
} else if (!metadata) {
45-
return false;
46-
} else if (metadata.permissions?.indexOf('*') === 0) {
44+
}
45+
46+
if (metadata?.permissions?.indexOf('*') === 0) {
4747
// Return immediately with true, if allowed to all
4848
// This is for publicly open routes only
4949
return true;
50-
} else if (!metadata.resource) {
50+
}
51+
52+
if (!metadata?.resource) {
53+
if (!metadata) {
54+
return false;
55+
}
5156
throw new HttpErrors.Unauthorized(
5257
`Resource parameter is missing in the decorator.`,
5358
);
@@ -56,7 +61,6 @@ export class CasbinAuthorizationProvider
5661
if (!user.id) {
5762
throw new HttpErrors.Unauthorized(`User not found.`);
5863
}
59-
6064
const subject = this.getUserName(`${user.id}`);
6165

6266
let desiredPermissions;

src/providers/casbin-enforcer-config.provider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import {HttpErrors} from '@loopback/rest';
66
export class CasbinEnforcerProvider
77
implements Provider<CasbinEnforcerConfigGetterFn>
88
{
9-
constructor() {}
9+
constructor() {
10+
//This is intentional
11+
}
1012

1113
value(): CasbinEnforcerConfigGetterFn {
1214
return async (

src/providers/user-permissions.provider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import {UserPermission, UserPermissionsFn} from '../types';
55
export class UserPermissionsProvider
66
implements Provider<UserPermissionsFn<string>>
77
{
8-
constructor() {}
8+
constructor() {
9+
//This is intentional
10+
}
911

1012
value(): UserPermissionsFn<string> {
1113
return (userPermissions, rolePermissions) =>
@@ -27,6 +29,8 @@ export class UserPermissionsProvider
2729
} else if (!userPerm.allowed && perms.indexOf(userPerm.permission) >= 0) {
2830
// Remove permission if it is disallowed for user
2931
perms.splice(perms.indexOf(userPerm.permission), 1);
32+
} else {
33+
//this is intentional
3034
}
3135
});
3236
return perms;

0 commit comments

Comments
 (0)