-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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(nav): infinite redirect and upload dataset nav permissions #19708
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,9 +34,11 @@ import { | |
import { DEFAULT_FETCH_RETRY_OPTIONS, DEFAULT_BASE_URL } from './constants'; | ||
|
||
const defaultUnauthorizedHandler = () => { | ||
window.location.href = `/login?next=${ | ||
window.location.pathname + window.location.search | ||
}`; | ||
if (!window.location.pathname.startsWith('/login')) { | ||
window.location.href = `/login?next=${ | ||
window.location.pathname + window.location.search | ||
}`; | ||
} | ||
}; | ||
|
||
export default class SupersetClientClass { | ||
|
@@ -161,7 +163,7 @@ export default class SupersetClientClass { | |
headers, | ||
timeout, | ||
fetchRetryOptions, | ||
ignoreUnauthorized, | ||
ignoreUnauthorized = false, | ||
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. Be more explicit what is the default. I kind of feel this should probably default to cc @geido @kgabryje could you give more context on why #17597 made redirects on 401 the default? 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. I strongly agree here, this behavior is quite surprising from an api client. Though I guess this approach involves the least amount of code changes. From a UX perspective I'd suggest presenting the user with the option to re-auth. There could be unsaved work that would be lost via a the redirect. 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. 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. I think we always want to redirect to login on a 401. 401 means that there's no auth token at all. 403 should be used if the user is forbidden, right? 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. 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. ahh i see. so we're fine with rendering some stuff even when a user is logged out. I guess that's fine then, carry on! 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. We will have a conversation about having the default to true and we'll follow up. Thank you! |
||
...rest | ||
}: RequestConfig & { parseMethod?: T }) { | ||
await this.ensureAuth(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,15 +105,15 @@ const RightMenu = ({ | |
const canChart = findPermission('can_write', 'Chart', roles); | ||
const canDatabase = findPermission('can_write', 'Database', roles); | ||
|
||
const { canUploadCSV, canUploadColumnar, canUploadExcel } = uploadUserPerms( | ||
roles, | ||
CSV_EXTENSIONS, | ||
COLUMNAR_EXTENSIONS, | ||
EXCEL_EXTENSIONS, | ||
ALLOWED_EXTENSIONS, | ||
); | ||
const { canUploadData, canUploadCSV, canUploadColumnar, canUploadExcel } = | ||
uploadUserPerms( | ||
roles, | ||
CSV_EXTENSIONS, | ||
COLUMNAR_EXTENSIONS, | ||
EXCEL_EXTENSIONS, | ||
ALLOWED_EXTENSIONS, | ||
); | ||
|
||
const canUpload = canUploadCSV || canUploadColumnar || canUploadExcel; | ||
const showActionDropdown = canSql || canChart || canDashboard; | ||
const [allowUploads, setAllowUploads] = useState<boolean>(false); | ||
const isAdmin = isUserAdmin(user); | ||
|
@@ -137,19 +137,19 @@ const RightMenu = ({ | |
label: t('Upload CSV to database'), | ||
name: 'Upload a CSV', | ||
url: '/csvtodatabaseview/form', | ||
perm: CSV_EXTENSIONS && showUploads, | ||
perm: canUploadCSV && showUploads, | ||
}, | ||
{ | ||
label: t('Upload columnar file to database'), | ||
name: 'Upload a Columnar file', | ||
url: '/columnartodatabaseview/form', | ||
perm: COLUMNAR_EXTENSIONS && showUploads, | ||
perm: canUploadColumnar && showUploads, | ||
}, | ||
{ | ||
label: t('Upload Excel file to database'), | ||
name: 'Upload Excel', | ||
url: '/exceltodatabaseview/form', | ||
perm: EXCEL_EXTENSIONS && showUploads, | ||
perm: canUploadExcel && showUploads, | ||
}, | ||
], | ||
}, | ||
|
@@ -176,7 +176,7 @@ const RightMenu = ({ | |
}, | ||
]; | ||
|
||
const hasFileUploadEnabled = () => { | ||
const checkAllowUploads = () => { | ||
const payload = { | ||
filters: [ | ||
{ col: 'allow_file_upload', opr: 'upload_is_enabled', value: true }, | ||
|
@@ -189,7 +189,11 @@ const RightMenu = ({ | |
}); | ||
}; | ||
|
||
useEffect(() => hasFileUploadEnabled(), []); | ||
useEffect(() => { | ||
if (canUploadData) { | ||
checkAllowUploads(); | ||
} | ||
}, [canUploadData]); | ||
|
||
const menuIconAndLabel = (menu: MenuObjectProps) => ( | ||
<> | ||
|
@@ -234,19 +238,21 @@ const RightMenu = ({ | |
}; | ||
|
||
const onMenuOpen = (openKeys: string[]) => { | ||
if (openKeys.length) { | ||
return hasFileUploadEnabled(); | ||
if (openKeys.length && canUploadData) { | ||
return checkAllowUploads(); | ||
} | ||
return null; | ||
}; | ||
|
||
return ( | ||
<StyledDiv align={align}> | ||
<DatabaseModal | ||
onHide={handleOnHideModal} | ||
show={showModal} | ||
dbEngine={engine} | ||
/> | ||
{canDatabase && ( | ||
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. Bycatch: only render the DatabaseModal when users can create new database connection. |
||
<DatabaseModal | ||
onHide={handleOnHideModal} | ||
show={showModal} | ||
dbEngine={engine} | ||
/> | ||
)} | ||
<Menu | ||
selectable={false} | ||
mode="horizontal" | ||
|
@@ -262,23 +268,31 @@ const RightMenu = ({ | |
icon={<Icons.TriangleDown />} | ||
> | ||
{dropdownItems.map(menu => { | ||
const canShowChild = menu.childs?.some( | ||
item => typeof item === 'object' && !!item.perm, | ||
); | ||
if (menu.childs) { | ||
return canDatabase || canUpload ? ( | ||
<SubMenu | ||
key={`sub2_${menu.label}`} | ||
className="data-menu" | ||
title={menuIconAndLabel(menu)} | ||
> | ||
{menu.childs.map((item, idx) => | ||
typeof item !== 'string' && item.name && item.perm ? ( | ||
<Fragment key={item.name}> | ||
{idx === 2 && <Menu.Divider />} | ||
{buildMenuItem(item)} | ||
</Fragment> | ||
) : null, | ||
)} | ||
</SubMenu> | ||
) : null; | ||
if (canShowChild) { | ||
return ( | ||
<SubMenu | ||
key={`sub2_${menu.label}`} | ||
className="data-menu" | ||
title={menuIconAndLabel(menu)} | ||
> | ||
{menu.childs.map((item, idx) => | ||
typeof item !== 'string' && item.name && item.perm ? ( | ||
<Fragment key={item.name}> | ||
{idx === 2 && <Menu.Divider />} | ||
{buildMenuItem(item)} | ||
</Fragment> | ||
) : null, | ||
)} | ||
</SubMenu> | ||
); | ||
} | ||
if (!menu.url) { | ||
return null; | ||
} | ||
} | ||
return ( | ||
findPermission( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,22 +240,22 @@ const SubMenuComponent: React.FunctionComponent<SubMenuProps> = props => { | |
if ((props.usesRouter || hasHistory) && !!tab.usesRouter) { | ||
return ( | ||
<Menu.Item key={tab.label}> | ||
<li | ||
<div | ||
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. Bycatch: fix a React warning about nested |
||
role="tab" | ||
data-test={tab['data-test']} | ||
className={tab.name === props.activeChild ? 'active' : ''} | ||
> | ||
<div> | ||
<Link to={tab.url || ''}>{tab.label}</Link> | ||
</div> | ||
</li> | ||
</div> | ||
</Menu.Item> | ||
); | ||
} | ||
|
||
return ( | ||
<Menu.Item key={tab.label}> | ||
<li | ||
<div | ||
className={cx('no-router', { | ||
active: tab.name === props.activeChild, | ||
})} | ||
|
@@ -264,7 +264,7 @@ const SubMenuComponent: React.FunctionComponent<SubMenuProps> = props => { | |
<a href={tab.url} onClick={tab.onClick}> | ||
{tab.label} | ||
</a> | ||
</li> | ||
</div> | ||
</Menu.Item> | ||
); | ||
})} | ||
|
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.
Only redirect when we are not on the login page so we never see infinite redirect caused by the API client ever again.