Skip to content

Commit

Permalink
support set permission for share link (#6332)
Browse files Browse the repository at this point in the history
  • Loading branch information
imwhatiam authored Jul 11, 2024
1 parent 0071304 commit 84540f5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 35 deletions.
48 changes: 23 additions & 25 deletions frontend/src/components/share-link-panel/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { isPro, gettext, shareLinkExpireDaysMin, shareLinkExpireDaysMax, shareLinkExpireDaysDefault } from '../../utils/constants';
import { gettext, shareLinkExpireDaysMin, shareLinkExpireDaysMax, shareLinkExpireDaysDefault } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api';
import { Utils } from '../../utils/utils';
import ShareLink from '../../models/share-link';
Expand Down Expand Up @@ -55,34 +55,32 @@ class ShareLinkPanel extends React.Component {
toaster.danger(errMessage);
});

if (isPro) {
const { itemType, userPerm } = this.props;
if (itemType == 'library') {
let permissionOptions = Utils.getShareLinkPermissionList(itemType, userPerm, path);
const { itemType, userPerm } = this.props;
if (itemType == 'library') {
let permissionOptions = Utils.getShareLinkPermissionList(itemType, userPerm, path);
this.setState({
permissionOptions: permissionOptions,
currentPermission: permissionOptions[0],
});
} else {
let getDirentInfoAPI;
if (this.props.itemType === 'file') {
getDirentInfoAPI = seafileAPI.getFileInfo(repoID, path);
} else if (this.props.itemType === 'dir') {
getDirentInfoAPI = seafileAPI.getDirInfo(repoID, path);
}
getDirentInfoAPI.then((res) => {
let canEdit = res.data.can_edit;
let permission = res.data.permission;
let permissionOptions = Utils.getShareLinkPermissionList(this.props.itemType, permission, path, canEdit);
this.setState({
permissionOptions: permissionOptions,
currentPermission: permissionOptions[0],
});
} else {
let getDirentInfoAPI;
if (this.props.itemType === 'file') {
getDirentInfoAPI = seafileAPI.getFileInfo(repoID, path);
} else if (this.props.itemType === 'dir') {
getDirentInfoAPI = seafileAPI.getDirInfo(repoID, path);
}
getDirentInfoAPI.then((res) => {
let canEdit = res.data.can_edit;
let permission = res.data.permission;
let permissionOptions = Utils.getShareLinkPermissionList(this.props.itemType, permission, path, canEdit);
this.setState({
permissionOptions: permissionOptions,
currentPermission: permissionOptions[0],
});
}).catch(error => {
let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
}
}).catch(error => {
let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
}
}

Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/share-link-panel/link-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import moment from 'moment';
import { Button, Form, FormGroup, Label, Input, InputGroup, InputGroupAddon, Alert } from 'reactstrap';
import { isPro, gettext, shareLinkExpireDaysMin, shareLinkExpireDaysMax, shareLinkExpireDaysDefault, shareLinkForceUsePassword, shareLinkPasswordMinLength, shareLinkPasswordStrengthLevel } from '../../utils/constants';
import { gettext, shareLinkExpireDaysMin, shareLinkExpireDaysMax, shareLinkExpireDaysDefault, shareLinkForceUsePassword, shareLinkPasswordMinLength, shareLinkPasswordStrengthLevel } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api';
import { Utils } from '../../utils/utils';
import ShareLink from '../../models/share-link';
Expand Down Expand Up @@ -101,11 +101,11 @@ class LinkCreation extends React.Component {
this.setState({errorInfo: ''});
let { type, itemPath, repoID } = this.props;
let { linkAmount, isShowPasswordInput, password, isExpireChecked, expType, expireDays, expDate } = this.state;

const permissionDetails = Utils.getShareLinkPermissionObject(this.state.currentPermission).permissionDetails;
let permissions;
if (isPro) {
const permissionDetails = Utils.getShareLinkPermissionObject(this.state.currentPermission).permissionDetails;
permissions = JSON.stringify(permissionDetails);
}
permissions = JSON.stringify(permissionDetails);

let expirationTime = '';
if (isExpireChecked) {
if (expType == 'by-days') {
Expand Down Expand Up @@ -327,7 +327,7 @@ class LinkCreation extends React.Component {
</div>
}
</FormGroup>
{(isPro && !isCustomPermission) && (
{!isCustomPermission && (
<FormGroup check>
<Label check>
<span>{gettext('Set permission')}</span>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/share-link-panel/link-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import moment from 'moment';
import copy from 'copy-to-clipboard';
import { Button } from 'reactstrap';
import { isPro, gettext, shareLinkExpireDaysMin, shareLinkExpireDaysMax, shareLinkExpireDaysDefault, canSendShareLinkEmail } from '../../utils/constants';
import { gettext, shareLinkExpireDaysMin, shareLinkExpireDaysMax, shareLinkExpireDaysDefault, canSendShareLinkEmail } from '../../utils/constants';
import Selector from '../../components/single-selector';
import CommonOperationConfirmationDialog from '../../components/dialog/common-operation-confirmation-dialog';
import { seafileAPI } from '../../utils/seafile-api';
Expand Down Expand Up @@ -234,7 +234,7 @@ class LinkDetails extends React.Component {
}
</>
)}
{(isPro && sharedLinkInfo.permissions) && (
{sharedLinkInfo.permissions && (
<>
<dt className="text-secondary font-weight-normal">{gettext('Permission:')}</dt>
<dd style={{width:'250px'}} onMouseEnter={this.handleMouseOver} onMouseLeave={this.handleMouseOut}>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/share-link-panel/link-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import moment from 'moment';
import copy from 'copy-to-clipboard';
import toaster from '../toast';
import { isPro, gettext } from '../../utils/constants';
import { gettext } from '../../utils/constants';
import { Utils } from '../../utils/utils';
import CommonOperationConfirmationDialog from '../../components/dialog/common-operation-confirmation-dialog';

Expand Down Expand Up @@ -103,7 +103,7 @@ class LinkItem extends React.Component {
{this.cutLink(link)}
</td>
<td>
{(isPro && permissions) && Utils.getShareLinkPermissionObject(currentPermission).text}
{permissions && Utils.getShareLinkPermissionObject(currentPermission).text}
</td>
<td>
{expire_date ? moment(expire_date).format('YYYY-MM-DD HH:mm') : '--'}
Expand Down

0 comments on commit 84540f5

Please sign in to comment.