Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions nae.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,21 +303,6 @@
},
"processUri": "/test"
},
"hidden-active-group": {
"component": {
"class": "ActiveGroupComponent",
"from": "./doc/active-group/active-group.component"
},
"access": "private",
"navigation": {
"title": "Active group view",
"icon": "coronavirus",
"hidden": false
},
"routing": {
"path": "active-group"
}
},
"demo-breadcrumbs": {
"component": {
"class": "BreadcrumbsExampleComponent",
Expand Down Expand Up @@ -850,17 +835,6 @@
}
}
},
"demo-active-group": {
"component": {
"class": "ActiveGroupComponent",
"from": "./doc/active-group/active-group.component"
},
"access": "private",
"navigation": true,
"routing": {
"path": "active-group"
}
},
"dashboard": {
"layout": {
"name": "dashboard",
Expand Down
4 changes: 0 additions & 4 deletions projects/nae-example-app/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ import {ResetPasswordFormComponent} from './doc/forms/reset-password-form/reset-
import {PublicTaskViewComponent} from './doc/public-task-view/public-task-view.component';
import {PublicWorkflowViewComponent} from './doc/public-workflow-view/public-workflow-view.component';
import {PublicResolverComponent} from './doc/public-resolver/public-resolver.component';
import {GroupViewComponent} from './doc/group-view/group-view.component';
import {
DemoTitleConfigContent0TaskViewComponent
} from './doc/demo-title-config/content/0/demo-title-config-content0-task-view.component';
Expand All @@ -115,7 +114,6 @@ import {
} from './doc/demo-title-config/content/3/demo-title-config-content3-case-view.component';
import {TitleConfigComponent} from './doc/demo-title-config/title-config.component';
import {ExampleRedirectComponent} from './doc/redirect/example-redirect.component';
import {ActiveGroupComponent} from './doc/active-group/active-group.component';
import {WrapperEmptyViewComponent} from './views/wrapper/wrapper-empty-view.component';
import {DoubleDrawerExampleComponent} from './doc/double-drawer-example/double-drawer-example.component';
import {PublicSingleTaskViewComponent} from './doc/public-single-task-view/public-single-task-view.component';
Expand Down Expand Up @@ -179,14 +177,12 @@ export function HttpLoaderFactory(http: HttpClient) {
PublicTaskViewComponent,
PublicWorkflowViewComponent,
PublicResolverComponent,
GroupViewComponent,
ExampleRedirectComponent,
DemoTitleConfigContent0TaskViewComponent,
DemoTitleConfigContent1CaseViewComponent,
DemoTitleConfigContent2CaseViewComponent,
DemoTitleConfigContent3CaseViewComponent,
TitleConfigComponent,
ActiveGroupComponent,
WrapperEmptyViewComponent,
DoubleDrawerExampleComponent,
PublicSingleTaskViewComponent,
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ import {LdapGroupRolesAssignComponent} from './doc/ldap-group-roles-assign/ldap-
import {TreeViewExampleComponent} from './doc/tree-view-example/tree-view-example.component';
import {UserInviteComponent} from './doc/user-invite/user-invite.component';
import {ResetPasswordFormComponent} from './doc/forms/reset-password-form/reset-password-form.component';
import {GroupViewComponent} from './doc/group-view/group-view.component';
import {TitleConfigComponent} from './doc/demo-title-config/title-config.component';
import {ExampleRedirectComponent} from './doc/redirect/example-redirect.component';
import {ActiveGroupComponent} from './doc/active-group/active-group.component';
import {WrapperEmptyViewComponent} from './views/wrapper/wrapper-empty-view.component';
import {DoubleDrawerExampleComponent} from './doc/double-drawer-example/double-drawer-example.component';
import {BreadcrumbsExampleComponent} from './doc/breadcrumbs-example/breadcrumbs-example.component';
Expand Down Expand Up @@ -63,9 +61,7 @@ export class NaeExampleAppViewService extends ViewService {
{id: 'TitleConfigComponent', class: TitleConfigComponent},
{id: 'PublicSingleTaskViewComponent', class: DefaultPublicSingleTaskViewComponent},
{id: 'WrapperEmptyViewComponent', class: WrapperEmptyViewComponent},
{id: 'ActiveGroupComponent', class: ActiveGroupComponent},
{id: 'ExampleRedirectComponent', class: ExampleRedirectComponent},
{id: 'GroupViewComponent', class: GroupViewComponent},
{id: 'UserInviteComponent', class: UserInviteComponent},
{id: 'TreeViewExampleComponent', class: TreeViewExampleComponent},
{id: 'ButtonsNavComponent', class: ButtonsNavComponent},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ describe('UserTransformer', () => {
lastName: 'string',
fullName: 'string string',
groups: [],
authorities: [{authority: 'ADMIN'}],
authorities: [{name: 'ADMIN', authority: 'ADMIN'}],
processRoles: [{stringId: 'string', description: 'desc', name: 'name', importId: 'importId'}],
nextGroups: [],
groupIds: [],
_links: {},
}).fullName).toEqual('string string');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export class UserTransformer implements Transformer<UserResource, User> {
user.lastName,
this.transformAuthorities(user.authorities),
user.processRoles,
groups,
user.nextGroups,
user.groupIds,
user.groups,
user.impersonated ? this.transform(user.impersonated) : undefined);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import {ConfigurationService} from '../../configuration/configuration.service';
import {LoggerService} from '../../logger/services/logger.service';
import {View} from '../../../commons/schema';
import {NextGroupService} from '../../groups/services/next-group.service';

@Injectable({
providedIn: AuthenticationModule
Expand All @@ -18,7 +17,6 @@

constructor(protected _redirectService: RedirectService,
protected _userService: UserService,
protected _nextGroupService: NextGroupService,
protected _configService: ConfigurationService,
protected _log: LoggerService) {
this._loginUrl = this._redirectService.resolveLoginPath();
Expand All @@ -39,7 +37,7 @@
} else {
allowedGroups = [view.access.group];
}
const groupOfUser = this._nextGroupService.groupOfUser.map(group => group.title);
const groupOfUser = this._userService.user.groups.map(group => group.displayName);

Check warning on line 40 in projects/netgrif-components-core/src/lib/authorization/group/group-guard.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

`groupOfUser` should be a `Set`, and use `groupOfUser.has()` to check existence or non-existence.

See more on https://sonarcloud.io/project/issues?id=netgrif_components&issues=AZzcjmhd6i_sKKncDyDh&open=AZzcjmhd6i_sKKncDyDh&pullRequest=317
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check User construction to verify groups is always an array
ast-grep --pattern $'new User($$$)'

Repository: netgrif/components

Length of output: 12371


🏁 Script executed:

# Find and examine the User class definition
fd User.ts projects/netgrif-components-core/src/lib/authentication/models/

Repository: netgrif/components

Length of output: 44


🏁 Script executed:

# Check the User class constructor
cat -n projects/netgrif-components-core/src/lib/authentication/models/user.model.ts | head -100

Repository: netgrif/components

Length of output: 170


🏁 Script executed:

# Get complete view of user.transformer.ts to see full context
cat -n projects/netgrif-components-core/src/lib/authentication/models/user.transformer.ts

Repository: netgrif/components

Length of output: 1361


🏁 Script executed:

# Find the User model file
fd -e ts User projects/netgrif-components-core/src/lib/user/models/

Repository: netgrif/components

Length of output: 44


🏁 Script executed:

# Search for User class definition in user directory
rg "class User" projects/netgrif-components-core/src/lib/user/

Repository: netgrif/components

Length of output: 771


🏁 Script executed:

# Get the User class definition
cat -n projects/netgrif-components-core/src/lib/user/models/user.ts

Repository: netgrif/components

Length of output: 2050


Potential runtime error: groups may be undefined.

The User class defines groups as an optional parameter (line 20 of user.ts: public groups?: Group[]), which means it can be undefined. While the emptyUser initializes it as an empty array, the UserTransformer passes user.groups directly from the API response without guarantee it's defined.

The code on line 40 calls .map() directly without null-checking:

const groupOfUser = this._userService.user.groups.map(group => group.displayName);

This will throw a runtime error if groups is undefined. Add a null-coalescing operator or defensive check:

const groupOfUser = this._userService.user.groups?.map(group => group.displayName) ?? [];
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@projects/netgrif-components-core/src/lib/authorization/group/group-guard.service.ts`
at line 40, The call to this._userService.user.groups.map(...) in
GroupGuardService (variable groupOfUser) can throw if user.groups is undefined;
update the logic that derives groupOfUser to safely handle a missing groups
array (use a null-coalescing or optional chaining fallback so groupOfUser
becomes an empty array when this._userService.user.groups is undefined) and keep
the rest of the guard logic unchanged.


return allowedGroups.some(groupTitle => {
return groupOfUser.includes(groupTitle);
Expand Down
Loading
Loading