mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-18 06:57:52 +00:00
optimized code
This commit is contained in:
parent
d5d6472186
commit
a09770720e
@ -904,47 +904,53 @@ export const Utils = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* judgement user is has the permission to share.
|
* Check whether user has permission to share a dirent.
|
||||||
* one scence: current repo(the root path), in the toolbar
|
* If dirent is none, then check whether the user can share the repo
|
||||||
* two scence: selected a dirent, in the toolbar
|
* scence 1: root path or folder path, control the share button in the toolbar
|
||||||
* three scence: dirent list(grid list), in the item operation menu;
|
* scence 2: selected a dirent, control the share button in the toolbar dropdown-menu
|
||||||
|
* scence 3: dirent list(grid list), control the share button in the dirent-item or righe-menu
|
||||||
*
|
*
|
||||||
* @param {*} repoInfo
|
* @param {*} repoInfo
|
||||||
* @param {*} userDirPermission
|
* @param {*} userDirPermission
|
||||||
* @param {*} dirent
|
* @param {*} dirent
|
||||||
*/
|
*/
|
||||||
isHasPermissionToShare: function(repoInfo, userDirPermission, 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 { is_admin: isAdmin, is_virtual: isVirtual, encrypted: repoEncrypted, owner_email: ownerEmail } = repoInfo;
|
||||||
let isRepoOwner = ownerEmail === username;
|
let isRepoOwner = ownerEmail === username;
|
||||||
|
|
||||||
// the root path or the dirent type is dir
|
if (repoEncrypted) {
|
||||||
if (!repoEncrypted) {
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dirent && dirent.type === 'file') {
|
||||||
let hasGenerateShareLinkPermission = false;
|
let hasGenerateShareLinkPermission = false;
|
||||||
if (canGenerateShareLink && (userDirPermission == 'rw' || userDirPermission == 'r')) {
|
if (canGenerateShareLink && (userDirPermission == 'rw' || userDirPermission == 'r')) {
|
||||||
hasGenerateShareLinkPermission = true;
|
hasGenerateShareLinkPermission = true;
|
||||||
}
|
}
|
||||||
let hasGenerateUploadLinkPermission = false;
|
return hasGenerateShareLinkPermission;
|
||||||
if (canGenerateUploadLink && (userDirPermission == 'rw')) {
|
|
||||||
hasGenerateUploadLinkPermission = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isVirtual && (isRepoOwner || isAdmin)) {
|
|
||||||
hasDirPrivateSharePermission = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasGenerateShareLinkPermission || hasGenerateUploadLinkPermission || hasDirPrivateSharePermission) {
|
|
||||||
hasPermissionToShare = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dirent && dirent.type === 'file') {
|
// the root path or the dirent type is dir
|
||||||
return hasPermissionToShare && canGenerateShareLink;
|
let hasGenerateShareLinkPermission = false;
|
||||||
|
if (canGenerateShareLink && (userDirPermission == 'rw' || userDirPermission == 'r')) {
|
||||||
|
hasGenerateShareLinkPermission = true;
|
||||||
|
return hasGenerateShareLinkPermission;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hasPermissionToShare;
|
let hasGenerateUploadLinkPermission = false;
|
||||||
|
if (canGenerateUploadLink && (userDirPermission == 'rw')) {
|
||||||
|
hasGenerateUploadLinkPermission = true;
|
||||||
|
return hasGenerateUploadLinkPermission;
|
||||||
|
}
|
||||||
|
|
||||||
|
let hasDirPrivateSharePermission = false;
|
||||||
|
if (!isVirtual && (isRepoOwner || isAdmin)) {
|
||||||
|
hasDirPrivateSharePermission = true;
|
||||||
|
return hasDirPrivateSharePermission;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user