Skip to content

Commit

Permalink
fix: enable admin to edit dataset in explore (#20613)
Browse files Browse the repository at this point in the history
* add conditional

* add test

* fix lint
  • Loading branch information
pkdotson committed Jul 8, 2022
1 parent 0ce0c6e commit e1a918f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,27 @@ test('Click on Edit dataset', async () => {
).toBeInTheDocument();
});

test('Edit dataset should be disabled when user is not admin', async () => {
const props = createProps();
// @ts-expect-error
props.user.roles = {};
props.datasource.owners = [];
SupersetClientGet.mockImplementation(
async () => ({ json: { result: [] } } as any),
);

render(<DatasourceControl {...props} />, {
useRedux: true,
});

userEvent.click(screen.getByTestId('datasource-menu-trigger'));

expect(screen.getByTestId('edit-dataset')).toHaveAttribute(
'aria-disabled',
'true',
);
});

test('Click on View in SQL Lab', async () => {
const props = createProps();
const postFormSpy = jest.spyOn(SupersetClient, 'postForm');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,9 @@ class DatasourceControl extends React.PureComponent {

const isSqlSupported = datasource.type === 'table';
const { user } = this.props;
const allowEdit = datasource.owners
?.map(o => o.id || o.value)
.includes(user.userId);
isUserAdmin(user);
const allowEdit =
datasource.owners?.map(o => o.id || o.value).includes(user.userId) ||
isUserAdmin(user);

const editText = t('Edit dataset');

Expand Down

0 comments on commit e1a918f

Please sign in to comment.