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

repair share btn control bug

This commit is contained in:
shanshuirenjia
2019-06-21 17:54:06 +08:00
parent 1b1df904f5
commit d5d6472186
10 changed files with 67 additions and 51 deletions

View File

@@ -46,7 +46,6 @@ const propTypes = {
// list
isDirentListLoading: PropTypes.bool.isRequired,
direntList: PropTypes.array.isRequired,
showShareBtn: PropTypes.bool.isRequired,
sortBy: PropTypes.string.isRequired,
sortOrder: PropTypes.string.isRequired,
sortItems: PropTypes.func.isRequired,
@@ -205,7 +204,6 @@ class DirColumnView extends React.Component {
updateUsedRepoTags={this.props.updateUsedRepoTags}
isDirentListLoading={this.props.isDirentListLoading}
direntList={this.props.direntList}
showShareBtn={this.props.showShareBtn}
sortBy={this.props.sortBy}
sortOrder={this.props.sortOrder}
sortItems={this.props.sortItems}

View File

@@ -26,7 +26,6 @@ const propTypes = {
isDirentDetailShow: PropTypes.bool.isRequired,
enableDirPrivateShare: PropTypes.bool.isRequired,
updateDirent: PropTypes.func.isRequired,
showShareBtn: PropTypes.bool.isRequired,
showDirentDetail: PropTypes.func.isRequired,
onAddFolder: PropTypes.func.isRequired,
onFileTagChanged: PropTypes.func,
@@ -72,7 +71,6 @@ class DirGridView extends React.Component {
onItemCopy={this.props.onItemCopy}
isDirentListLoading={this.props.isDirentListLoading}
updateDirent={this.props.updateDirent}
showShareBtn={this.props.showShareBtn}
onRenameNode={this.props.onRenameNode}
showDirentDetail={this.props.showDirentDetail}
onGridItemClick={this.props.onGridItemClick}

View File

@@ -17,7 +17,6 @@ const propTypes = {
updateUsedRepoTags: PropTypes.func.isRequired,
isDirentListLoading: PropTypes.bool.isRequired,
direntList: PropTypes.array.isRequired,
showShareBtn: PropTypes.bool.isRequired,
sortBy: PropTypes.string.isRequired,
sortOrder: PropTypes.string.isRequired,
sortItems: PropTypes.func.isRequired,
@@ -75,7 +74,6 @@ class DirListView extends React.Component {
isGroupOwnedRepo={this.props.isGroupOwnedRepo}
enableDirPrivateShare={this.props.enableDirPrivateShare}
direntList={this.props.direntList}
showShareBtn={this.props.showShareBtn}
sortBy={this.props.sortBy}
sortOrder={this.props.sortOrder}
sortItems={this.props.sortItems}

View File

@@ -34,7 +34,6 @@ const propTypes = {
onItemClick: PropTypes.func.isRequired,
isDirentListLoading: PropTypes.bool.isRequired,
isGroupOwnedRepo: PropTypes.bool.isRequired,
showShareBtn: PropTypes.bool.isRequired,
enableDirPrivateShare: PropTypes.bool.isRequired,
updateDirent: PropTypes.func.isRequired,
isDirentDetailShow: PropTypes.bool.isRequired,
@@ -407,12 +406,15 @@ class DirentGridView extends React.Component{
let type = dirent.type;
let permission = dirent.permission;
let showShareBtn = Utils.isHasPermissionToShare(currentRepoInfo, permission, dirent);
let menuList = [];
let contextmenuList = [];
if (isContextmenu) {
let { SHARE, DOWNLOAD, DELETE } = TextTranslation;
contextmenuList = this.props.showShareBtn ? [SHARE] : [];
if (showShareBtn) {
contextmenuList = [SHARE];
}
if (dirent.permission === 'rw' || dirent.permission === 'r') {
contextmenuList = [...contextmenuList, DOWNLOAD];

View File

@@ -22,7 +22,6 @@ const propTypes = {
path: PropTypes.string.isRequired,
repoID: PropTypes.string.isRequired,
isItemFreezed: PropTypes.bool.isRequired,
showShareBtn: PropTypes.bool.isRequired,
dirent: PropTypes.object.isRequired,
onItemClick: PropTypes.func.isRequired,
freezeItem: PropTypes.func.isRequired,
@@ -458,10 +457,11 @@ class DirentListItem extends React.Component {
}
renderItemOperation = () => {
let { dirent, selectedDirentList, currentRepoInfo, showShareBtn } = this.props;
let { dirent, selectedDirentList, currentRepoInfo } = this.props;
if (currentRepoInfo.permission === 'cloud-edit' || currentRepoInfo.permission === 'preview') {
return '';
}
let showShareBtn = Utils.isHasPermissionToShare(currentRepoInfo, dirent.permission, dirent);
return (
<Fragment>

View File

@@ -25,7 +25,6 @@ const propTypes = {
isAllItemSelected: PropTypes.bool.isRequired,
isDirentListLoading: PropTypes.bool.isRequired,
direntList: PropTypes.array.isRequired,
showShareBtn: PropTypes.bool.isRequired,
sortBy: PropTypes.string.isRequired,
sortOrder: PropTypes.string.isRequired,
sortItems: PropTypes.func.isRequired,
@@ -468,13 +467,17 @@ class DirentListView extends React.Component {
let type = dirent.type;
let permission = dirent.permission;
let showShareBtn = Utils.isHasPermissionToShare(currentRepoInfo, permission, dirent);
let menuList = [];
let contextmenuList = [];
if (isContextmenu) {
let { SHARE, DOWNLOAD, DELETE } = TextTranslation;
contextmenuList = this.props.showShareBtn ? [SHARE] : [];
if (showShareBtn) {
contextmenuList = [SHARE];
}
if (dirent.permission === 'rw' || dirent.permission === 'r') {
contextmenuList = [...contextmenuList, DOWNLOAD];
@@ -485,14 +488,15 @@ class DirentListView extends React.Component {
}
contextmenuList = [...contextmenuList, 'Divider'];
}
let { RENAME, MOVE, COPY, PERMISSION, OPEN_VIA_CLIENT, LOCK, UNLOCK, COMMENT, HISTORY, ACCESS_LOG, TAGS } = TextTranslation;
if (type === 'dir' && permission === 'rw') {
if (can_set_folder_perm) {
menuList = [...menuList, RENAME, MOVE, COPY, 'Divider', PERMISSION, 'Divider', OPEN_VIA_CLIENT];
menuList = [...contextmenuList, RENAME, MOVE, COPY, 'Divider', PERMISSION, 'Divider', OPEN_VIA_CLIENT];
} else {
menuList = [...menuList, RENAME, MOVE, COPY, 'Divider', OPEN_VIA_CLIENT];
menuList = [...contextmenuList, RENAME, MOVE, COPY, 'Divider', OPEN_VIA_CLIENT];
}
return menuList;
}
@@ -659,7 +663,6 @@ class DirentListView extends React.Component {
repoEncrypted={this.repoEncrypted}
enableDirPrivateShare={this.props.enableDirPrivateShare}
isGroupOwnedRepo={this.props.isGroupOwnedRepo}
showShareBtn={this.props.showShareBtn}
onItemClick={this.props.onItemClick}
onItemRenameToggle={this.onItemRenameToggle}
onItemSelected={this.onItemSelected}

View File

@@ -32,7 +32,6 @@ const propTypes = {
onFilesTagChanged: PropTypes.func.isRequired,
unSelectDirent: PropTypes.func.isRequired,
updateDirent: PropTypes.func.isRequired,
showShareBtn: PropTypes.bool.isRequired,
};
class MutipleDirOperationToolbar extends React.Component {
@@ -90,18 +89,19 @@ class MutipleDirOperationToolbar extends React.Component {
getDirentMenuList = (dirent) => {
let menuList = [];
let currentRepoInfo = this.props.currentRepoInfo;
let showShareBtn = Utils.isHasPermissionToShare(currentRepoInfo, dirent.permission, dirent);
const { SHARE, TAGS, RELATED_FILES, HISTORY, ACCESS_LOG, OPEN_VIA_CLIENT, LOCK, UNLOCK } = TextTranslation;
if (dirent.type === 'dir') {
let shareBtn = this.props.showShareBtn ? [SHARE] : [];
menuList = [...shareBtn];
if (showShareBtn) {
menuList = [SHARE];
}
return menuList;
}
if (dirent.type === 'file') {
let shareBtn = (this.props.showShareBtn && canGenerateShareLink) ? [SHARE] : [];
let shareBtn = showShareBtn ? [SHARE] : [];
menuList = [...shareBtn, TAGS, RELATED_FILES, 'Divider', HISTORY, ACCESS_LOG, 'Divider', OPEN_VIA_CLIENT];
if (!Utils.isMarkdownFile(dirent.name)) {

View File

@@ -58,7 +58,6 @@ const propTypes = {
// list
isDirentListLoading: PropTypes.bool.isRequired,
direntList: PropTypes.array.isRequired,
showShareBtn: PropTypes.bool.isRequired,
sortBy: PropTypes.string.isRequired,
sortOrder: PropTypes.string.isRequired,
sortItems: PropTypes.func.isRequired,
@@ -203,7 +202,6 @@ class LibContentContainer extends React.Component {
updateUsedRepoTags={this.props.updateUsedRepoTags}
isDirentListLoading={this.props.isDirentListLoading}
direntList={this.props.direntList}
showShareBtn={this.props.showShareBtn}
sortBy={this.props.sortBy}
sortOrder={this.props.sortOrder}
sortItems={this.props.sortItems}
@@ -250,7 +248,6 @@ class LibContentContainer extends React.Component {
onItemCopy={this.props.onItemCopy}
updateDirent={this.props.updateDirent}
onAddFolder={this.props.onAddFolder}
showShareBtn={this.props.showShareBtn}
showDirentDetail={this.props.showDirentDetail}
onGridItemClick={this.onGridItemClick}
isDirentDetailShow={this.props.isDirentDetailShow}
@@ -295,7 +292,6 @@ class LibContentContainer extends React.Component {
updateUsedRepoTags={this.props.updateUsedRepoTags}
isDirentListLoading={this.props.isDirentListLoading}
direntList={this.props.direntList}
showShareBtn={this.props.showShareBtn}
sortBy={this.props.sortBy}
sortOrder={this.props.sortOrder}
sortItems={this.props.sortItems}

View File

@@ -1480,33 +1480,11 @@ class LibContentView extends React.Component {
return '';
}
let showShareBtn = false;
let enableDirPrivateShare = false;
let { currentRepoInfo, repoEncrypted, userPerm } = this.state;
let isAdmin = currentRepoInfo.is_admin;
let isVirtual = currentRepoInfo.is_virtual;
let { currentRepoInfo, userPerm } = this.state;
let showShareBtn = Utils.isHasPermissionToShare(currentRepoInfo, userPerm);
let isRepoOwner = currentRepoInfo.owner_email === username;
if (!repoEncrypted) {
let showGenerateShareLinkTab = false;
if (canGenerateShareLink && (userPerm == 'rw' || userPerm == 'r')) {
showGenerateShareLinkTab = true;
}
let showGenerateUploadLinkTab = false;
if (canGenerateUploadLink && (userPerm == 'rw')) {
showGenerateUploadLinkTab = true;
}
if (!isVirtual && (isRepoOwner || isAdmin)) {
enableDirPrivateShare = true;
}
if (showGenerateShareLinkTab || showGenerateUploadLinkTab || enableDirPrivateShare) {
showShareBtn = true;
}
}
let direntItemsList = this.state.direntList.filter((item, index) => {
return index < this.state.itemsShowLength;
});
@@ -1599,7 +1577,6 @@ class LibContentView extends React.Component {
updateUsedRepoTags={this.updateUsedRepoTags}
isDirentListLoading={this.state.isDirentListLoading}
direntList={direntItemsList}
showShareBtn={showShareBtn}
sortBy={this.state.sortBy}
sortOrder={this.state.sortOrder}
sortItems={this.sortItems}

View File

@@ -1,4 +1,4 @@
import { mediaUrl, gettext, serviceURL, siteRoot } from './constants';
import { mediaUrl, gettext, serviceURL, siteRoot, canGenerateShareLink, canGenerateUploadLink, username } from './constants';
import { strChineseFirstPY } from './pinyin-by-unicode';
export const Utils = {
@@ -901,6 +901,50 @@ export const Utils = {
}
return event.target.getAttribute('data-' + data);
},
/**
* judgement user is has the permission to share.
* one scence: current repo(the root path), in the toolbar
* two scence: selected a dirent, in the toolbar
* three scence: dirent list(grid list), in the item operation menu;
*
* @param {*} repoInfo
* @param {*} userDirPermission
* @param {*} dirent
*/
isHasPermissionToShare: function(repoInfo, userDirPermission, dirent) {
let hasPermissionToShare = false;
let hasDirPrivateSharePermission = false;
let { is_admin: isAdmin, is_virtual: isVirtual, encrypted: repoEncrypted, owner_email: ownerEmail } = repoInfo;
let isRepoOwner = ownerEmail === username;
// the root path or the dirent type is dir
if (!repoEncrypted) {
let hasGenerateShareLinkPermission = false;
if (canGenerateShareLink && (userDirPermission == 'rw' || userDirPermission == 'r')) {
hasGenerateShareLinkPermission = true;
}
let hasGenerateUploadLinkPermission = false;
if (canGenerateUploadLink && (userDirPermission == 'rw')) {
hasGenerateUploadLinkPermission = true;
}
if (!isVirtual && (isRepoOwner || isAdmin)) {
hasDirPrivateSharePermission = true;
}
if (hasGenerateShareLinkPermission || hasGenerateUploadLinkPermission || hasDirPrivateSharePermission) {
hasPermissionToShare = true;
}
}
if (dirent && dirent.type === 'file') {
return hasPermissionToShare && canGenerateShareLink;
}
return hasPermissionToShare;
}
};