Skip to content

Commit 2e3bfff

Browse files
committed
APIPark访客模式完成
1 parent 03d76ce commit 2e3bfff

16 files changed

Lines changed: 117 additions & 81 deletions

File tree

controller/my_team/iml.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ type imlTeamController struct {
1414
module my_team.ITeamModule `autowired:""`
1515
}
1616

17+
func (c *imlTeamController) SimpleTeams(ctx *gin.Context, keyword string) ([]*team_dto.SimpleTeam, error) {
18+
return c.module.SimpleTeams(ctx, keyword)
19+
}
20+
1721
func (c *imlTeamController) UpdateMemberRole(ctx *gin.Context, id string, input *team_dto.UpdateMemberRole) error {
1822
return c.module.UpdateMemberRole(ctx, id, input)
1923
}
@@ -23,16 +27,16 @@ func (c *imlTeamController) GetTeam(ctx *gin.Context, id string) (*team_dto.Team
2327
}
2428

2529
func (c *imlTeamController) Search(ctx *gin.Context, keyword string) ([]*team_dto.Item, error) {
26-
30+
2731
return c.module.Search(ctx, keyword)
2832
}
2933

3034
func (c *imlTeamController) EditTeam(ctx *gin.Context, id string, team *team_dto.EditTeam) (*team_dto.Team, error) {
3135
return c.module.Edit(ctx, id, team)
3236
}
3337

34-
func (c *imlTeamController) SimpleTeams(ctx *gin.Context, keyword string) ([]*team_dto.SimpleTeam, error) {
35-
return c.module.SimpleTeams(ctx, keyword)
38+
func (c *imlTeamController) MySimpleTeams(ctx *gin.Context, keyword string) ([]*team_dto.SimpleTeam, error) {
39+
return c.module.MySimpleTeams(ctx, keyword)
3640
}
3741

3842
func (c *imlTeamController) AddMember(ctx *gin.Context, id string, users *team_dto.UserIDs) error {

controller/my_team/team.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package my_team
22

33
import (
44
"reflect"
5-
5+
66
team_dto "github.com/APIParkLab/APIPark/module/my-team/dto"
77
"github.com/eolinker/go-common/autowire"
88
"github.com/gin-gonic/gin"
@@ -13,6 +13,7 @@ type ITeamController interface {
1313
GetTeam(ctx *gin.Context, id string) (*team_dto.Team, error)
1414
Search(ctx *gin.Context, keyword string) ([]*team_dto.Item, error)
1515
EditTeam(ctx *gin.Context, id string, team *team_dto.EditTeam) (*team_dto.Team, error)
16+
MySimpleTeams(ctx *gin.Context, keyword string) ([]*team_dto.SimpleTeam, error)
1617
SimpleTeams(ctx *gin.Context, keyword string) ([]*team_dto.SimpleTeam, error)
1718
AddMember(ctx *gin.Context, id string, users *team_dto.UserIDs) error
1819
RemoveMember(ctx *gin.Context, id string, uuid string) error

frontend/packages/common/src/contexts/GlobalStateContext.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,22 @@ export const GlobalProvider: FC<{children:ReactNode}> = ({ children }) => {
109109
const [pluginAccessDictionary, setPluginAccessDictionary] = useState<{[k:string]:string}>({})
110110
const [teamDataFlushed, setTeamDataFlushed] = useState<boolean>(false)
111111
const [accessInit, setAccessInit] = useState<boolean>(false)
112+
let getGlobalAccessPromise: Promise<BasicResponse<{ access:string[] }>> | null = null
112113

113114
const getGlobalAccessData = ()=>{
114-
fetchData<BasicResponse<{ access:string[]}>>('profile/permission/system',{method:'GET'},).then(response=>{
115+
getGlobalAccessPromise = new Promise((resolve, reject) => fetchData<BasicResponse<{ access:string[]}>>('profile/permission/system',{method:'GET'},).then(response=>{
115116
const {code,data,msg} = response
116117
if(code === STATUS_CODE.SUCCESS){
117118
setAccessInit(true)
118119
setAccessData(prevData => new Map(prevData).set('system', data.access))
120+
resolve(data.response)
119121
}else{
120122
message.error(msg || '操作失败')
123+
reject(data.msg || '操作失败')
121124
}
122125
})
126+
)
127+
return getGlobalAccessData
123128
}
124129

125130
const getTeamAccessData = (teamId:string)=>{
@@ -149,7 +154,13 @@ export const GlobalProvider: FC<{children:ReactNode}> = ({ children }) => {
149154
setPluginAccessDictionary({})
150155
}
151156

152-
const checkPermission = (access:keyof typeof PERMISSION_DEFINITION[0] | Array<keyof typeof PERMISSION_DEFINITION[0]>)=>{
157+
const checkPermission = async (access:keyof typeof PERMISSION_DEFINITION[0] | Array<keyof typeof PERMISSION_DEFINITION[0]>)=>{
158+
if( !accessInit && getGlobalAccessPromise){
159+
await getGlobalAccessPromise
160+
}
161+
if( !accessInit && !getGlobalAccessPromise){
162+
await getGlobalAccessData()
163+
}
153164
let revs = false;
154165
if (Array.isArray(access)) {
155166
revs = access.some(item => checkAccess(item, accessData));

frontend/packages/core/src/pages/system/SystemConfig.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { getImgBase64 } from "@common/utils/dataTransfer.ts";
2020
import { CategorizesType } from "@market/const/serviceHub/type.ts";
2121
import WithPermission from "@common/components/aoplatform/WithPermission.tsx";
2222
import { Icon } from "@iconify/react/dist/iconify.js";
23+
import { useGlobalContext } from "@common/contexts/GlobalStateContext.tsx";
2324

2425
const MAX_SIZE = 2 * 1024; // 1KB
2526

@@ -38,6 +39,7 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_,ref) => {
3839
const [tagOptionList, setTagOptionList] = useState<DefaultOptionType[]>([])
3940
const [serviceClassifyOptionList, setServiceClassifyOptionList] = useState<DefaultOptionType[]>()
4041
const [uploadLoading, setUploadLoading] = useState<boolean>(false)
42+
const {checkPermission} = useGlobalContext()
4143

4244
useImperativeHandle(ref, () => ({
4345
save:onFinish
@@ -157,7 +159,8 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_,ref) => {
157159

158160
const getTeamOptionList = ()=>{
159161
setTeamOptionList([])
160-
fetchData<BasicResponse<{ teams: SimpleTeamItem[] }>>('simple/teams/mine',{method:'GET',eoTransformKeys:['available_partitions']}).then(response=>{
162+
163+
fetchData<BasicResponse<{ teams: SimpleTeamItem[] }>>(!checkPermission('system.workspace.team.view_all') ?'simple/teams/mine' :'simple/teams',{method:'GET',eoTransformKeys:[]}).then(response=>{
161164
const {code,data,msg} = response
162165
if(code === STATUS_CODE.SUCCESS){
163166
setTeamOptionList(data.teams?.map((x:MemberItem)=>{return {...x,

frontend/packages/core/src/pages/system/SystemList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const SystemList:FC = ()=>{
5555
}
5656

5757
const getTeamsList = ()=>{
58-
fetchData<BasicResponse<{teams:SimpleTeamItem[]}>>('simple/teams/mine',{method:'GET'}).then(response=>{
58+
fetchData<BasicResponse<{ teams: SimpleTeamItem[] }>>(!checkPermission('system.workspace.team.view_all') ?'simple/teams/mine' :'simple/teams',{method:'GET',eoTransformKeys:[]}).then(response=>{
5959
const {code,data,msg} = response
6060
setTeamList(data.teams)
6161
if(code === STATUS_CODE.SUCCESS){

frontend/packages/market/src/pages/serviceHub/ServiceHubDetail.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ import { EntityItem } from "@common/const/type.ts";
1111
import { ApplyServiceModal } from "./ApplyServiceModal.tsx";
1212
import ServiceHubApiDocument from "./ServiceHubApiDocument.tsx";
1313
import { ApiFilled, ArrowLeftOutlined, LeftOutlined } from "@ant-design/icons";
14-
import { Typography } from 'antd';
1514
import { SimpleSystemItem } from "@core/const/system/type.ts";
1615
import { Icon } from "@iconify/react/dist/iconify.js";
1716
import DOMPurify from 'dompurify';
1817

19-
const { Title, Text } = Typography;
2018

2119
const ServiceHubDetail = ()=>{
2220
const {serviceId} = useParams<RouterParams>();

frontend/packages/market/src/pages/serviceHub/management/ServiceHubManagement.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const getServiceList = ()=>{
5151

5252
const getTeamsList = ()=>{
5353
setPageLoading(true)
54-
fetchData<BasicResponse<{teams:SimpleTeamItem[]}>>('simple/teams/mine',{method:'GET',eoTransformKeys:['app_num','subscribe_num']}).then(response=>{
54+
fetchData<BasicResponse<{ teams: SimpleTeamItem[] }>>(!checkPermission('system.workspace.team.view_all') ?'simple/teams/mine' :'simple/teams',{method:'GET',eoTransformKeys:['app_num','subscribe_num']}).then(response=>{
5555
const {code,data,msg} = response
5656
if(code === STATUS_CODE.SUCCESS){
5757
setTeamList(data.teams.map((x:SimpleTeamItem)=>({label:<div className="flex items-center justify-between "><span className="w-[calc(100%-42px)] truncate" title={x.name}>{x.name}</span><span className="bg-[#fff] rounded-[5px] h-[20px] w-[30px] flex items-center justify-center">{x.appNum || 0}</span></div>, key:x.id})))

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ go 1.21
77
require (
88
github.com/eolinker/ap-account v1.0.9
99
github.com/eolinker/eosc v0.17.3
10-
github.com/eolinker/go-common v1.0.2
10+
github.com/eolinker/go-common v1.0.4
1111
github.com/gabriel-vasile/mimetype v1.4.4
1212
github.com/gin-gonic/gin v1.10.0
1313
github.com/google/uuid v1.6.0
@@ -67,3 +67,4 @@ require (
6767
)
6868

6969
//replace github.com/eolinker/ap-account => ../../eolinker/ap-account
70+
//replace github.com/eolinker/go-common => ../../eolinker/go-common

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ github.com/eolinker/ap-account v1.0.9 h1:tW345b1wsn0V8pfMMlZOMfpbjxQhMWBVfgsClFT
2727
github.com/eolinker/ap-account v1.0.9/go.mod h1:5lsZwkQfnHO5YJ3Cu6X1PZwZ0gbmJBUcix0hxG8aEsY=
2828
github.com/eolinker/eosc v0.17.3 h1:sr2yT+v/AsqEdciRaaZZj0zL9pTufR5RvDW6+65hraQ=
2929
github.com/eolinker/eosc v0.17.3/go.mod h1:xgq816hpanlMXFtZw7Ztdctb1eEk9UPHchY4NfFO6Cw=
30-
github.com/eolinker/go-common v1.0.2 h1:rGxcrDdHr+mtMHVPdz3tx7oOsKLo0Msy6W0U1ZNsXaQ=
31-
github.com/eolinker/go-common v1.0.2/go.mod h1:Kb/jENMN1mApnodvRgV4YwO9FJby1Jkt2EUjrBjvSX4=
30+
github.com/eolinker/go-common v1.0.4 h1:F0akjnzJfIFOVmK30fD0SsCLU7DAKPXuY21MeyMmQ7w=
31+
github.com/eolinker/go-common v1.0.4/go.mod h1:Kb/jENMN1mApnodvRgV4YwO9FJby1Jkt2EUjrBjvSX4=
3232
github.com/gabriel-vasile/mimetype v1.4.4 h1:QjV6pZ7/XZ7ryI2KuyeEDE8wnh7fHP9YnQy+R0LnH8I=
3333
github.com/gabriel-vasile/mimetype v1.4.4/go.mod h1:JwLei5XPtWdGiMFB5Pjle1oEeoSeEuJfJE+TtfvdB/s=
3434
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=

module/my-team/iml.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,40 @@ type imlTeamModule struct {
3939
transaction store.ITransaction `autowired:""`
4040
}
4141

42+
func (m *imlTeamModule) SimpleTeams(ctx context.Context, keyword string) ([]*team_dto.SimpleTeam, error) {
43+
teams, err := m.teamService.Search(ctx, keyword, nil)
44+
if err != nil {
45+
return nil, err
46+
}
47+
projects, err := m.serviceService.Search(ctx, "", nil)
48+
projectCount := make(map[string]int64)
49+
appCount := make(map[string]int64)
50+
for _, p := range projects {
51+
if p.AsServer {
52+
if _, ok := projectCount[p.Team]; !ok {
53+
projectCount[p.Team] = 0
54+
}
55+
projectCount[p.Team]++
56+
}
57+
if p.AsApp {
58+
if _, ok := appCount[p.Team]; !ok {
59+
appCount[p.Team] = 0
60+
}
61+
appCount[p.Team]++
62+
}
63+
}
64+
65+
return utils.SliceToSlice(teams, func(s *team.Team) *team_dto.SimpleTeam {
66+
return &team_dto.SimpleTeam{
67+
Id: s.Id,
68+
Name: s.Name,
69+
Description: s.Description,
70+
ServiceNum: projectCount[s.Id],
71+
AppNum: appCount[s.Id],
72+
}
73+
}), nil
74+
}
75+
4276
func (m *imlTeamModule) UpdateMemberRole(ctx context.Context, id string, input *team_dto.UpdateMemberRole) error {
4377
_, err := m.teamService.Get(ctx, id)
4478
if err != nil {
@@ -157,7 +191,7 @@ func (m *imlTeamModule) Edit(ctx context.Context, id string, input *team_dto.Edi
157191
return m.GetTeam(ctx, id)
158192
}
159193

160-
func (m *imlTeamModule) SimpleTeams(ctx context.Context, keyword string) ([]*team_dto.SimpleTeam, error) {
194+
func (m *imlTeamModule) MySimpleTeams(ctx context.Context, keyword string) ([]*team_dto.SimpleTeam, error) {
161195
userID := utils.UserId(ctx)
162196
memberMap, err := m.teamMemberService.FilterMembersForUser(ctx, userID)
163197
if err != nil {

0 commit comments

Comments
 (0)