-
Notifications
You must be signed in to change notification settings - Fork 370
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
fix: [M3-7967] - Returning proper scope when selecting all perms #10359
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,7 @@ import { | |
StyledPermissionsCell, | ||
StyledPermsTable, | ||
} from './APITokenDrawer.styles'; | ||
import { | ||
basePermNameMap as _basePermNameMap, | ||
filterPermsNameMap, | ||
scopeStringToPermTuples, | ||
} from './utils'; | ||
import { basePermNameMap, scopeStringToPermTuples } from './utils'; | ||
|
||
interface Props { | ||
onClose: () => void; | ||
|
@@ -39,39 +35,13 @@ export const ViewAPITokenDrawer = (props: Props) => { | |
globalGrantType: 'child_account_access', | ||
}); | ||
|
||
const hasParentChildAccountAccess = Boolean(flags.parentChildAccountAccess); | ||
|
||
// @TODO: Parent/Child - once in GA, remove _basePermNameMap logic and references. | ||
// Just use the basePermNameMap import directly w/o any manipulation. | ||
const basePermNameMap = filterPermsNameMap(_basePermNameMap, [ | ||
{ | ||
name: 'child_account', | ||
shouldBeIncluded: hasParentChildAccountAccess, | ||
}, | ||
]); | ||
|
||
const allPermissions = scopeStringToPermTuples(token?.scopes ?? ''); | ||
|
||
/** | ||
* A parent user with child_account_access can issue a PAT with child_account scope. | ||
* If access is later revoked, we'll still display this scope for existing PATs, but not for new ones. | ||
* */ | ||
const hideChildAccountAccessScope = allPermissions.some( | ||
(scope) => | ||
scope[0] === 'child_account' && | ||
scope[1] === 0 && | ||
isChildAccountAccessRestricted | ||
); | ||
|
||
// Filter permissions for all users except parent user accounts. | ||
const showFilteredPermissions = | ||
!flags.parentChildAccountAccess || | ||
// Visually hide the "Child Account Access" permission even though it's still part of the base perms. | ||
const hideChildAccountAccessScope = | ||
profile?.user_type !== 'parent' || | ||
hideChildAccountAccessScope; | ||
|
||
const filteredPermissions = allPermissions.filter( | ||
(scopeTup) => basePermNameMap[scopeTup[0]] !== 'Child Account Access' | ||
); | ||
isChildAccountAccessRestricted || | ||
!flags.parentChildAccountAccess; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same logic as CreateAPITokenDrawer https://github.com/linode/manager/pull/10359/files#diff-d179f0d0f9fc3644a265f97bc10ba57f5e177c4c96b9960e7b9f779bb7c724aeR204-R207 can we keep things dry and util this logic? |
||
|
||
return ( | ||
<Drawer onClose={onClose} open={open} title={token?.label ?? 'Token'}> | ||
|
@@ -95,56 +65,58 @@ export const ViewAPITokenDrawer = (props: Props) => { | |
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{(showFilteredPermissions ? filteredPermissions : allPermissions).map( | ||
(scopeTup) => { | ||
if (!basePermNameMap[scopeTup[0]]) { | ||
return null; | ||
} | ||
return ( | ||
<TableRow | ||
data-qa-row={basePermNameMap[scopeTup[0]]} | ||
key={scopeTup[0]} | ||
> | ||
<StyledAccessCell padding="checkbox" parentColumn="Access"> | ||
{basePermNameMap[scopeTup[0]]} | ||
</StyledAccessCell> | ||
<StyledPermissionsCell padding="checkbox" parentColumn="None"> | ||
<AccessCell | ||
active={scopeTup[1] === 0} | ||
disabled={false} | ||
onChange={() => null} | ||
scope="0" | ||
scopeDisplay={scopeTup[0]} | ||
viewOnly={true} | ||
/> | ||
</StyledPermissionsCell> | ||
<StyledPermissionsCell | ||
padding="checkbox" | ||
parentColumn="Read Only" | ||
> | ||
<AccessCell | ||
active={scopeTup[1] === 1} | ||
disabled={false} | ||
onChange={() => null} | ||
scope="1" | ||
scopeDisplay={scopeTup[0]} | ||
viewOnly={true} | ||
/> | ||
</StyledPermissionsCell> | ||
<TableCell padding="checkbox" parentColumn="Read/Write"> | ||
<AccessCell | ||
active={scopeTup[1] === 2} | ||
disabled={false} | ||
onChange={() => null} | ||
scope="2" | ||
scopeDisplay={scopeTup[0]} | ||
viewOnly={true} | ||
/> | ||
</TableCell> | ||
</TableRow> | ||
); | ||
{allPermissions.map((scopeTup) => { | ||
if ( | ||
!basePermNameMap[scopeTup[0]] || | ||
(hideChildAccountAccessScope && | ||
basePermNameMap[scopeTup[0]] === 'Child Account Access') | ||
) { | ||
return null; | ||
} | ||
)} | ||
return ( | ||
<TableRow | ||
data-qa-row={basePermNameMap[scopeTup[0]]} | ||
key={scopeTup[0]} | ||
> | ||
<StyledAccessCell padding="checkbox" parentColumn="Access"> | ||
{basePermNameMap[scopeTup[0]]} | ||
</StyledAccessCell> | ||
<StyledPermissionsCell padding="checkbox" parentColumn="None"> | ||
<AccessCell | ||
active={scopeTup[1] === 0} | ||
disabled={false} | ||
onChange={() => null} | ||
scope="0" | ||
scopeDisplay={scopeTup[0]} | ||
viewOnly={true} | ||
/> | ||
</StyledPermissionsCell> | ||
<StyledPermissionsCell | ||
padding="checkbox" | ||
parentColumn="Read Only" | ||
> | ||
<AccessCell | ||
active={scopeTup[1] === 1} | ||
disabled={false} | ||
onChange={() => null} | ||
scope="1" | ||
scopeDisplay={scopeTup[0]} | ||
viewOnly={true} | ||
/> | ||
</StyledPermissionsCell> | ||
<TableCell padding="checkbox" parentColumn="Read/Write"> | ||
<AccessCell | ||
active={scopeTup[1] === 2} | ||
disabled={false} | ||
onChange={() => null} | ||
scope="2" | ||
scopeDisplay={scopeTup[0]} | ||
viewOnly={true} | ||
/> | ||
</TableCell> | ||
</TableRow> | ||
); | ||
})} | ||
</TableBody> | ||
</StyledPermsTable> | ||
</Drawer> | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scopeTup
- was wondering what it meant at first EDIT: This is whole thing is a bit hard to read because of naming conventions. naming it a tuple is ok-ish wondering if we can come up with something better.also:
const something =
renamedScopeTup[0]
const somethingElse =
renamedScopeTup[1]
or similar to improve readability?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it means "scope tuple", but agreed that this section of the code base isn't the most readable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be a follow up since this is a hotfix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted for followup βοΈ