Skip to content
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

Cherry-pick plugin permissions from Enterprise #359

Merged
merged 3 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/code-studio/src/main/AppInit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,22 @@ const log = Log.module('AppInit');

// Default values used
const NAME = 'user';
const USER = { name: NAME, operateAs: NAME };
const USER = {
name: NAME,
operateAs: NAME,
groups: [],
permissions: {
isSuperUser: false,
isQueryViewOnly: false,
isNonInteractive: false,
canUsePanels: true,
canCreateDashboard: true,
canCreateCodeStudio: true,
canCreateQueryMonitor: true,
canCopy: true,
canDownloadCsv: true,
},
};
const WORKSPACE_STORAGE = new LocalWorkspaceStorage();
const COMMAND_HISTORY_STORAGE = new PouchCommandHistoryStorage();
const FILE_STORAGE = new WebdavFileStorage(
Expand Down
53 changes: 29 additions & 24 deletions packages/code-studio/src/main/AppMainContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
MarkdownPlugin,
PandasPlugin,
getDashboardSessionWrapper,
UIPropTypes,
} from '@deephaven/dashboard-core-plugins';
import ControlType from '@deephaven/dashboard-core-plugins/dist/controls/ControlType';
import ToolType from '@deephaven/dashboard-core-plugins/dist/linker/ToolType';
Expand Down Expand Up @@ -500,6 +501,8 @@ export class AppMainContainer extends Component {
const { data: workspaceData = {} } = workspace;
const { data = EMPTY_OBJECT, layoutConfig } = workspaceData;
const { layoutSettings = EMPTY_OBJECT } = data;
const { permissions } = user;
const { canUsePanels } = permissions;
const {
contextActions,
isPanelsMenuShown,
Expand Down Expand Up @@ -538,30 +541,32 @@ export class AppMainContainer extends Component {
onClearFilter={this.handleClearFilter}
/>
</button>
<button
type="button"
className="btn btn-link btn-panels-menu btn-show-panels"
data-testid="app-main-panels-button"
onClick={this.handleWidgetMenuClick}
>
<FontAwesomeIcon icon={dhPanels} />
Panels
<Popper
isShown={isPanelsMenuShown}
className="panels-menu-popper"
onExited={this.handleWidgetsMenuClose}
closeOnBlur
interactive
{canUsePanels && (
<button
type="button"
className="btn btn-link btn-panels-menu btn-show-panels"
data-testid="app-main-panels-button"
onClick={this.handleWidgetMenuClick}
>
<WidgetList
widgets={widgets}
onExportLayout={this.handleExportLayoutClick}
onImportLayout={this.handleImportLayoutClick}
onResetLayout={this.handleResetLayoutClick}
onSelect={this.handleWidgetSelect}
/>
</Popper>
</button>
<FontAwesomeIcon icon={dhPanels} />
Panels
<Popper
isShown={isPanelsMenuShown}
className="panels-menu-popper"
onExited={this.handleWidgetsMenuClose}
closeOnBlur
interactive
>
<WidgetList
widgets={widgets}
onExportLayout={this.handleExportLayoutClick}
onImportLayout={this.handleImportLayoutClick}
onResetLayout={this.handleResetLayoutClick}
onSelect={this.handleWidgetSelect}
/>
</Popper>
</button>
)}
<button
type="button"
className={classNames(
Expand Down Expand Up @@ -630,7 +635,7 @@ AppMainContainer.propTypes = {
session: APIPropTypes.IdeSession.isRequired,
setActiveTool: PropTypes.func.isRequired,
updateWorkspaceData: PropTypes.func.isRequired,
user: APIPropTypes.User.isRequired,
user: UIPropTypes.User.isRequired,
workspace: PropTypes.shape({
data: PropTypes.shape({
data: PropTypes.shape({}),
Expand Down
9 changes: 2 additions & 7 deletions packages/code-studio/src/main/AppMainContainer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { shallow } from 'enzyme';
import ToolType from '@deephaven/dashboard-core-plugins/dist/linker/ToolType';
import dh from '@deephaven/jsapi-shim';
import { TestUtils } from '@deephaven/utils';
import { AppMainContainer } from './AppMainContainer';
import LocalWorkspaceStorage from '../storage/LocalWorkspaceStorage';

Expand All @@ -19,13 +20,7 @@ function makeSession() {

function makeAppMainContainer({
layoutStorage = {},
user = {
name: 'name',
operateAs: 'operateAs',
groups: [],
isQueryViewOnly: false,
isSuperUser: false,
},
user = TestUtils.REGULAR_USER,
dashboardData = {},
saveWorkspace = jest.fn(() => Promise.resolve()),
updateWorkspaceData = jest.fn(() => Promise.resolve()),
Expand Down
1 change: 1 addition & 0 deletions packages/dashboard-core-plugins/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export { default as PandasPlugin } from './PandasPlugin';
export * from './events';
export * from './panels';
export * from './redux';
export * from './prop-types';
7 changes: 5 additions & 2 deletions packages/dashboard-core-plugins/src/panels/IrisGridPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
TableUtils,
} from '@deephaven/iris-grid';
import AdvancedSettings from '@deephaven/iris-grid/dist/sidebar/AdvancedSettings';
import { PropTypes as APIPropTypes } from '@deephaven/jsapi-shim';
import Log from '@deephaven/log';
import { getSettings, getUser, getWorkspace } from '@deephaven/redux';
import { PromiseUtils } from '@deephaven/utils';
Expand Down Expand Up @@ -869,6 +868,8 @@ export class IrisGridPanel extends PureComponent {
const childrenContent =
children ??
this.getPluginContent(Plugin, model?.table, user, workspace, pluginState);
const { permissions } = user;
const { canCopy, canDownloadCsv } = permissions;

return (
<WidgetPanel
Expand Down Expand Up @@ -937,6 +938,8 @@ export class IrisGridPanel extends PureComponent {
onAdvancedSettingsChange={this.handleAdvancedSettingsChange}
customFilters={pluginFilters}
pendingDataMap={pendingDataMap}
canCopy={canCopy}
canDownloadCsv={canDownloadCsv}
ref={this.irisGrid}
getDownloadWorker={getDownloadWorker}
>
Expand Down Expand Up @@ -979,7 +982,7 @@ IrisGridPanel.propTypes = {
columnSelectionValidator: PropTypes.func,
onStateChange: PropTypes.func,
onPanelStateUpdate: PropTypes.func,
user: APIPropTypes.User.isRequired,
user: UIPropTypes.User.isRequired,
workspace: PropTypes.shape({}).isRequired,
settings: PropTypes.shape({ timeZone: PropTypes.string.isRequired })
.isRequired,
Expand Down
18 changes: 18 additions & 0 deletions packages/dashboard-core-plugins/src/prop-types/UIPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,30 @@ const Link = PropTypes.shape({

const Links = PropTypes.arrayOf(Link);

const User = PropTypes.shape({
name: PropTypes.string.isRequired,
operateAs: PropTypes.string.isRequired,
groups: PropTypes.arrayOf(PropTypes.string).isRequired,
permissions: PropTypes.shape({
isSuperUser: PropTypes.bool.isRequired,
isQueryViewOnly: PropTypes.bool.isRequired,
isNonInteractive: PropTypes.bool.isRequired,
canUsePanels: PropTypes.bool.isRequired,
canCreateDashboard: PropTypes.bool.isRequired,
canCreateCodeStudio: PropTypes.bool.isRequired,
canCreateQueryMonitor: PropTypes.bool.isRequired,
canCopy: PropTypes.bool.isRequired,
canDownloadCsv: PropTypes.bool.isRequired,
}),
mofojed marked this conversation as resolved.
Show resolved Hide resolved
});

const UIPropTypes = Object.freeze({
InputFilter,
LinkPoint,
Link,
Links,
Panel,
User,
});

export default UIPropTypes;
Loading