Skip to content

Commit

Permalink
fix: Fix user permission
Browse files Browse the repository at this point in the history
Signed-off-by: leoliu <leoliu@yunify.com>
  • Loading branch information
leoliu committed Jul 23, 2020
1 parent 1244ac8 commit 7ac7239
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 64 deletions.
2 changes: 1 addition & 1 deletion server/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ client:
workspaceNavs:
- cate: 'workspace'
items:
- { name: overview, title: Overview, icon: dashboard, skipAuth: true }
- { name: overview, title: Overview, icon: dashboard, authKey: 'projects' }
- name: projects
title: NAV_PROJECTS
icon: project
Expand Down
10 changes: 6 additions & 4 deletions src/components/Modals/CustomMonitoring/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ export default class CustomMonitoringModal extends React.Component {
<ThemeSwitchButton />
<TimeRangeSelect />
<RefreshIntervalSelector />
<SwitchButton
onSaveClick={this.props.onSave}
isSubmitting={this.props.isSubmitting}
/>
{!this.props.readOnly && (
<SwitchButton
onSaveClick={this.props.onSave}
isSubmitting={this.props.isSubmitting}
/>
)}
</>
}
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modals/EditAuthorization/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class EditAuthorizationModal extends React.Component {
}

handleOk = () => {
this.props.onOk(this.state.roleTemplates)
this.props.onOk([...this.state.roleTemplates, 'role-template-view-basic'])
}

handleTabChange = e => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modals/ProjectSelect/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export default class ProjectSelectModal extends React.Component {

handleEnterWorkspace = () => {
const { workspace, onChange } = this.props
return onChange(`/workspaces/${workspace}/overview`)
return onChange(`/workspaces/${workspace}`)
}

handleOnEnter = item => {
Expand Down
4 changes: 1 addition & 3 deletions src/pages/fedprojects/containers/Overview/BaseInfo/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ export default class BaseInfo extends React.Component {
</div>
<div className={styles.content}>
<Text
title={
<Link to={`/workspaces/${workspace}/overview`}>{workspace}</Link>
}
title={<Link to={`/workspaces/${workspace}`}>{workspace}</Link>}
description={t('Workspace')}
/>
<Text title={detail.creator || '-'} description={t('Creator')} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ class ResourceUsage extends React.Component {
metric: 'namespace_service_count',
},
{
key: 'routes',
key: 'ingresses',
icon: ICON_TYPES['ingresses'],
name: 'Routes',
routeName: 'routes',
routeName: 'ingresses',
num: used['count/ingresses.extensions'],
metric: 'namespace_ingresses_extensions_count',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default class CrateDashboardModalContainer extends React.Component {
isSaving={this.props.isSubmitting}
onCancel={this.props.onCancel}
onSave={this.onSave}
readOnly={this.props.readOnly}
/>
)
}
Expand Down
1 change: 1 addition & 0 deletions src/pages/projects/containers/CustomMonitoring/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export default class CustomMonitoringDashboards extends React.Component {
isSaving={this.props.store.isSubmitting}
onCancel={this.hideEditModal}
onSave={this.editDashboard}
readOnly={!tableProps.enabledActions.includes('edit')}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ export default class IsolateInfo extends React.Component {
opened: props.networkIsolate,
}
}

toggle = () => {
const { opened } = this.state
this.props.onEdit(!opened)
this.setState({
opened: !opened,
})
}

render() {
const { opened } = this.state
const { module } = this.props
const { module, canEdit } = this.props
return (
<div className={styles.wrapper}>
<div className={styles.left}>
Expand All @@ -55,13 +57,15 @@ export default class IsolateInfo extends React.Component {
<div>{t('NETWORK_POLICY_STATUS')}</div>
</div>
</div>
<div
className={classNames(styles.toggle, opened ? '' : styles.closed)}
onClick={this.toggle}
>
<span>{opened ? t('On') : t('Close')}</span>
<label className={styles.toggleop} />
</div>
{canEdit && (
<div
className={classNames(styles.toggle, opened ? '' : styles.closed)}
onClick={this.toggle}
>
<span>{opened ? t('On') : t('Close')}</span>
<label className={styles.toggleop} />
</div>
)}
</div>
)
}
Expand Down
49 changes: 29 additions & 20 deletions src/pages/projects/containers/Network/Policies/RuleInfo/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,15 @@ export default class RuleInfo extends React.Component {
)
})}
</div>
<Icon
name="trash"
changeable
onClick={() => {
this.handleDelete(get(item, 'metadata.name'))
}}
/>
{this.props.canEdit && (
<Icon
name="trash"
changeable
onClick={() => {
this.handleDelete(get(item, 'metadata.name'))
}}
/>
)}
</div>
))}
</>
Expand Down Expand Up @@ -233,19 +235,22 @@ export default class RuleInfo extends React.Component {
)
})}
</div>
<Icon
name="trash"
changeable
onClick={() => {
this.handleDelete(get(item, 'metadata.name'))
}}
/>
{this.props.canEdit && (
<Icon
name="trash"
changeable
onClick={() => {
this.handleDelete(get(item, 'metadata.name'))
}}
/>
)}
</div>
))}
</>
)

renderInner() {
const { canEdit } = this.props
const { list } = this.store
const { curTab } = this.state
const innerEgressData = []
Expand Down Expand Up @@ -285,9 +290,11 @@ export default class RuleInfo extends React.Component {
<div className={classNames({ hide: curTab === 'outer' })}>
<div className={styles.rulemenu}>
<div>{t('NETWORK_POLICY_R1_DESC1')}</div>
<Button onClick={this.addAllowList} className={styles.addBtn}>
{t('Add Allowlist')}
</Button>
{canEdit && (
<Button onClick={this.addAllowList} className={styles.addBtn}>
{t('Add Allowlist')}
</Button>
)}
</div>
<div className={styles.rulebody}>
<div
Expand All @@ -313,9 +320,11 @@ export default class RuleInfo extends React.Component {
<div className={classNames({ hide: curTab === 'inner' })}>
<div className={styles.rulemenu}>
<div>{t('NETWORK_POLICY_R2_DESC1')}</div>
<Button onClick={this.addIpBlock} className={styles.addBtn}>
{t('Add Rule')}
</Button>
{canEdit && (
<Button onClick={this.addIpBlock} className={styles.addBtn}>
{t('Add Rule')}
</Button>
)}
</div>
<div className={styles.rulebody}>
<div
Expand Down
28 changes: 21 additions & 7 deletions src/pages/projects/containers/Network/Policies/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ export default class Policies extends React.Component {
return get(this.projectStore, 'detail.workspace', '')
}

get enabledActions() {
return globals.app.getActions({
module: 'project-settings',
...this.params,
project: this.params.namespace,
})
}

toggleNetworkIsolate = (flag = true) => {
const data = {}
set(
Expand Down Expand Up @@ -93,6 +101,8 @@ export default class Policies extends React.Component {
'detail.annotations["kubesphere.io/network-isolate"]'
) === 'enabled'

const canEdit = this.enabledActions.includes('edit')

return (
<div>
<Banner
Expand All @@ -110,13 +120,15 @@ export default class Policies extends React.Component {
desc={t('NETWORK_POLICY_EMP_DESC')}
className={styles.eplist}
actions={
<Button
type="control"
loading={isSubmitting}
onClick={this.toggleNetworkIsolate}
>
{t('On')}
</Button>
canEdit && (
<Button
type="control"
loading={isSubmitting}
onClick={this.toggleNetworkIsolate}
>
{t('On')}
</Button>
)
}
/>
) : (
Expand All @@ -125,12 +137,14 @@ export default class Policies extends React.Component {
module={module}
networkIsolate={networkIsolate}
onEdit={this.handleEditNetworkIsolate}
canEdit={canEdit}
/>
<RuleInfo
module={module}
namespace={namespace}
cluster={cluster}
workspace={workspace}
canEdit={canEdit}
/>
</Panel>
)}
Expand Down
25 changes: 22 additions & 3 deletions src/pages/workspaces/containers/Base/List/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* along with KubeSphere Console. If not, see <https://www.gnu.org/licenses/>.
*/

// import { get } from 'lodash'
import React, { Component } from 'react'
import { inject, observer } from 'mobx-react'

Expand All @@ -36,11 +35,31 @@ class WorkspaceLayout extends Component {
return this.props.rootStore.routing
}

get canViewOverview() {
return globals.app.hasPermission({
workspace: this.workspace,
module: 'projects',
action: 'view',
})
}

getRoutes() {
const { routes, path } = this.props.route
if (routes && !this.canViewOverview) {
routes.forEach(route => {
if (route.path === path && route.redirect) {
route.redirect.to = `${path}/projects`
}
})
}
return routes
}

enterWorkspace = async workspace =>
this.routing.push(`/workspaces/${workspace}/overview`)

render() {
const { match, route, location } = this.props
const { match, location } = this.props
const { detail } = this.props.workspaceStore
return (
<div className="ks-page">
Expand All @@ -57,7 +76,7 @@ class WorkspaceLayout extends Component {
match={match}
/>
</div>
<div className="ks-page-main">{renderRoutes(route.routes)}</div>
<div className="ks-page-main">{renderRoutes(this.getRoutes())}</div>
</div>
)
}
Expand Down
36 changes: 23 additions & 13 deletions src/pages/workspaces/containers/BaseInfo/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class BaseInfo extends React.Component {
}

componentDidMount() {
this.fetchMetrics()
this.canViewWorkspaceProjects && this.fetchMetrics()
}

get store() {
Expand Down Expand Up @@ -83,6 +83,14 @@ class BaseInfo extends React.Component {
})
}

get canViewWorkspaceProjects() {
return globals.app.hasPermission({
module: 'projects',
action: 'view',
workspace: this.workspace,
})
}

getMetrics = () => {
const data = toJS(this.monitorStore.statistics.data)
const metrics = {}
Expand Down Expand Up @@ -214,18 +222,20 @@ class BaseInfo extends React.Component {
</Button>
)}
</div>
<div className={styles.content}>
{options
.filter(option => !option.hidden)
.map(option => (
<Text
key={option.name}
icon={option.icon}
title={option.value}
description={t(option.name)}
/>
))}
</div>
{this.canViewWorkspaceProjects && (
<div className={styles.content}>
{options
.filter(option => !option.hidden)
.map(option => (
<Text
key={option.name}
icon={option.icon}
title={option.value}
description={t(option.name)}
/>
))}
</div>
)}
</Panel>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspaces/containers/Members/Detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default class MemberDetail extends React.Component {
attrs: this.getAttrs(),
breadcrumbs: [
{
label: t('Workspace Roles'),
label: t('Workspace Members'),
url: this.listUrl,
},
],
Expand Down

0 comments on commit 7ac7239

Please sign in to comment.