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

optimized code

This commit is contained in:
shanshuirenjia
2019-07-02 11:43:07 +08:00
parent 65fed84036
commit 73c475deb2

View File

@@ -41,7 +41,9 @@ class SharedRepoListItem extends React.Component {
isHistorySettingDialogShow: false, isHistorySettingDialogShow: false,
isDeleteDialogShow: false, isDeleteDialogShow: false,
}; };
this.isDeparementOnwerGroupMember = false;
this.isCurrentDepartmentRepo = false; // is current department owned repo
this.isCurrentDepartmentStaff = false; // is one of this department's admin
} }
onMouseEnter = () => { onMouseEnter = () => {
@@ -209,21 +211,25 @@ class SharedRepoListItem extends React.Component {
generatorOperations = () => { generatorOperations = () => {
let { repo, currentGroup } = this.props; let { repo, currentGroup } = this.props;
let isCurrentDepartmentRepo = repo.owner_email === currentGroup.id + '@seafile_group'; // is current department owned repo
//todo this have a bug; use current api is not return admins param; //todo this have a bug; use current api is not return admins param;
let isStaff = currentGroup && currentGroup.admins && currentGroup.admins.indexOf(username) > -1; //for group repolist; let isStaff = currentGroup && currentGroup.admins && currentGroup.admins.indexOf(username) > -1; //for group repolist;
let isRepoOwner = repo.owner_email === username; let isRepoOwner = repo.owner_email === username;
this.isCurrentDepartmentRepo = isCurrentDepartmentRepo;
this.isCurrentDepartmentStaff = isStaff;
let isAdmin = repo.is_admin; let isAdmin = repo.is_admin;
let operations = []; let operations = [];
// todo ,shared width me shared width all;
if (isPro) { if (isPro) {
if (repo.owner_email.indexOf('@seafile_group') != -1) { //current repo is belong to a group; if (repo.owner_email.indexOf('@seafile_group') != -1) { //current repo is belong to a group;
if (isStaff) { if (isStaff) {
if (repo.owner_email === currentGroup.id + '@seafile_group') { if (isCurrentDepartmentRepo) {
this.isDeparementOnwerGroupMember = true;
if (folderPermEnabled) { if (folderPermEnabled) {
operations = ['Rename', 'Folder Permission', 'History Setting', 'Details']; operations = ['Rename', 'Folder Permission', 'History Setting', 'Details'];
} else { } else {
operations = ['Rename', 'Details']; operations = ['Rename', 'History Setting', 'Details'];
} }
} else { } else {
operations.push('Unshare'); operations.push('Unshare');
@@ -257,7 +263,7 @@ class SharedRepoListItem extends React.Component {
} }
} else { } else {
operations = this.generatorOperations(); operations = this.generatorOperations();
if (this.isDeparementOnwerGroupMember) { if (this.isCurrentDepartmentRepo && this.isCurrentDepartmentStaff) {
operations.unshift('Unshare'); operations.unshift('Unshare');
operations.unshift('Share'); operations.unshift('Share');
} }
@@ -302,7 +308,7 @@ class SharedRepoListItem extends React.Component {
const unshareOperation = <a href="#" className="op-icon sf2-icon-x3" title={gettext('Unshare')} onClick={this.onItemUnshare}></a>; const unshareOperation = <a href="#" className="op-icon sf2-icon-x3" title={gettext('Unshare')} onClick={this.onItemUnshare}></a>;
const deleteOperation = <a href="#" className="op-icon sf2-icon-delete" title={gettext('Delete')} onClick={this.onItemDeleteToggle}></a>; const deleteOperation = <a href="#" className="op-icon sf2-icon-delete" title={gettext('Delete')} onClick={this.onItemDeleteToggle}></a>;
if (this.isDeparementOnwerGroupMember) { if (this.isCurrentDepartmentRepo && this.isCurrentDepartmentStaff) {
return ( return (
<Fragment> <Fragment>
{shareOperation} {shareOperation}