Skip to content

Commit

Permalink
feat: Update database permissions in async mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitor-Avila committed Feb 12, 2025
1 parent 0d87643 commit 5feb650
Show file tree
Hide file tree
Showing 17 changed files with 1,386 additions and 291 deletions.
65 changes: 65 additions & 0 deletions superset-frontend/src/pages/DatabaseList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ interface DatabaseDeleteObject extends DatabaseObject {
interface DatabaseListProps {
addDangerToast: (msg: string) => void;
addSuccessToast: (msg: string) => void;
addInfoToast: (msg: string) => void;
user: {
userId: string | number;
firstName: string;
Expand Down Expand Up @@ -101,6 +102,7 @@ function BooleanDisplay({ value }: { value: Boolean }) {

function DatabaseList({
addDangerToast,
addInfoToast,
addSuccessToast,
user,
}: DatabaseListProps) {
Expand All @@ -121,6 +123,9 @@ function DatabaseList({
const fullUser = useSelector<any, UserWithPermissionsAndRoles>(
state => state.user,
);
const shouldResyncPermsInAsyncMode = useSelector<any, boolean>(
state => state.common?.conf.RESYNC_DB_PERMISSIONS_IN_ASYNC_MODE,
);
const showDatabaseModal = getUrlParam(URL_PARAMS.showDatabaseModal);

const [query, setQuery] = useQueryParams({
Expand Down Expand Up @@ -426,6 +431,49 @@ function DatabaseList({
handleDatabaseEditModal({ database: original, modalOpen: true });
const handleDelete = () => openDatabaseDeleteModal(original);
const handleExport = () => handleDatabaseExport(original);
const handleResync = () => {
shouldResyncPermsInAsyncMode
? addInfoToast(
t('Validating connectivity for %s', original.database_name),
)
: addInfoToast(
t('Resyncing permissions for %s', original.database_name),
);
SupersetClient.post({
endpoint: `/api/v1/database/${original.id}/resync_permissions/`,
})
.then(({ response, json }) => {
// Sync request
if (response.status === 200) {
addSuccessToast(
t(
'Permissions successfully resynced for %s',
original.database_name,
),
);
}
// Async request
else {
addInfoToast(
t(
'Syncing permissions for %s in the background',
original.database_name,
),
);
}
})
.catch(
createErrorHandler(errMsg =>
addDangerToast(
t(
'An error occurred while resyncing permissions for %s: %s',
original.database_name,
errMsg,
),
),
),
);
};
if (!canEdit && !canDelete && !canExport) {
return null;
}
Expand Down Expand Up @@ -481,6 +529,23 @@ function DatabaseList({
</span>
</Tooltip>
)}
{canEdit && (
<Tooltip
id="resync-action-tooltip"
title={t('Resync Permissions')}
placement="bottom"
>
<span
role="button"
data-test="database-resync-perm"
tabIndex={0}
className="action-button"
onClick={handleResync}
>
<Icons.Refresh />
</span>
</Tooltip>
)}
</Actions>
);
},
Expand Down
6 changes: 3 additions & 3 deletions superset/commands/database/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def __init__(self, key: str = "") -> None:
)


class DatabaseConnectionNotWorkingError(CommandException):
status = 400
message = _("DB Connection not working, please check your connection settings.")
class DatabaseConnectionResyncPermissionsError(CommandException):
status = 500
message = _("Unable to resync permissions for this database connection.")


class DatabaseNotFoundError(CommandException):
Expand Down
Loading

0 comments on commit 5feb650

Please sign in to comment.