Skip to content

Commit

Permalink
move user default quota (#7159)
Browse files Browse the repository at this point in the history
* move user default quota

* update

* optimize code

---------

Co-authored-by: 孙永强 <[email protected]>
  • Loading branch information
awu0403 and 孙永强 authored Dec 10, 2024
1 parent 00e8d7b commit d9c9779
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 44 deletions.
41 changes: 3 additions & 38 deletions frontend/src/pages/org-admin/org-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { orgAdminAPI } from '../../utils/org-admin-api';
import { mediaUrl, gettext, orgMemberQuotaEnabled } from '../../utils/constants';
import { Utils } from '../../utils/utils';
import MainPanelTopbar from './main-panel-topbar';
import SetOrgUserDefaultQuota from '../../components/dialog/set-org-user-default-quota';
import '../../css/org-admin-info-page.css';

const { orgID } = window.org.pageOptions;

class OrgInfo extends Component {

Expand All @@ -16,8 +14,6 @@ class OrgInfo extends Component {
org_name: '',
storage_quota: 0,
storage_usage: 0,
isSetUserDefaultQuotaDialogOpen: false,
user_default_quota: 0,
member_quota: 0,
member_usage: 0,
active_members: 0
Expand All @@ -29,33 +25,21 @@ class OrgInfo extends Component {
const {
org_id, org_name,
member_quota, member_usage, active_members,
storage_quota, storage_usage, user_default_quota
storage_quota, storage_usage
} = res.data;
this.setState({
org_id, org_name,
member_quota, member_usage, active_members,
storage_quota, storage_usage, user_default_quota
storage_quota, storage_usage
});
});
}

toggleSetUserDefaultQuotaDialog = () => {
this.setState({
isSetUserDefaultQuotaDialogOpen: !this.state.isSetUserDefaultQuotaDialogOpen
});
};

updateQuota = (quota) => {
this.setState({
user_default_quota: quota
});
};

render() {
const {
org_id, org_name,
member_quota, member_usage, active_members,
storage_quota, storage_usage, user_default_quota
storage_quota, storage_usage
} = this.state;
return (
<Fragment>
Expand Down Expand Up @@ -120,29 +104,10 @@ class OrgInfo extends Component {
<p>{Utils.bytesToSize(storage_usage)}</p>
)}
</div>

<div className="info-content-item">
<h4 className="info-content-item-heading">{gettext('User default quota')}</h4>
<span>{Utils.bytesToSize(user_default_quota)}</span>
<span
title={gettext('Edit')}
className="sf3-font sf3-font-rename attr-action-icon"
onClick={this.toggleSetUserDefaultQuotaDialog}>
</span>

</div>
</div>
</div>
</div>
</div>
{this.state.isSetUserDefaultQuotaDialogOpen &&
<SetOrgUserDefaultQuota
orgID={orgID}
userDefaultQuota={this.state.user_default_quota}
updateQuota={this.updateQuota}
toggleDialog={this.toggleSetUserDefaultQuotaDialog}
/>
}
</Fragment>
);
}
Expand Down
13 changes: 10 additions & 3 deletions frontend/src/pages/org-admin/web-settings/input-item.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import { Input, Button } from 'reactstrap';
import { Input, Button, InputGroup } from 'reactstrap';
import { gettext } from '../../../utils/constants';
import SettingItemBase from './setting-item-base';

Expand All @@ -12,6 +12,8 @@ const propTypes = {
helpTip: PropTypes.string.isRequired,
displayName: PropTypes.string.isRequired,
disabled: PropTypes.bool.isRequired,
inputAddon: PropTypes.node,
valueFixed: PropTypes.number,
};

class WebSettingInput extends Component {
Expand Down Expand Up @@ -43,24 +45,29 @@ class WebSettingInput extends Component {
};

onSubmit = (e) => {
const { valueFixed = 0 } = this.props;
const value = this.state.value.trim();
if (value != this.props.value) {
this.props.saveSetting(this.props.keyText, value);
this.setState({ value: parseInt(value).toFixed(valueFixed) });
}
this.toggleBtns();
};

render() {
const { isBtnsShown, value } = this.state;
const { helpTip, displayName, inputType, disabled } = this.props;
const { helpTip, displayName, inputType, disabled, inputAddon } = this.props;
return (
<SettingItemBase
displayName={displayName}
helpTip={helpTip}
mainContent={
disabled ?
<Input type={inputType || 'text'} className={inputType == 'textarea' ? 'web-setting-textarea' : ''} value={value} disabled /> :
<Input type={inputType || 'text'} className={inputType == 'textarea' ? 'web-setting-textarea' : ''} onChange={this.onInputChange} onFocus={this.toggleBtns} onBlur={this.hideBtns} value={value} />
<InputGroup>
<Input type={inputType || 'text'} className={inputType == 'textarea' ? 'web-setting-textarea' : ''} onChange={this.onInputChange} onFocus={this.toggleBtns} onBlur={this.hideBtns} value={value} />
{inputAddon && inputAddon}
</InputGroup>
}
extraContent={
isBtnsShown ?
Expand Down
37 changes: 34 additions & 3 deletions frontend/src/pages/org-admin/web-settings/web-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import MainPanelTopbar from '../main-panel-topbar';
import Section from './section';
import InputItem from './input-item';
import FileItem from './file-item';
import { InputGroupAddon, InputGroupText } from 'reactstrap';

import '../../../css/system-admin-web-settings.css';
import CheckboxItem from '../../sys-admin/web-settings/checkbox-item';
Expand All @@ -27,19 +28,23 @@ class OrgWebSettings extends Component {
file_ext_white_list: '',
force_adfs_login: false,
disable_org_encrypted_library: false,
disable_org_user_clean_trash: false
disable_org_user_clean_trash: false,
user_default_quota: ''
};
}

componentDidMount() {
orgAdminAPI.orgAdminGetOrgInfo().then((res) => {
const user_default_quota = res.data.user_default_quota;
const i = parseInt(Math.floor(Math.log(user_default_quota) / Math.log(1000)), 10);
this.setState({
loading: false,
config_dict: res.data,
file_ext_white_list: res.data.file_ext_white_list,
force_adfs_login: res.data.force_adfs_login,
disable_org_encrypted_library: res.data.disable_org_encrypted_library,
disable_org_user_clean_trash: res.data.disable_org_user_clean_trash
disable_org_user_clean_trash: res.data.disable_org_user_clean_trash,
user_default_quota: (user_default_quota / (1000 ** i)).toFixed(1),
});
}).catch((error) => {
this.setState({
Expand Down Expand Up @@ -82,8 +87,17 @@ class OrgWebSettings extends Component {
});
};

orgUpdateUserDefaultQuota = (key, quota) => {
orgAdminAPI.orgAdminSetOrgUserDefaultQuota(orgID, parseInt(quota)).then((res) => {
toaster.success(gettext('User default quota updated'));
}).catch((error) => {
let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
};

render() {
const { loading, errorMsg, config_dict, file_ext_white_list, force_adfs_login, disable_org_encrypted_library, disable_org_user_clean_trash } = this.state;
const { loading, errorMsg, config_dict, file_ext_white_list, force_adfs_login, disable_org_encrypted_library, disable_org_user_clean_trash, user_default_quota } = this.state;
let logoPath = this.state.logoPath;
logoPath = logoPath.indexOf('image-view') != -1 ? logoPath : mediaUrl + logoPath;
return (
Expand Down Expand Up @@ -169,6 +183,23 @@ class OrgWebSettings extends Component {
</Fragment>
</Section>
}
<Section headingText={gettext('User')}>
<Fragment>
<InputItem
className={'form-control'}
saveSetting={this.orgUpdateUserDefaultQuota}
displayName={gettext('User default quota')}
value={user_default_quota}
helpTip={gettext('Tip: 0 means default limit, the unit is MB')}
inputAddon={
<InputGroupAddon addonType="append">
<InputGroupText>MB</InputGroupText>
</InputGroupAddon>
}
valueFixed={1}
/>
</Fragment>
</Section>
</Fragment>
}
</div>
Expand Down

0 comments on commit d9c9779

Please sign in to comment.