Skip to content

Commit f3d95ab

Browse files
zhouwenxuanzhouwenxuan
authored andcommitted
check preview permission
1 parent 3a193e4 commit f3d95ab

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

frontend/src/metadata/context.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import LocalStorage from './utils/local-storage';
88
import EventBus from '../components/common/event-bus';
99
import { username, lang } from '../utils/constants';
10+
import { Utils } from '../utils/utils';
1011

1112
class Context {
1213

@@ -41,6 +42,8 @@ class Context {
4142
this.eventBus = eventBus;
4243

4344
this.permission = repoInfo.permission !== 'admin' && repoInfo.permission !== 'rw' ? 'r' : 'rw';
45+
const { isCustomPermission, customPermission } = Utils.getUserPermission(repoInfo.permission);
46+
this.customPermission = isCustomPermission ? customPermission : null;
4447

4548
this.hasInit = true;
4649
}
@@ -187,6 +190,14 @@ class Context {
187190
return true;
188191
};
189192

193+
canPreview = () => {
194+
if (this.customPermission) {
195+
const { preview, modify } = this.customPermission.permission;
196+
return preview || modify;
197+
}
198+
return true;
199+
};
200+
190201
restoreRows = () => {
191202
// todo
192203
};

frontend/src/metadata/utils/file.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ const _openOthers = (repoID, fileName, parentDir, fileType) => {
7474
};
7575

7676
export const openFile = (repoID, record, _openImage = () => {}) => {
77-
if (!record) return;
77+
const canPreview = window.sfMetadataContext.canPreview();
78+
if (!record || !canPreview) return;
7879
const fileName = getFileNameFromRecord(record);
7980
const isDir = checkIsDir(record);
8081
const parentDir = _getParentDir(record);
@@ -101,7 +102,8 @@ export const openFile = (repoID, record, _openImage = () => {}) => {
101102
};
102103

103104
export const openInNewTab = (repoID, record) => {
104-
if (!record) return;
105+
const canPreview = window.sfMetadataContext.canPreview();
106+
if (!record || !canPreview) return;
105107
const isDir = checkIsDir(record);
106108
const fileName = getFileNameFromRecord(record);
107109
const parentDir = _getParentDir(record);

frontend/src/metadata/views/table/masks/interaction-masks/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ class InteractionMasks extends React.Component {
451451
};
452452

453453
handleSpaceKeyDown = (e) => {
454+
e.preventDefault();
454455
e.stopPropagation();
455456
e.nativeEvent.stopImmediatePropagation();
456457
const repoID = window.sfMetadataContext.getSetting('repoID');

0 commit comments

Comments
 (0)