Skip to content

Commit

Permalink
fix: Fix cluster visibility for public cluster
Browse files Browse the repository at this point in the history
Signed-off-by: leoliu <leoliu@yunify.com>
  • Loading branch information
leoliu committed Aug 6, 2020
1 parent 6705f16 commit d64ef71
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 56 deletions.
49 changes: 24 additions & 25 deletions src/pages/clusters/actions/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,30 @@ export default {
)

const requests = []
if (data.public === false) {
if (data.addWorkspaces) {
data.addWorkspaces.forEach(item => {
const formData = {}
const clusters = item.clusters || []
set(
formData,
'spec.placement.clusters',
uniqBy([...clusters, { name: cluster.name }], 'name')
)
requests.push(workspaceStore.patch(item, formData))
})
}
if (data.deleteWorkspaces) {
data.deleteWorkspaces.forEach(item => {
const formData = {}
const clusters = item.clusters || []
set(
formData,
'spec.placement.clusters',
clusters.filter(({ name }) => name !== cluster.name)
)
requests.push(workspaceStore.patch(item, formData))
})
}

if (data.addWorkspaces) {
data.addWorkspaces.forEach(item => {
const formData = {}
const clusters = item.clusters || []
set(
formData,
'spec.placement.clusters',
uniqBy([...clusters, { name: cluster.name }], 'name')
)
requests.push(workspaceStore.patch(item, formData))
})
}
if (data.deleteWorkspaces) {
data.deleteWorkspaces.forEach(item => {
const formData = {}
const clusters = item.clusters || []
set(
formData,
'spec.placement.clusters',
clusters.filter(({ name }) => name !== cluster.name)
)
requests.push(workspaceStore.patch(item, formData))
})
}

await Promise.all(requests)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ export default class ClusterVisibility extends React.Component {
key={item.name}
data={item}
type="authed"
disabled={
isPublic || globals.config.systemWorkspace === item.name
}
disabled={globals.config.systemWorkspace === item.name}
onClick={this.handleWorkspaceUnAuth}
/>
))}
Expand Down
21 changes: 4 additions & 17 deletions src/pages/clusters/containers/Visibility/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import React from 'react'
import { toJS } from 'mobx'
import { observer, inject } from 'mobx-react'
import Banner from 'components/Cards/Banner'
import { Alert, Avatar, Button, Panel, Text } from 'components/Base'
import { Avatar, Button, Panel, Text } from 'components/Base'
import Table from 'components/Tables/Base'
import { getLocalTime, getDisplayName } from 'utils'
import { trigger } from 'utils/action'
Expand All @@ -36,9 +36,7 @@ export default class Overview extends React.Component {
workspaceStore = new WorkspaceStore()

componentDidMount() {
if (!this.isClusterPublicVisible) {
this.getData()
}
this.getData()
}

get cluster() {
Expand Down Expand Up @@ -80,9 +78,8 @@ export default class Overview extends React.Component {
afterEdit = async () => {
const { cluster } = this.props.match.params
await this.cluster.fetchDetail({ name: cluster })
if (!this.isClusterPublicVisible) {
this.getData()
}

this.getData()
}

getColumns() {
Expand Down Expand Up @@ -121,16 +118,6 @@ export default class Overview extends React.Component {
})

renderVisibility() {
if (this.isClusterPublicVisible) {
return (
<Alert
className="margin-t12"
title={t('The current cluster is public')}
message={t('PUBLIC_CLUSTER_DESC')}
/>
)
}

const {
data,
total,
Expand Down
12 changes: 1 addition & 11 deletions src/stores/cluster/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ export default class ClusterStore extends Base {
getAgentUrl = ({ cluster }) =>
`kapis/cluster.kubesphere.io/v1alpha1/clusters/${cluster}/agent/deployment`

getTenantUrl = (params = {}) =>
`kapis/tenant.kubesphere.io/v1alpha2${this.getPath(params)}/${this.module}`

@action
async fetchList({ cluster, workspace, namespace, more, ...params } = {}) {
this.list.isLoading = true
Expand All @@ -71,16 +68,9 @@ export default class ClusterStore extends Base {
let result
if (!globals.app.isMultiCluster) {
result = { items: [DEFAULT_CLUSTER] }
} else if (
globals.app.hasPermission({ module: 'clusters', action: 'view' })
) {
result = await request.get(
this.getResourceUrl({ cluster, workspace, namespace }),
params
)
} else {
result = await request.get(
this.getTenantUrl({ cluster, workspace, namespace }),
this.getResourceUrl({ cluster, workspace, namespace }),
params
)
}
Expand Down

0 comments on commit d64ef71

Please sign in to comment.