Skip to content

Commit

Permalink
support issues #6645 (#6903)
Browse files Browse the repository at this point in the history
* add ldap print error log

* update history dataId and group filter is select

* fix select add showSearch properties

* To avoid unexpected NPE

* add security annotation on controller configs method
  • Loading branch information
andotorg authored Sep 17, 2021
1 parent bfa94e3 commit 99e6ce9
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
* @author Nacos
*/
@EnableScheduling
@SpringBootApplication(scanBasePackages = {"com.alibaba.nacos.config.server", "com.alibaba.nacos.core"})
@SpringBootApplication(scanBasePackages = {
"com.alibaba.nacos.config.server",
"com.alibaba.nacos.core"})
public class Config {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,23 @@
import com.alibaba.nacos.auth.annotation.Secured;
import com.alibaba.nacos.auth.common.ActionTypes;
import com.alibaba.nacos.auth.exception.AccessException;
import com.alibaba.nacos.common.utils.NamespaceUtil;
import com.alibaba.nacos.config.server.auth.ConfigResourceParser;
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.model.ConfigHistoryInfo;
import com.alibaba.nacos.config.server.model.ConfigInfoWrapper;
import com.alibaba.nacos.config.server.model.Page;
import com.alibaba.nacos.config.server.service.repository.PersistService;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.config.server.utils.ParamUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
Expand Down Expand Up @@ -143,5 +147,20 @@ public ConfigHistoryInfo getPreviousConfigHistoryInfo(@RequestParam("dataId") St
checkHistoryInfoPermission(configHistoryInfo, dataId, group, tenant);
return configHistoryInfo;
}

/**
* Query configs list by namespace.
* @param tenant config_info namespace
* @since 2.1.1
* @return list
*/
@GetMapping(value = "/configs")
@Secured(action = ActionTypes.READ, parser = ConfigResourceParser.class)
public List<ConfigInfoWrapper> getDataIds(@RequestParam("tenant") String tenant) {
// check tenant
ParamUtils.checkTenant(tenant);
tenant = NamespaceUtil.processNamespaceParameter(tenant);
return persistService.queryConfigInfoByNamespace(tenant);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1337,5 +1337,12 @@ Map<String, Object> batchInsertOrUpdate(List<ConfigAllInfo> configInfoList, Stri
* @return count by tenantId
*/
int tenantInfoCountByTenantId(String tenantId);


/**
* Query dataId list by namespace.
*
* @param tenantId tenantId
* @return {@link ConfigInfoBase}
*/
List<ConfigInfoWrapper> queryConfigInfoByNamespace(final String tenantId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2563,6 +2563,13 @@ public int tenantInfoCountByTenantId(String tenantId) {
}
return result;
}


@Override
public List<ConfigInfoWrapper> queryConfigInfoByNamespace(String tenantId) {
Assert.hasText(tenantId, "tenantId can not be null");
String tenantTmp = StringUtils.isBlank(tenantId) ? StringUtils.EMPTY : tenantId;
final String sql = "SELECT data_id,group_id,tenant_id,app_name,type FROM config_info WHERE tenant_id=?";
return databaseOperate.queryMany(sql, new Object[] {tenantTmp}, CONFIG_INFO_WRAPPER_ROW_MAPPER);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2786,5 +2786,22 @@ public int tenantInfoCountByTenantId(String tenantId) {
}
return result.intValue();
}


@Override
public List<ConfigInfoWrapper> queryConfigInfoByNamespace(String tenant) {
Assert.hasText(tenant, "tenant can not be null");
String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
try {
return this.jt.query(
"SELECT data_id,group_id,tenant_id,app_name,type FROM config_info_beta WHERE tenant_id=?",
new Object[]{tenantTmp},
CONFIG_INFO_WRAPPER_ROW_MAPPER);
} catch (EmptyResultDataAccessException e) { // Indicates that the data does not exist, returns null.
return Collections.EMPTY_LIST;
} catch (CannotGetJdbcConnectionException e) {
LogUtil.FATAL_LOG.error("[db-error] " + e.toString(), e);
throw e;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import React from 'react';
import PropTypes from 'prop-types';
import { ConfigProvider, Field, Form, Input, Loading, Pagination, Table } from '@alifd/next';
import { ConfigProvider, Field, Form, Loading, Pagination, Select, Table } from '@alifd/next';
import RegionGroup from 'components/RegionGroup';
import { getParams, setParams, request } from '@/globalLib';

Expand Down Expand Up @@ -94,6 +94,7 @@ class HistoryRollback extends React.Component {
}

this.getData();
this.getConfigList();
}

getData(pageNo = 1) {
Expand Down Expand Up @@ -204,6 +205,35 @@ class HistoryRollback extends React.Component {
);
}

getConfigList() {
const { locale = {} } = this.props;
this.tenant = getParams('namespace') || ''; // 为当前实例保存tenant参数
const self = this;
request({
url: `v1/cs/history/configs?tenant=${this.tenant}`,
success(result) {
if (result != null) {
const dataIdList = [];
const groupList = [];
for (let i = 0; i < result.length; i++) {
dataIdList.push({
value: result[i].dataId,
label: result[i].dataId,
});
groupList.push({
value: result[i].group,
label: result[i].group,
});
}
self.setState({
dataIds: dataIdList,
groups: groupList,
});
}
},
});
}

render() {
const { locale = {} } = this.props;
const { init } = this.field;
Expand All @@ -224,9 +254,21 @@ class HistoryRollback extends React.Component {
<div>
<Form inline field={this.field}>
<Form.Item label="Data ID:" required>
<Input
placeholder={locale.dataId}
<Select
style={{ width: 200 }}
size="medium"
hasArrow
mode="single"
placeholder={locale.dataId}
dataSource={this.state.dataIds}
hasClear
showSearch
onSearch={val => {
const { dataIds } = this.state;
if (!dataIds.includes(val)) {
this.setState({ dataIds: dataIds.concat(val) });
}
}}
{...this.init('dataId', {
rules: [
{
Expand All @@ -238,9 +280,21 @@ class HistoryRollback extends React.Component {
/>
</Form.Item>
<Form.Item label="Group:" required>
<Input
placeholder={locale.group}
<Select
style={{ width: 200 }}
size="medium"
hasArrow
mode="single"
placeholder={locale.group}
dataSource={this.state.groups}
hasClear
showSearch
onSearch={val => {
const { groups } = this.state;
if (!groups.includes(val)) {
this.setState({ groups: groups.concat(val) });
}
}}
{...this.init('group', {
rules: [
{
Expand All @@ -251,7 +305,6 @@ class HistoryRollback extends React.Component {
})}
/>
</Form.Item>

<Form.Item label="">
<Form.Submit
validate
Expand Down

0 comments on commit 99e6ce9

Please sign in to comment.