-
Notifications
You must be signed in to change notification settings - Fork 14
Add authorization to views #3284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
23f66de
:passport_control: introduice Authorize verification with correpondan…
b2a39ff
Some Tests
0b35751
Remove Groups (not user friendly experience)
285f1b3
Migration BD (remove Groups
0e52a62
Role Managament frontend
0c5755a
User's Role Management views are functionnals + fix small bugs
61fb6f0
Add first connected user to the default Administrators role
Metal-Mighty 0703625
Update style
Metal-Mighty 5a47677
Add volume for pgsql in docker compose
Metal-Mighty ce4e8dc
Fix device models update route
Metal-Mighty 88f3bd9
Add authorization checks on all views
Metal-Mighty 07b23c1
Various formatting
Metal-Mighty 7736c05
Improve debug Dockerfile
Metal-Mighty 9d7645f
Potential fix for code scanning alert no. 1916: Exposure of private i…
Metal-Mighty 8756622
Add Select All button in role edit
Metal-Mighty 190086d
Tests: Add mocked PermissionService
Metal-Mighty 31c174f
Tests: Add AuthContext for views tests
Metal-Mighty ffa01a9
Handle errors and tests changes
Metal-Mighty df51682
Fix unit tests
Metal-Mighty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
src/IoTHub.Portal.Application/Services/IGroupManagementService.cs
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Missed opportunity to use Where Note
Copilot Autofix
AI 7 months ago
In general, to fix a missed
Whereopportunity in aforeach, move the filtering logic that appears as anifguard inside the loop into a LINQWhereclause (or even directly intoAny/All/FirstOrDefaultetc., if the loop is only used for a boolean or search outcome). This reduces nesting, makes the predicate explicit, and improves readability.For this specific method,
UserHasPermissionAsynconly needs to know whether any access control has a role whose actions contain an entry matching the requestedpermission(case-insensitive). Instead of looping and returningtruefrom inside the loop, we can compute a boolean with a single LINQAnycall. Concretely, replace theforeachblock (lines 178–185) and the subsequentreturn false(line 186) with a single statement:This preserves the logic exactly:
trueif there exists at least oneacfor whichac.Role?.Actions != nulland at least one action name equalspermissionignoring case.falseotherwise, becauseAnyreturnsfalsewhen no element satisfies the predicate.No extra imports are needed:
System.Linqis already imported andAnyis part of LINQ. All changes are confined toUserHasPermissionAsyncinsrc/IoTHub.Portal.Application/Services/AccessControlService.cs.