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

CB-4961 Control files downloading ability #2744

Merged
merged 13 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
DATA_CONTEXT_DV_PRESENTATION,
DATA_VIEWER_DATA_MODEL_ACTIONS_MENU,
DataViewerPresentationType,
DataViewerService,
IDatabaseDataSource,
IDataContainerOptions,
} from '@cloudbeaver/plugin-data-viewer';
Expand All @@ -38,6 +39,7 @@ export class DataExportMenuService {
private readonly menuService: MenuService,
private readonly sessionPermissionsResource: SessionPermissionsResource,
private readonly localizationService: LocalizationService,
private readonly dataViewerService: DataViewerService,
) {}

register(): void {
Expand All @@ -60,6 +62,7 @@ export class DataExportMenuService {
id: 'data-export-base-handler',
menus: [DATA_VIEWER_DATA_MODEL_ACTIONS_MENU],
contexts: [DATA_CONTEXT_DV_DDM, DATA_CONTEXT_DV_DDM_RESULT_INDEX],
isHidden: (context, action) => !this.dataViewerService.canDownload,
actions: [ACTION_EXPORT],
isDisabled(context) {
const model = context.get(DATA_CONTEXT_DV_DDM)!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
import { selectFiles } from '@cloudbeaver/core-browser';
import { injectable } from '@cloudbeaver/core-di';
import { NotificationService } from '@cloudbeaver/core-events';
import { createResultSetBlobValue, ResultSetDataContentAction, ResultSetEditAction, ResultSetFormatAction } from '@cloudbeaver/plugin-data-viewer';
import {
createResultSetBlobValue,
DataViewerService,
ResultSetDataContentAction,
ResultSetEditAction,
ResultSetFormatAction,
} from '@cloudbeaver/plugin-data-viewer';

import { DataGridContextMenuService } from './DataGridContextMenuService';

Expand All @@ -17,6 +23,7 @@ export class DataGridContextMenuSaveContentService {
constructor(
private readonly dataGridContextMenuService: DataGridContextMenuService,
private readonly notificationService: NotificationService,
private readonly dataViewerService: DataViewerService,
) {}

register(): void {
Expand All @@ -38,7 +45,8 @@ export class DataGridContextMenuSaveContentService {
},
isHidden: context => {
const content = context.data.model.source.getAction(context.data.resultIndex, ResultSetDataContentAction);
return !content.isDownloadable(context.data.key);

return !content.isDownloadable(context.data.key) || !this.dataViewerService.canDownload;
},
isDisabled: context => {
const content = context.data.model.source.getAction(context.data.resultIndex, ResultSetDataContentAction);
Expand Down
4 changes: 4 additions & 0 deletions webapp/packages/plugin-data-viewer/src/DataViewerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export class DataViewerService {
return this.sessionPermissionsResource.has(EAdminPermission.admin) || !this.dataViewerSettingsService.disableCopyData;
}

get canDownload() {
return this.sessionPermissionsResource.has(EAdminPermission.admin) || !this.dataViewerSettingsService.disableDownload;
}

constructor(
private readonly dataViewerSettingsService: DataViewerSettingsService,
private readonly sessionPermissionsResource: SessionPermissionsResource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const DEFAULT_FETCH_SIZE = 200;
const defaultSettings = schema.object({
'plugin.data-viewer.disableEdit': schemaExtra.stringedBoolean().default(false),
'plugin.data-viewer.disableCopyData': schemaExtra.stringedBoolean().default(false),
'plugin.data-viewer.disableDownload': schemaExtra.stringedBoolean().default(false),
'plugin.data-viewer.fetchMin': schema.coerce.number().min(FETCH_MIN).default(DEFAULT_FETCH_SIZE),
'plugin.data-viewer.fetchMax': schema.coerce.number().min(FETCH_MIN).default(FETCH_MAX),
'resultset.maxrows': schema.coerce.number().min(FETCH_MIN).max(FETCH_MAX).default(DEFAULT_FETCH_SIZE),
Expand All @@ -45,6 +46,10 @@ export class DataViewerSettingsService extends Dependency {
return this.settings.getValue('plugin.data-viewer.disableCopyData');
}

get disableDownload(): boolean {
return this.settings.getValue('plugin.data-viewer.disableDownload');
}

get maxFetchSize(): number {
return this.settings.getValue('plugin.data-viewer.fetchMax');
}
Expand Down Expand Up @@ -127,6 +132,16 @@ export class DataViewerSettingsService extends Dependency {
description: 'settings_data_editor_disable_data_copy_description',
group: DATA_EDITOR_SETTINGS_GROUP,
},
{
key: 'plugin.data-viewer.disableDownload',
access: {
scope: ['server'],
},
type: ESettingsValueType.Checkbox,
name: 'settings_data_editor_disable_data_download_name',
description: 'settings_data_editor_disable_data_download_description',
group: DATA_EDITOR_SETTINGS_GROUP,
},
{
key: 'plugin.data-viewer.fetchMin',
access: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,23 @@ export const ImageValuePresentation: TabContainerPanelComponent<IDataValuePanelP
},
);

function imageOnContextMenuHandler(event: React.MouseEvent<HTMLImageElement>) {
Wroud marked this conversation as resolved.
Show resolved Hide resolved
if (!data.canSave) {
event.preventDefault();
}
}

return (
<Container vertical>
<Container fill overflow center>
<Loader suspense>
{data.src && <ImageRenderer srcGetter={srcGetter} className={s(style, { img: true, stretch: state.stretch })} />}
{data.src && (
<ImageRenderer
srcGetter={srcGetter}
className={s(style, { img: true, stretch: state.stretch })}
onContextMenu={imageOnContextMenuHandler}
/>
)}
{isTruncatedMessageDisplay && (
<QuotaPlaceholder model={data.model} resultIndex={data.resultIndex} elementKey={data.selectedCell}>
{isDownloadable && (
Expand Down Expand Up @@ -99,14 +111,15 @@ export const ImageValuePresentation: TabContainerPanelComponent<IDataValuePanelP
interface ImageRendererProps {
className?: string;
srcGetter: () => string | null;
onContextMenu?: (event: React.MouseEvent<HTMLImageElement>) => void;
}

export const ImageRenderer = observer<ImageRendererProps>(function ImageRenderer({ srcGetter, className }) {
export const ImageRenderer = observer<ImageRendererProps>(function ImageRenderer({ srcGetter, className, onContextMenu }) {
const src = srcGetter();

if (!src) {
return null;
}

return <img src={src} className={className} />;
return <img src={src} className={className} onContextMenu={onContextMenu} />;
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { ResultSetFormatAction } from '../../DatabaseDataModel/Actions/ResultSet
import { ResultSetSelectAction } from '../../DatabaseDataModel/Actions/ResultSet/ResultSetSelectAction';
import type { IDatabaseDataModel } from '../../DatabaseDataModel/IDatabaseDataModel';
import type { IDatabaseResultSet } from '../../DatabaseDataModel/IDatabaseResultSet';
import { DataViewerService } from '../../DataViewerService';

interface Props {
model: IDatabaseDataModel<any, IDatabaseResultSet>;
Expand All @@ -32,6 +33,7 @@ interface Props {

export function useValuePanelImageValue({ model, resultIndex }: Props) {
const notificationService = useService(NotificationService);
const dataViewerService = useService(DataViewerService);
const selectAction = model.source.getAction(resultIndex, ResultSetSelectAction);
const formatAction = model.source.getAction(resultIndex, ResultSetFormatAction);
const contentAction = model.source.getAction(resultIndex, ResultSetDataContentAction);
Expand Down Expand Up @@ -88,6 +90,10 @@ export function useValuePanelImageValue({ model, resultIndex }: Props) {
return this.contentAction.retrieveBlobFromCache(this.selectedCell);
},
get canSave() {
if (!this.dataViewerService.canDownload) {
return false;
}

if (this.truncated && this.selectedCell) {
return this.contentAction.isDownloadable(this.selectedCell);
}
Expand Down Expand Up @@ -158,6 +164,6 @@ export function useValuePanelImageValue({ model, resultIndex }: Props) {
upload: action.bound,
loadFullImage: action.bound,
},
{ model, resultIndex, notificationService, selectAction, formatAction, contentAction, editAction },
{ model, resultIndex, notificationService, selectAction, formatAction, contentAction, editAction, dataViewerService },
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ResultSetEditAction } from '../../DatabaseDataModel/Actions/ResultSet/R
import { ResultSetFormatAction } from '../../DatabaseDataModel/Actions/ResultSet/ResultSetFormatAction';
import { ResultSetSelectAction } from '../../DatabaseDataModel/Actions/ResultSet/ResultSetSelectAction';
import type { IDatabaseResultSet } from '../../DatabaseDataModel/IDatabaseResultSet';
import { DataViewerService } from '../../DataViewerService';
import type { IDataValuePanelProps } from '../../TableViewer/ValuePanel/DataValuePanelService';
import { getDefaultLineWrapping } from './getDefaultLineWrapping';
import { isTextValueReadonly } from './isTextValueReadonly';
Expand All @@ -36,6 +37,7 @@ export const TextValuePresentation: TabContainerPanelComponent<IDataValuePanelPr
const translate = useTranslate();
const notificationService = useService(NotificationService);
const textValuePresentationService = useService(TextValuePresentationService);
const dataViewerService = useService(DataViewerService);
const style = useS(styles, TextValuePresentationTab);
const selectAction = model.source.getAction(resultIndex, ResultSetSelectAction);
const formatAction = model.source.getAction(resultIndex, ResultSetFormatAction);
Expand Down Expand Up @@ -76,7 +78,7 @@ export const TextValuePresentation: TabContainerPanelComponent<IDataValuePanelPr
const autoLineWrapping = getDefaultLineWrapping(contentType);
const lineWrapping = state.lineWrapping ?? autoLineWrapping;
const isReadonly = isTextValueReadonly({ model, resultIndex, contentAction, cell: firstSelectedCell, formatAction });
const canSave = firstSelectedCell && contentAction.isDownloadable(firstSelectedCell);
const canSave = firstSelectedCell && contentAction.isDownloadable(firstSelectedCell) && dataViewerService.canDownload;

function valueChangeHandler(newValue: string) {
if (firstSelectedCell && !isReadonly) {
Expand Down
2 changes: 2 additions & 0 deletions webapp/packages/plugin-data-viewer/src/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export default [
['settings_data_editor_disable_edit_description', 'Deaktivieren Sie die Bearbeitung von Daten in Data Viewer für Nicht-Admin-Benutzer'],
['settings_data_editor_disable_data_copy_name', 'Kopie deaktivieren'],
['settings_data_editor_disable_data_copy_description', 'Deaktivieren Sie das Kopieren von Daten in Data Viewer für Nicht-Admin-Benutzer'],
['settings_data_editor_disable_data_download_name', 'Disable Download'],
['settings_data_editor_disable_data_download_description', 'Disable downloading of data in Data Viewer for non-admin users'],
['settings_data_editor_fetch_min_name', 'Minimale fetch size'],
['settings_data_editor_fetch_min_description', 'Mindestanzahl von Zeilen zum Abrufen'],
['settings_data_editor_fetch_max_name', 'Maximale fetch size'],
Expand Down
2 changes: 2 additions & 0 deletions webapp/packages/plugin-data-viewer/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export default [
['settings_data_editor_disable_edit_description', 'Disable editing of data in Data Viewer for non-admin users'],
['settings_data_editor_disable_data_copy_name', 'Disable Copy'],
['settings_data_editor_disable_data_copy_description', 'Disable copying of data in Data Viewer for non-admin users'],
['settings_data_editor_disable_data_download_name', 'Disable Download'],
['settings_data_editor_disable_data_download_description', 'Disable downloading of data in Data Viewer for non-admin users'],
['settings_data_editor_fetch_min_name', 'Minimum fetch size'],
['settings_data_editor_fetch_min_description', 'Minimum number of rows to fetch'],
['settings_data_editor_fetch_max_name', 'Maximum fetch size'],
Expand Down
2 changes: 2 additions & 0 deletions webapp/packages/plugin-data-viewer/src/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export default [
['settings_data_editor_disable_edit_name', "Désactiver l'édition"],
['settings_data_editor_disable_edit_description', "Désactiver l'édition des données dans le Data Viewer pour les utilisateurs non administrateurs"],
['settings_data_editor_disable_data_copy_name', 'Désactiver la copie'],
['settings_data_editor_disable_data_download_name', 'Disable Download'],
['settings_data_editor_disable_data_download_description', 'Disable downloading of data in Data Viewer for non-admin users'],
[
'settings_data_editor_disable_data_copy_description',
'Désactiver la copie des données dans le Data Viewer pour les utilisateurs non administrateurs',
Expand Down
2 changes: 2 additions & 0 deletions webapp/packages/plugin-data-viewer/src/locales/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export default [
['settings_data_editor_disable_edit_description', 'Disable editing of data in Data Viewer for non-admin users'],
['settings_data_editor_disable_data_copy_name', 'Disable Copy'],
['settings_data_editor_disable_data_copy_description', 'Disable copying of data in Data Viewer for non-admin users'],
['settings_data_editor_disable_data_download_name', 'Disable Download'],
['settings_data_editor_disable_data_download_description', 'Disable downloading of data in Data Viewer for non-admin users'],
['settings_data_editor_fetch_min_name', 'Minimum fetch size'],
['settings_data_editor_fetch_min_description', 'Minimum number of rows to fetch'],
['settings_data_editor_fetch_max_name', 'Maximum fetch size'],
Expand Down
2 changes: 2 additions & 0 deletions webapp/packages/plugin-data-viewer/src/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export default [
['settings_data_editor_disable_edit_description', 'Отключить редактирование данных для пользователей без прав администратора'],
['settings_data_editor_disable_data_copy_name', 'Отключить копирование'],
['settings_data_editor_disable_data_copy_description', 'Отключить копирование данных для пользователей без прав администратора'],
['settings_data_editor_disable_data_download_name', 'Отключить скачивание данных'],
['settings_data_editor_disable_data_download_description', 'Отключить скачивание данных для пользователей без прав администратора'],
['settings_data_editor_fetch_min_name', 'Минимальный размер выборки'],
['settings_data_editor_fetch_min_description', 'Минимальное количество строк для выборки'],
['settings_data_editor_fetch_max_name', 'Максимальный размер выборки'],
Expand Down
2 changes: 2 additions & 0 deletions webapp/packages/plugin-data-viewer/src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export default [
['settings_data_editor_disable_edit_description', 'Disable editing of data in Data Viewer for non-admin users'],
['settings_data_editor_disable_data_copy_name', 'Disable Copy'],
['settings_data_editor_disable_data_copy_description', 'Disable copying of data in Data Viewer for non-admin users'],
['settings_data_editor_disable_data_download_name', 'Disable Download'],
['settings_data_editor_disable_data_download_description', 'Disable downloading of data in Data Viewer for non-admin users'],
['settings_data_editor_fetch_min_name', 'Minimum fetch size'],
['settings_data_editor_fetch_min_description', 'Minimum number of rows to fetch'],
['settings_data_editor_fetch_max_name', 'Maximum fetch size'],
Expand Down
Loading