1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 07:01:12 +00:00

custom share permission (#4967)

* custom share permission

* remove path field

* add permission manager ui

* optimize custom permission manager style

* add permission setting

* add normalize_custom_permission_name

* optimize repo custom permission

* delete useless code

* optimize code

* optimize code

* optimize markdown file page

* fix a few bugs

* add permission control

* repair modify permission

* optimize style

* optimize copyright

* add try-except

* optimize code

* move file&folder

* batch operation item

* repair batch move item

* update copyright

* optimize move permission control

* optimize code

* optimize code

* optimize code & fix code wranning

* optimize code

* delete unsupport permission

* optimize code

* repair code bug

* add pro limit

* optimize code

* add permission handle for permission editor

* repair new file&folder bug

* optimize file uploader code

* custom permission user can not visit custom permission module

* optimize code

* forbid comment&detail module

* optimize code

* optimize modify/preview permission

* optimize custom permission share perm

* optimize view file module: file-toolbar

* optimize custom drag move operation

* repair column view bug

* optimize drag operation code

* repair code bug

* optimize code

Co-authored-by: shanshuirenjia <978987373@qq.com>
This commit is contained in:
王健辉
2021-09-13 10:37:07 +08:00
committed by GitHub
parent 1f68680257
commit 07df610e43
60 changed files with 1965 additions and 287 deletions

View File

@@ -73,6 +73,18 @@ class DirentListItem extends React.Component {
isPermissionDialogOpen: false,
isOpMenuOpen: false // for mobile
};
const { dirent } = this.props;
const { isCustomPermission, customPermission } = Utils.getUserPermission(dirent.permission);
this.isCustomPermission = isCustomPermission;
this.customPermission = customPermission;
this.canPreview = true;
this.canDrag = dirent.permission === 'rw';
if (isCustomPermission) {
const { preview, modify } = customPermission.permission;
this.canPreview = preview || modify;
this.canDrag = modify;
}
}
componentWillReceiveProps(nextProps) {
@@ -102,7 +114,9 @@ class DirentListItem extends React.Component {
isOperationShow: true,
});
}
this.setState({isDragTipShow: true});
if (this.canDrag) {
this.setState({isDragTipShow: true});
}
}
onMouseOver = () => {
@@ -112,7 +126,9 @@ class DirentListItem extends React.Component {
isOperationShow: true,
});
}
this.setState({isDragTipShow: true});
if (this.canDrag) {
this.setState({isDragTipShow: true});
}
}
onMouseLeave = () => {
@@ -175,6 +191,16 @@ class DirentListItem extends React.Component {
if (this.state.isRenameing) {
return;
}
if (dirent.isDir()) {
this.props.onItemClick(dirent);
return;
}
if (!this.canPreview) {
return;
}
if (Utils.imageCheck(dirent.name)) {
this.props.showImagePopup(dirent);
} else {
@@ -388,7 +414,7 @@ class DirentListItem extends React.Component {
}
onItemDragStart = (e) => {
if (Utils.isIEBrower()) {
if (Utils.isIEBrower() || !this.canDrag) {
return false;
}
e.dataTransfer.effectAllowed = 'move';
@@ -418,7 +444,7 @@ class DirentListItem extends React.Component {
}
onItemDragEnter = (e) => {
if (Utils.isIEBrower()) {
if (Utils.isIEBrower() || !this.canDrag) {
return false;
}
if (this.props.dirent.type === 'dir') {
@@ -428,7 +454,7 @@ class DirentListItem extends React.Component {
}
onItemDragOver = (e) => {
if (Utils.isIEBrower()) {
if (Utils.isIEBrower() || !this.canDrag) {
return false;
}
if (e.dataTransfer.dropEffect === 'copy') {
@@ -439,7 +465,7 @@ class DirentListItem extends React.Component {
}
onItemDragLeave = (e) => {
if (Utils.isIEBrower()) {
if (Utils.isIEBrower() || !this.canDrag) {
return false;
}
@@ -450,7 +476,7 @@ class DirentListItem extends React.Component {
}
onItemDragDrop = (e) => {
if (Utils.isIEBrower()) {
if (Utils.isIEBrower() || !this.canDrag) {
return false;
}
this.setState({isDropTipshow: false});
@@ -510,6 +536,14 @@ class DirentListItem extends React.Component {
renderItemOperation = () => {
let { dirent, currentRepoInfo, selectedDirentList } = this.props;
let canDownload = true;
let canDelete = true;
const { isCustomPermission, customPermission } = this;
if (isCustomPermission) {
const { permission } = customPermission;
canDownload = permission.download;
canDelete = permission.delete;
}
// https://dev.seafile.com/seahub/lib/d6f300e7-bb2b-4722-b83e-cf45e370bfbc/file/seaf-server%20%E5%8A%9F%E8%83%BD%E8%AE%BE%E8%AE%A1/%E6%9D%83%E9%99%90%E7%9B%B8%E5%85%B3/%E8%B5%84%E6%96%99%E5%BA%93%E6%9D%83%E9%99%90%E8%A7%84%E8%8C%83.md
let showShareBtn = Utils.isHasPermissionToShare(currentRepoInfo, dirent.permission, dirent);
@@ -526,6 +560,11 @@ class DirentListItem extends React.Component {
<i className="op-icon sf2-icon-download" title={gettext('Download')} onClick={this.onItemDownload}></i>
</li>
)}
{(isCustomPermission && canDownload) && (
<li className="operation-group-item">
<i className="op-icon sf2-icon-download" title={gettext('Download')} onClick={this.onItemDownload}></i>
</li>
)}
{showShareBtn && (
<li className="operation-group-item">
<i className="op-icon sf2-icon-share" title={gettext('Share')} onClick={this.onItemShare}></i>
@@ -536,6 +575,11 @@ class DirentListItem extends React.Component {
<i className="op-icon sf2-icon-delete" title={gettext('Delete')} onClick={this.onItemDelete}></i>
</li>
)}
{(isCustomPermission && canDelete) && (
<li className="operation-group-item">
<i className="op-icon sf2-icon-delete" title={gettext('Delete')} onClick={this.onItemDelete}></i>
</li>
)}
<li className="operation-group-item">
<ItemDropdownMenu
item={this.props.dirent}
@@ -560,12 +604,22 @@ class DirentListItem extends React.Component {
<i className="op-icon sf2-icon-download" title={gettext('Download')} onClick={this.onItemDownload}></i>
</li>
)}
{(isCustomPermission && canDownload) && (
<li className="operation-group-item">
<i className="op-icon sf2-icon-download" title={gettext('Download')} onClick={this.onItemDownload}></i>
</li>
)}
{showShareBtn && (
<li className="operation-group-item">
<i className="op-icon sf2-icon-share" title={gettext('Share')} onClick={this.onItemShare}></i>
</li>
)}
{dirent.permission === 'rw' && (
{(dirent.permission === 'rw') && (
<li className="operation-group-item">
<i className="op-icon sf2-icon-delete" title={gettext('Delete')} onClick={this.onItemDelete}></i>
</li>
)}
{(isCustomPermission && canDelete) && (
<li className="operation-group-item">
<i className="op-icon sf2-icon-delete" title={gettext('Delete')} onClick={this.onItemDelete}></i>
</li>
@@ -619,7 +673,7 @@ class DirentListItem extends React.Component {
const desktopItem = (
<tr
className={trClass}
draggable="true"
draggable={this.canDrag}
onMouseEnter={this.onMouseEnter}
onMouseOver={this.onMouseOver}
onMouseLeave={this.onMouseLeave}
@@ -650,10 +704,15 @@ class DirentListItem extends React.Component {
</div>
</td>
<td className="name">
{this.state.isRenameing ?
<Rename hasSuffix={dirent.type !== 'dir'} name={dirent.name} onRenameConfirm={this.onRenameConfirm} onRenameCancel={this.onRenameCancel} /> :
<a href={dirent.type === 'dir' ? dirHref : fileHref} onClick={this.onItemClick}>{dirent.name}</a>
}
{this.state.isRenameing && <Rename hasSuffix={dirent.type !== 'dir'} name={dirent.name} onRenameConfirm={this.onRenameConfirm} onRenameCancel={this.onRenameCancel} />}
{!this.state.isRenameing && (
<Fragment>
{(!dirent.isDir() && !this.canPreview) ?
<a className="sf-link" onClick={this.onItemClick}>{dirent.name}</a> :
<a href={dirent.type === 'dir' ? dirHref : fileHref} onClick={this.onItemClick}>{dirent.name}</a>
}
</Fragment>
)}
</td>
<td className="tag-list-title">
{(dirent.type !== 'dir' && dirent.file_tags && dirent.file_tags.length > 0) && (
@@ -689,10 +748,15 @@ class DirentListItem extends React.Component {
</div>
</td>
<td onClick={this.onItemClick}>
{this.state.isRenameing ?
<Rename hasSuffix={dirent.type !== 'dir'} name={dirent.name} onRenameConfirm={this.onRenameConfirm} onRenameCancel={this.onRenameCancel} /> :
<a href={dirent.type === 'dir' ? dirHref : fileHref}>{dirent.name}</a>
}
{this.state.isRenameing && <Rename hasSuffix={dirent.type !== 'dir'} name={dirent.name} onRenameConfirm={this.onRenameConfirm} onRenameCancel={this.onRenameCancel} /> }
{!this.state.isRenameing && (
<Fragment>
{(!dirent.isDir() && !this.canPreview) ?
<a className="sf-link">{dirent.name}</a> :
<a href={dirent.type === 'dir' ? dirHref : fileHref}>{dirent.name}</a>
}
</Fragment>
)}
<br />
{dirent.size && <span className="item-meta-info">{dirent.size}</span>}
<span className="item-meta-info">{dirent.mtime_relative}</span>

View File

@@ -83,6 +83,14 @@ class DirentListView extends React.Component {
this.currentItemRef = null;
this.zipToken = null;
const { userPerm } = props;
this.canDrop = userPerm === 'rw';
const { isCustomPermission, customPermission } = Utils.getUserPermission(userPerm);
if (isCustomPermission) {
const { modify } = customPermission.permission;
this.canDrop = modify;
}
}
freezeItem = () => {
@@ -315,12 +323,21 @@ class DirentListView extends React.Component {
event.preventDefault();
// Display menu items based on the permissions of the current path
let permission = this.props.userPerm;
if (permission !== 'admin' && permission !== 'rw') {
const { isCustomPermission, customPermission } = Utils.getUserPermission(this.props.userPerm);
if (permission !== 'admin' && permission !== 'rw' && !isCustomPermission) {
return;
}
if (this.props.selectedDirentList.length === 0) {
let id = 'dirent-container-menu';
// custom permission judgement
if (isCustomPermission) {
const { modify } = customPermission.permission;
if (!modify) return;
}
let menuList = [TextTranslation.NEW_FOLDER, TextTranslation.NEW_FILE];
this.handleContextClick(event, id, menuList);
} else {
@@ -334,6 +351,13 @@ class DirentListView extends React.Component {
this.onDirentClick(null);
event.preventDefault();
event.persist();
// custom permission judgement
if (isCustomPermission) {
const { modify } = customPermission.permission;
if (!modify) return;
}
setTimeout(() => {
let id = 'dirent-container-menu';
let menuList = [TextTranslation.NEW_FOLDER, TextTranslation.NEW_FILE];
@@ -342,7 +366,17 @@ class DirentListView extends React.Component {
}
} else {
let id = 'dirents-menu';
let menuList = [TextTranslation.MOVE, TextTranslation.COPY, TextTranslation.DOWNLOAD, TextTranslation.DELETE];
let menuList = [];
if (isCustomPermission) {
const { modify: canModify, copy: canCopy, download: canDownload, delete: canDelete } = customPermission.permission;
canModify && menuList.push(TextTranslation.MOVE);
canCopy && menuList.push(TextTranslation.COPY);
canDownload && menuList.push(TextTranslation.DOWNLOAD);
canDelete && menuList.push(TextTranslation.DELETE);
} else {
menuList = [TextTranslation.MOVE, TextTranslation.COPY, TextTranslation.DOWNLOAD, TextTranslation.DELETE];
}
this.handleContextClick(event, id, menuList);
}
}
@@ -448,7 +482,7 @@ class DirentListView extends React.Component {
}
onTableDragEnter = (e) => {
if (Utils.isIEBrower()) {
if (Utils.isIEBrower() || !this.canDrop) {
return false;
}
this.enteredCounter++;
@@ -461,7 +495,7 @@ class DirentListView extends React.Component {
}
onTableDragOver = (e) => {
if (Utils.isIEBrower()) {
if (Utils.isIEBrower() || !this.canDrop) {
return false;
}
if (e.dataTransfer.dropEffect === 'copy') {
@@ -472,7 +506,7 @@ class DirentListView extends React.Component {
}
onTableDragLeave = (e) => {
if (Utils.isIEBrower()) {
if (Utils.isIEBrower() || !this.canDrop) {
return false;
}
this.enteredCounter--;
@@ -482,7 +516,7 @@ class DirentListView extends React.Component {
}
tableDrop = (e) => {
if (Utils.isIEBrower()) {
if (Utils.isIEBrower() || !this.canDrop) {
return false;
}
e.persist();
@@ -540,7 +574,7 @@ class DirentListView extends React.Component {
return (
<div
className={`table-container ${this.state.isListDropTipShow ? 'table-drop-active' : ''}`}
className={`table-container ${(this.state.isListDropTipShow && this.canDrop) ? 'table-drop-active' : ''}`}
onMouseDown={this.onContainerMouseDown}
onContextMenu={this.onContainerContextMenu}
onClick={this.onContainerClick}