修改普通用户不能通过dashboard页面跳转到用户管理和会话管理
This commit is contained in:
parent
abf1e0217c
commit
5b7cebb602
@ -13,11 +13,25 @@ type Counter struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func OverviewCounterEndPoint(c echo.Context) error {
|
func OverviewCounterEndPoint(c echo.Context) error {
|
||||||
countUser, _ := model.CountUser()
|
account, _ := GetCurrentAccount(c)
|
||||||
countOnlineSession, _ := model.CountOnlineSession()
|
|
||||||
credential, _ := model.CountCredential()
|
|
||||||
asset, _ := model.CountAsset()
|
|
||||||
|
|
||||||
|
var (
|
||||||
|
countUser int64
|
||||||
|
countOnlineSession int64
|
||||||
|
credential int64
|
||||||
|
asset int64
|
||||||
|
)
|
||||||
|
if model.TypeUser == account.Type {
|
||||||
|
countUser, _ = model.CountUser()
|
||||||
|
countOnlineSession, _ = model.CountOnlineSession()
|
||||||
|
credential, _ = model.CountCredentialByUserId(account.ID)
|
||||||
|
asset, _ = model.CountAssetByUserId(account.ID)
|
||||||
|
} else {
|
||||||
|
countUser, _ = model.CountUser()
|
||||||
|
countOnlineSession, _ = model.CountOnlineSession()
|
||||||
|
credential, _ = model.CountCredential()
|
||||||
|
asset, _ = model.CountAsset()
|
||||||
|
}
|
||||||
counter := Counter{
|
counter := Counter{
|
||||||
User: countUser,
|
User: countUser,
|
||||||
OnlineSession: countOnlineSession,
|
OnlineSession: countOnlineSession,
|
||||||
|
@ -164,6 +164,24 @@ func CountAsset() (total int64, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CountAssetByUserId(userId string) (total int64, err error) {
|
||||||
|
db := global.DB.Joins("left join resource_sharers on assets.id = resource_sharers.resource_id")
|
||||||
|
|
||||||
|
db = db.Where("assets.owner = ? or resource_sharers.user_id = ?", userId, userId)
|
||||||
|
|
||||||
|
// 查询用户所在用户组列表
|
||||||
|
userGroupIds, err := FindUserGroupIdsByUserId(userId)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if userGroupIds != nil && len(userGroupIds) > 0 {
|
||||||
|
db = db.Or("resource_sharers.user_group_id in ?", userGroupIds)
|
||||||
|
}
|
||||||
|
err = db.Find(&Asset{}).Count(&total).Error
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func FindAssetTags() (o []string, err error) {
|
func FindAssetTags() (o []string, err error) {
|
||||||
var assets []Asset
|
var assets []Asset
|
||||||
err = global.DB.Not("tags = ?", "").Find(&assets).Error
|
err = global.DB.Not("tags = ?", "").Find(&assets).Error
|
||||||
|
@ -103,3 +103,21 @@ func CountCredential() (total int64, err error) {
|
|||||||
err = global.DB.Find(&Credential{}).Count(&total).Error
|
err = global.DB.Find(&Credential{}).Count(&total).Error
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CountCredentialByUserId(userId string) (total int64, err error) {
|
||||||
|
db := global.DB.Joins("left join resource_sharers on credentials.id = resource_sharers.resource_id")
|
||||||
|
|
||||||
|
db = db.Where("credentials.owner = ? or resource_sharers.user_id = ?", userId, userId)
|
||||||
|
|
||||||
|
// 查询用户所在用户组列表
|
||||||
|
userGroupIds, err := FindUserGroupIdsByUserId(userId)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if userGroupIds != nil && len(userGroupIds) > 0 {
|
||||||
|
db = db.Or("resource_sharers.user_group_id in ?", userGroupIds)
|
||||||
|
}
|
||||||
|
err = db.Find(&Credential{}).Count(&total).Error
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -7,6 +7,7 @@ import './Dashboard.css'
|
|||||||
import {Link} from "react-router-dom";
|
import {Link} from "react-router-dom";
|
||||||
import {Area} from '@ant-design/charts';
|
import {Area} from '@ant-design/charts';
|
||||||
import Logout from "../user/Logout";
|
import Logout from "../user/Logout";
|
||||||
|
import {isAdmin} from "../../service/permission";
|
||||||
|
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
@ -97,7 +98,7 @@ class Dashboard extends Component {
|
|||||||
<Row gutter={16}>
|
<Row gutter={16}>
|
||||||
<Col span={6}>
|
<Col span={6}>
|
||||||
<Card bordered={true}>
|
<Card bordered={true}>
|
||||||
<Link to={'/user'}>
|
<Link to={'/user'} disabled={!isAdmin()}>
|
||||||
<Statistic title="在线用户" value={this.state.counter['user']}
|
<Statistic title="在线用户" value={this.state.counter['user']}
|
||||||
prefix={<UserOutlined/>}/>
|
prefix={<UserOutlined/>}/>
|
||||||
</Link>
|
</Link>
|
||||||
@ -122,7 +123,7 @@ class Dashboard extends Component {
|
|||||||
</Col>
|
</Col>
|
||||||
<Col span={6}>
|
<Col span={6}>
|
||||||
<Card bordered={true}>
|
<Card bordered={true}>
|
||||||
<Link to={'/online-session'}>
|
<Link to={'/online-session'} disabled={!isAdmin()}>
|
||||||
<Statistic title="在线会话" value={this.state.counter['onlineSession']}
|
<Statistic title="在线会话" value={this.state.counter['onlineSession']}
|
||||||
prefix={<LinkOutlined/>}/>
|
prefix={<LinkOutlined/>}/>
|
||||||
</Link>
|
</Link>
|
||||||
|
Loading…
Reference in New Issue
Block a user