Skip to content

Commit

Permalink
[ISSUE #8784] fix some bugs for Console UI (#8787)
Browse files Browse the repository at this point in the history
* [ISSUE #8784] fix some bugs for Console UI

- add server.error.include-message property
- add no permission tip when push config
- use addAllowedOriginPattern instead of addAllowedOrigin
- remove RAM logic in the lib.js
- fix button type error and mode value error in NewConfig.js
- fix the password reset dialog can't show

Close #8784

* [ISSUE #8784] fix translate error

* [ISSUE #8784] user ON_PARAM instead of ALWAYS

* [ISSUE #8784] fix user reset password in the Header.js
  • Loading branch information
onewe authored Jul 25, 2022
1 parent 4a3472b commit 29d472e
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 77 deletions.
7 changes: 4 additions & 3 deletions console-ui/src/globalLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,11 @@ const request = (function(_global) {
console.log('Token Error', localStorage.token, e);
goLogin();
}
const { accessToken = '', username = '' } = token;
const [url, paramsStr = ''] = config.url.split('?');
const params = paramsStr.split('&');
const { accessToken = '' } = token;
const [url, paramsStr] = config.url.split('?');
const params = paramsStr ? paramsStr.split('&') : [];
params.push(`accessToken=${accessToken}`);
params.push('message=true');

return $.ajax(
Object.assign({}, config, {
Expand Down
8 changes: 6 additions & 2 deletions console-ui/src/layouts/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Header extends React.Component {
changePassword = () => {
this.setState({
passwordResetUser: this.getUsername(),
passwordResetUserVisible: true,
});
};

Expand Down Expand Up @@ -84,7 +85,7 @@ class Header extends React.Component {
location: { pathname },
} = this.props;
const { home, docs, blog, community, enterprise, languageSwitchButton } = locale;
const { passwordResetUser = '' } = this.state;
const { passwordResetUser = '', passwordResetUserVisible = false } = this.state;
const BASE_URL = `https://nacos.io/${language.toLocaleLowerCase()}/`;
const NAV_MENU = [
{ id: 1, title: home, link: BASE_URL },
Expand Down Expand Up @@ -135,13 +136,16 @@ class Header extends React.Component {
</div>
</header>
<PasswordReset
visible={passwordResetUserVisible}
username={passwordResetUser}
onOk={user =>
passwordReset(user).then(res => {
return res;
})
}
onCancel={() => this.setState({ passwordResetUser: undefined })}
onCancel={() =>
this.setState({ passwordResetUser: undefined, passwordResetUserVisible: false })
}
/>
</>
);
Expand Down
53 changes: 1 addition & 52 deletions console-ui/src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { getParams, request, aliwareIntl } from './globalLib';

let hasAlert = false;
import { getParams, request } from './globalLib';

window.edasprefix = 'acm'; // 固定的edas网关需要的项目名

Expand Down Expand Up @@ -48,55 +46,6 @@ request.middleWare((_config = {}) => {
}
}

const preSucess = config.success;
const preErorr = config.error;

config.success = function(res) {
if (res.code === 'ConsoleNeedLogin' && window.location.host.indexOf('acm') !== -1) {
window.location.reload();
}
if (res.code === 403 && !hasAlert) {
hasAlert = true;
window.Dialog.alert({
style: { width: 400 },
content: res.message,
onOk: () => {
hasAlert = false;
},
onCancel: () => {
hasAlert = false;
},
onClose: () => {
hasAlert = false;
},
});
} else {
typeof preSucess === 'function' && preSucess(res);
}
};

config.error = function(res) {
if (res.status === 403 && !hasAlert) {
hasAlert = true;

window.Dialog.alert({
style: { width: 400 },
content: aliwareIntl.get('com.alibaba.nacos.pubshow'), // '子账号没有权限,请联系主账号负责人RAM上授权',
onOk: () => {
hasAlert = false;
},
onCancel: () => {
hasAlert = false;
},
onClose: () => {
hasAlert = false;
},
});
} else {
typeof preErorr === 'function' && preErorr(res);
}
};

return config;
});

Expand Down
1 change: 1 addition & 0 deletions console-ui/src/locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ const I18N_CONF = {
newListingMain: 'Create Configuration',
newListing: 'Create Configuration',
publishFailed: 'Publish failed. Make sure parameters are entered correctly.',
publishFailed403: 'Publish failed. No permission to create Configuration',
doNotEnter: 'Illegal characters not allowed',
newConfig: 'Data ID cannot be empty.',
dataIdIsNotEmpty: 'Data ID cannot exceed 255 characters in length',
Expand Down
1 change: 1 addition & 0 deletions console-ui/src/locales/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ const I18N_CONF = {
newListingMain: '新建配置',
newListing: '新建配置',
publishFailed: '发布失败。请检查参数是否正确。',
publishFailed403: '发布失败,请检查是否有权限新增配置',
doNotEnter: '不允许非法字符',
newConfig: 'Data ID 不能为空',
dataIdIsNotEmpty: 'Data ID 长度不能超过255字符',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,14 @@ class UserManagement extends React.Component {

render() {
const { users, locale } = this.props;
const { loading, pageSize, pageNo, createUserVisible, passwordResetUser } = this.state;
const {
loading,
pageSize,
pageNo,
createUserVisible,
passwordResetUserVisible,
passwordResetUser,
} = this.state;
return (
<>
<RegionGroup left={locale.userManagement} />
Expand Down Expand Up @@ -99,7 +106,9 @@ class UserManagement extends React.Component {
<>
<Button
type="primary"
onClick={() => this.setState({ passwordResetUser: username })}
onClick={() =>
this.setState({ passwordResetUser: username, passwordResetUserVisible: true })
}
>
{locale.resetPassword}
</Button>
Expand Down Expand Up @@ -144,14 +153,17 @@ class UserManagement extends React.Component {
onCancel={() => this.colseCreateUser()}
/>
<PasswordReset
visible={passwordResetUserVisible}
username={passwordResetUser}
onOk={user =>
passwordReset(user).then(res => {
this.getUsers();
return res;
})
}
onCancel={() => this.setState({ passwordResetUser: undefined })}
onCancel={() =>
this.setState({ passwordResetUser: undefined, passwordResetUserVisible: false })
}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import $ from 'jquery';
import React from 'react';
import PropTypes from 'prop-types';
import SuccessDialog from '../../../components/SuccessDialog';
import { getParams, setParams, request, aliwareIntl } from '../../../globalLib';
import { getParams, setParams, request } from '../../../globalLib';
import { generateUrl } from '../../../utils/nacosutil';
import {
Balloon,
Expand Down Expand Up @@ -313,6 +313,13 @@ class NewConfig extends React.Component {
},
error: err => {
// 后端接口很不规范 响应为空 说明没有数据 就可以新增
const { status } = err || {};
if (status === 403) {
Dialog.alert({
content: locale.publishFailed403,
});
return;
}
this._publishConfig(content);
},
});
Expand Down Expand Up @@ -534,8 +541,7 @@ class NewConfig extends React.Component {
hasArrow
style={{ width: '100%', height: '100%!important' }}
autoWidth
multiple
mode="tag"
mode="multiple"
filterLocal
placeholder={locale.pleaseEnterTag}
dataSource={this.state.tagLst}
Expand Down Expand Up @@ -605,7 +611,7 @@ class NewConfig extends React.Component {
{locale.escExit}
</Button>

<Button type={'light'} onClick={this.goList.bind(this)}>
<Button type={'normal'} onClick={this.goList.bind(this)}>
{locale.release}
</Button>
</div>
Expand Down
1 change: 1 addition & 0 deletions console-ui/src/utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const request = () => {
if (!params) {
config.params = {};
}
config.params.message = true;
if (!url.includes('auth/users/login')) {
let token = {};
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public void init() {
public CorsFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.setMaxAge(18000L);
config.addAllowedMethod("*");
config.addAllowedOriginPattern("*");
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
Expand Down
2 changes: 2 additions & 0 deletions console/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#*************** Spring Boot Related Configurations ***************#
### Default web context path:
server.servlet.contextPath=/nacos
### Include message field
server.error.include-message=ON_PARAM
### Default web server port:

#*************** Network Related Configurations ***************#
Expand Down
6 changes: 3 additions & 3 deletions console/src/main/resources/static/css/main.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions console/src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<link rel="stylesheet" type="text/css" href="console-ui/public/css/icon.css">
<link rel="stylesheet" type="text/css" href="console-ui/public/css/font-awesome.css">
<!-- 第三方css结束 -->
<link href="./css/main.css?7449a5cb967e58fecbaa" rel="stylesheet"></head>
<link href="./css/main.css?63e21d02ece6640bf812" rel="stylesheet"></head>

<body>
<div id="root" style="overflow:hidden"></div>
Expand All @@ -56,6 +56,6 @@
<script src="console-ui/public/js/merge.js"></script>
<script src="console-ui/public/js/loader.js"></script>
<!-- 第三方js结束 -->
<script type="text/javascript" src="./js/main.js?7449a5cb967e58fecbaa"></script></body>
<script type="text/javascript" src="./js/main.js?63e21d02ece6640bf812"></script></body>

</html>
Loading

0 comments on commit 29d472e

Please sign in to comment.