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 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
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
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 @@ -73,6 +78,7 @@ export class DataViewerSettingsService extends Dependency {
createSettingsAliasResolver(this.settingsResolverService, this.settings, {
'plugin.data-viewer.disableEdit': 'core.app.dataViewer.disableEdit',
'plugin.data-viewer.disableCopyData': 'core.app.dataViewer.disableCopyData',
'plugin.data-viewer.disableDownload': 'core.app.dataViewer.disableDownload',
Wroud marked this conversation as resolved.
Show resolved Hide resolved
'plugin.data-viewer.fetchMin': 'core.app.dataViewer.fetchMin',
'plugin.data-viewer.fetchMax': 'core.app.dataViewer.fetchMax',
'resultset.maxrows': 'core.app.dataViewer.fetchDefault',
Expand Down Expand Up @@ -127,6 +133,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 @@ -11,6 +11,7 @@ import { QuotasService } from '@cloudbeaver/core-root';
import { GraphQLService, ResultDataFormat } from '@cloudbeaver/core-sdk';
import { bytesToSize, download, downloadFromURL, GlobalConstants, isNotNullDefined } from '@cloudbeaver/core-utils';

import { DataViewerService } from '../../../DataViewerService';
import { DatabaseDataAction } from '../../DatabaseDataAction';
import type { IDatabaseDataSource } from '../../IDatabaseDataSource';
import type { IDatabaseResultSet } from '../../IDatabaseResultSet';
Expand Down Expand Up @@ -42,6 +43,7 @@ export class ResultSetDataContentAction extends DatabaseDataAction<any, IDatabas
private readonly graphQLService: GraphQLService,
private readonly quotasService: QuotasService,
private readonly cache: ResultSetCacheAction,
private readonly dataViewerService: DataViewerService,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not responsibility of database data model - it presents only database not hight level API or logic

) {
super(source);

Expand Down Expand Up @@ -100,7 +102,7 @@ export class ResultSetDataContentAction extends DatabaseDataAction<any, IDatabas
}

isDownloadable(element: IResultSetElementKey) {
return !!this.result.data?.hasRowIdentifier && isResultSetContentValue(this.format.get(element));
return !!this.result.data?.hasRowIdentifier && isResultSetContentValue(this.format.get(element)) && this.dataViewerService.canDownload;
}

retrieveFullTextFromCache(element: IResultSetElementKey) {
Expand Down
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 @@ -92,7 +94,7 @@ export function useValuePanelImageValue({ model, resultIndex }: Props) {
return this.contentAction.isDownloadable(this.selectedCell);
}

return this.staticSrc && !this.truncated;
return this.staticSrc && !this.truncated && this.dataViewerService.canDownload;
},
get canUpload() {
if (!this.selectedCell) {
Expand Down Expand Up @@ -158,6 +160,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 },
);
}
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