APIPark访客模式完成

This commit is contained in:
Liujian
2024-08-16 20:55:16 +08:00
parent 7a8557590c
commit d82fe39a17
16 changed files with 117 additions and 81 deletions
+7 -3
View File
@@ -14,6 +14,10 @@ type imlTeamController struct {
module my_team.ITeamModule `autowired:""`
}
func (c *imlTeamController) SimpleTeams(ctx *gin.Context, keyword string) ([]*team_dto.SimpleTeam, error) {
return c.module.SimpleTeams(ctx, keyword)
}
func (c *imlTeamController) UpdateMemberRole(ctx *gin.Context, id string, input *team_dto.UpdateMemberRole) error {
return c.module.UpdateMemberRole(ctx, id, input)
}
@@ -23,7 +27,7 @@ func (c *imlTeamController) GetTeam(ctx *gin.Context, id string) (*team_dto.Team
}
func (c *imlTeamController) Search(ctx *gin.Context, keyword string) ([]*team_dto.Item, error) {
return c.module.Search(ctx, keyword)
}
@@ -31,8 +35,8 @@ func (c *imlTeamController) EditTeam(ctx *gin.Context, id string, team *team_dto
return c.module.Edit(ctx, id, team)
}
func (c *imlTeamController) SimpleTeams(ctx *gin.Context, keyword string) ([]*team_dto.SimpleTeam, error) {
return c.module.SimpleTeams(ctx, keyword)
func (c *imlTeamController) MySimpleTeams(ctx *gin.Context, keyword string) ([]*team_dto.SimpleTeam, error) {
return c.module.MySimpleTeams(ctx, keyword)
}
func (c *imlTeamController) AddMember(ctx *gin.Context, id string, users *team_dto.UserIDs) error {
+2 -1
View File
@@ -2,7 +2,7 @@ package my_team
import (
"reflect"
team_dto "github.com/APIParkLab/APIPark/module/my-team/dto"
"github.com/eolinker/go-common/autowire"
"github.com/gin-gonic/gin"
@@ -13,6 +13,7 @@ type ITeamController interface {
GetTeam(ctx *gin.Context, id string) (*team_dto.Team, error)
Search(ctx *gin.Context, keyword string) ([]*team_dto.Item, error)
EditTeam(ctx *gin.Context, id string, team *team_dto.EditTeam) (*team_dto.Team, error)
MySimpleTeams(ctx *gin.Context, keyword string) ([]*team_dto.SimpleTeam, error)
SimpleTeams(ctx *gin.Context, keyword string) ([]*team_dto.SimpleTeam, error)
AddMember(ctx *gin.Context, id string, users *team_dto.UserIDs) error
RemoveMember(ctx *gin.Context, id string, uuid string) error
@@ -109,17 +109,22 @@ export const GlobalProvider: FC<{children:ReactNode}> = ({ children }) => {
const [pluginAccessDictionary, setPluginAccessDictionary] = useState<{[k:string]:string}>({})
const [teamDataFlushed, setTeamDataFlushed] = useState<boolean>(false)
const [accessInit, setAccessInit] = useState<boolean>(false)
let getGlobalAccessPromise: Promise<BasicResponse<{ access:string[] }>> | null = null
const getGlobalAccessData = ()=>{
fetchData<BasicResponse<{ access:string[]}>>('profile/permission/system',{method:'GET'},).then(response=>{
getGlobalAccessPromise = new Promise((resolve, reject) => fetchData<BasicResponse<{ access:string[]}>>('profile/permission/system',{method:'GET'},).then(response=>{
const {code,data,msg} = response
if(code === STATUS_CODE.SUCCESS){
setAccessInit(true)
setAccessData(prevData => new Map(prevData).set('system', data.access))
resolve(data.response)
}else{
message.error(msg || '操作失败')
reject(data.msg || '操作失败')
}
})
)
return getGlobalAccessData
}
const getTeamAccessData = (teamId:string)=>{
@@ -149,7 +154,13 @@ export const GlobalProvider: FC<{children:ReactNode}> = ({ children }) => {
setPluginAccessDictionary({})
}
const checkPermission = (access:keyof typeof PERMISSION_DEFINITION[0] | Array<keyof typeof PERMISSION_DEFINITION[0]>)=>{
const checkPermission = async (access:keyof typeof PERMISSION_DEFINITION[0] | Array<keyof typeof PERMISSION_DEFINITION[0]>)=>{
if( !accessInit && getGlobalAccessPromise){
await getGlobalAccessPromise
}
if( !accessInit && !getGlobalAccessPromise){
await getGlobalAccessData()
}
let revs = false;
if (Array.isArray(access)) {
revs = access.some(item => checkAccess(item, accessData));
@@ -20,6 +20,7 @@ import { getImgBase64 } from "@common/utils/dataTransfer.ts";
import { CategorizesType } from "@market/const/serviceHub/type.ts";
import WithPermission from "@common/components/aoplatform/WithPermission.tsx";
import { Icon } from "@iconify/react/dist/iconify.js";
import { useGlobalContext } from "@common/contexts/GlobalStateContext.tsx";
const MAX_SIZE = 2 * 1024; // 1KB
@@ -38,6 +39,7 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_,ref) => {
const [tagOptionList, setTagOptionList] = useState<DefaultOptionType[]>([])
const [serviceClassifyOptionList, setServiceClassifyOptionList] = useState<DefaultOptionType[]>()
const [uploadLoading, setUploadLoading] = useState<boolean>(false)
const {checkPermission} = useGlobalContext()
useImperativeHandle(ref, () => ({
save:onFinish
@@ -157,7 +159,8 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_,ref) => {
const getTeamOptionList = ()=>{
setTeamOptionList([])
fetchData<BasicResponse<{ teams: SimpleTeamItem[] }>>('simple/teams/mine',{method:'GET',eoTransformKeys:['available_partitions']}).then(response=>{
fetchData<BasicResponse<{ teams: SimpleTeamItem[] }>>(!checkPermission('system.workspace.team.view_all') ?'simple/teams/mine' :'simple/teams',{method:'GET',eoTransformKeys:[]}).then(response=>{
const {code,data,msg} = response
if(code === STATUS_CODE.SUCCESS){
setTeamOptionList(data.teams?.map((x:MemberItem)=>{return {...x,
@@ -55,7 +55,7 @@ const SystemList:FC = ()=>{
}
const getTeamsList = ()=>{
fetchData<BasicResponse<{teams:SimpleTeamItem[]}>>('simple/teams/mine',{method:'GET'}).then(response=>{
fetchData<BasicResponse<{ teams: SimpleTeamItem[] }>>(!checkPermission('system.workspace.team.view_all') ?'simple/teams/mine' :'simple/teams',{method:'GET',eoTransformKeys:[]}).then(response=>{
const {code,data,msg} = response
setTeamList(data.teams)
if(code === STATUS_CODE.SUCCESS){
@@ -11,12 +11,10 @@ import { EntityItem } from "@common/const/type.ts";
import { ApplyServiceModal } from "./ApplyServiceModal.tsx";
import ServiceHubApiDocument from "./ServiceHubApiDocument.tsx";
import { ApiFilled, ArrowLeftOutlined, LeftOutlined } from "@ant-design/icons";
import { Typography } from 'antd';
import { SimpleSystemItem } from "@core/const/system/type.ts";
import { Icon } from "@iconify/react/dist/iconify.js";
import DOMPurify from 'dompurify';
const { Title, Text } = Typography;
const ServiceHubDetail = ()=>{
const {serviceId} = useParams<RouterParams>();
@@ -51,7 +51,7 @@ const getServiceList = ()=>{
const getTeamsList = ()=>{
setPageLoading(true)
fetchData<BasicResponse<{teams:SimpleTeamItem[]}>>('simple/teams/mine',{method:'GET',eoTransformKeys:['app_num','subscribe_num']}).then(response=>{
fetchData<BasicResponse<{ teams: SimpleTeamItem[] }>>(!checkPermission('system.workspace.team.view_all') ?'simple/teams/mine' :'simple/teams',{method:'GET',eoTransformKeys:['app_num','subscribe_num']}).then(response=>{
const {code,data,msg} = response
if(code === STATUS_CODE.SUCCESS){
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})))
+2 -1
View File
@@ -7,7 +7,7 @@ go 1.21
require (
github.com/eolinker/ap-account v1.0.9
github.com/eolinker/eosc v0.17.3
github.com/eolinker/go-common v1.0.2
github.com/eolinker/go-common v1.0.4
github.com/gabriel-vasile/mimetype v1.4.4
github.com/gin-gonic/gin v1.10.0
github.com/google/uuid v1.6.0
@@ -67,3 +67,4 @@ require (
)
//replace github.com/eolinker/ap-account => ../../eolinker/ap-account
//replace github.com/eolinker/go-common => ../../eolinker/go-common
+2 -2
View File
@@ -27,8 +27,8 @@ github.com/eolinker/ap-account v1.0.9 h1:tW345b1wsn0V8pfMMlZOMfpbjxQhMWBVfgsClFT
github.com/eolinker/ap-account v1.0.9/go.mod h1:5lsZwkQfnHO5YJ3Cu6X1PZwZ0gbmJBUcix0hxG8aEsY=
github.com/eolinker/eosc v0.17.3 h1:sr2yT+v/AsqEdciRaaZZj0zL9pTufR5RvDW6+65hraQ=
github.com/eolinker/eosc v0.17.3/go.mod h1:xgq816hpanlMXFtZw7Ztdctb1eEk9UPHchY4NfFO6Cw=
github.com/eolinker/go-common v1.0.2 h1:rGxcrDdHr+mtMHVPdz3tx7oOsKLo0Msy6W0U1ZNsXaQ=
github.com/eolinker/go-common v1.0.2/go.mod h1:Kb/jENMN1mApnodvRgV4YwO9FJby1Jkt2EUjrBjvSX4=
github.com/eolinker/go-common v1.0.4 h1:F0akjnzJfIFOVmK30fD0SsCLU7DAKPXuY21MeyMmQ7w=
github.com/eolinker/go-common v1.0.4/go.mod h1:Kb/jENMN1mApnodvRgV4YwO9FJby1Jkt2EUjrBjvSX4=
github.com/gabriel-vasile/mimetype v1.4.4 h1:QjV6pZ7/XZ7ryI2KuyeEDE8wnh7fHP9YnQy+R0LnH8I=
github.com/gabriel-vasile/mimetype v1.4.4/go.mod h1:JwLei5XPtWdGiMFB5Pjle1oEeoSeEuJfJE+TtfvdB/s=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
+35 -1
View File
@@ -39,6 +39,40 @@ type imlTeamModule struct {
transaction store.ITransaction `autowired:""`
}
func (m *imlTeamModule) SimpleTeams(ctx context.Context, keyword string) ([]*team_dto.SimpleTeam, error) {
teams, err := m.teamService.Search(ctx, keyword, nil)
if err != nil {
return nil, err
}
projects, err := m.serviceService.Search(ctx, "", nil)
projectCount := make(map[string]int64)
appCount := make(map[string]int64)
for _, p := range projects {
if p.AsServer {
if _, ok := projectCount[p.Team]; !ok {
projectCount[p.Team] = 0
}
projectCount[p.Team]++
}
if p.AsApp {
if _, ok := appCount[p.Team]; !ok {
appCount[p.Team] = 0
}
appCount[p.Team]++
}
}
return utils.SliceToSlice(teams, func(s *team.Team) *team_dto.SimpleTeam {
return &team_dto.SimpleTeam{
Id: s.Id,
Name: s.Name,
Description: s.Description,
ServiceNum: projectCount[s.Id],
AppNum: appCount[s.Id],
}
}), nil
}
func (m *imlTeamModule) UpdateMemberRole(ctx context.Context, id string, input *team_dto.UpdateMemberRole) error {
_, err := m.teamService.Get(ctx, id)
if err != nil {
@@ -157,7 +191,7 @@ func (m *imlTeamModule) Edit(ctx context.Context, id string, input *team_dto.Edi
return m.GetTeam(ctx, id)
}
func (m *imlTeamModule) SimpleTeams(ctx context.Context, keyword string) ([]*team_dto.SimpleTeam, error) {
func (m *imlTeamModule) MySimpleTeams(ctx context.Context, keyword string) ([]*team_dto.SimpleTeam, error) {
userID := utils.UserId(ctx)
memberMap, err := m.teamMemberService.FilterMembersForUser(ctx, userID)
if err != nil {
+5 -3
View File
@@ -3,9 +3,9 @@ package my_team
import (
"context"
"reflect"
"github.com/eolinker/go-common/autowire"
team_dto "github.com/APIParkLab/APIPark/module/my-team/dto"
)
@@ -16,6 +16,8 @@ type ITeamModule interface {
Search(ctx context.Context, keyword string) ([]*team_dto.Item, error)
// Edit 编辑团队
Edit(ctx context.Context, id string, input *team_dto.EditTeam) (*team_dto.Team, error)
// MySimpleTeams 简易搜索团队
MySimpleTeams(ctx context.Context, keyword string) ([]*team_dto.SimpleTeam, error)
// SimpleTeams 简易搜索团队
SimpleTeams(ctx context.Context, keyword string) ([]*team_dto.SimpleTeam, error)
// AddMember 添加团队成员
@@ -26,7 +28,7 @@ type ITeamModule interface {
Members(ctx context.Context, id string, keyword string) ([]*team_dto.Member, error)
// SimpleMembers 获取团队成员简易列表
SimpleMembers(ctx context.Context, id string, keyword string) ([]*team_dto.SimpleMember, error)
// UpdateMemberRole 更新成员角色
UpdateMemberRole(ctx context.Context, id string, input *team_dto.UpdateMemberRole) error
}
+27 -26
View File
@@ -24,31 +24,32 @@ type imlTeamPermitModule struct {
func (m *imlTeamPermitModule) Permissions(ctx context.Context, teamId string) ([]string, error) {
uid := utils.UserId(ctx)
roleMembers, err := m.roleMemberService.List(ctx, role.TeamTarget(teamId), uid)
if err != nil {
return nil, err
}
roleIds := utils.SliceToSlice(roleMembers, func(rm *role.Member) string {
return rm.Role
})
if len(roleMembers) == 0 {
return []string{}, nil
}
roles, err := m.roleService.List(ctx, roleIds...)
if err != nil {
return nil, err
}
permits := make(map[string]struct{})
for _, r := range roles {
for _, p := range r.Permit {
permits[p] = struct{}{}
}
}
return utils.MapToSlice(permits, func(k string, v struct{}) string {
return k
}), nil
//uid := utils.UserId(ctx)
//roleMembers, err := m.roleMemberService.List(ctx, role.TeamTarget(teamId), uid)
//if err != nil {
// return nil, err
//}
//roleIds := utils.SliceToSlice(roleMembers, func(rm *role.Member) string {
// return rm.Role
//})
//if len(roleMembers) == 0 {
// return []string{}, nil
//}
//roles, err := m.roleService.List(ctx, roleIds...)
//if err != nil {
// return nil, err
//}
//permits := make(map[string]struct{})
//for _, r := range roles {
// for _, p := range r.Permit {
// permits[p] = struct{}{}
// }
//}
//
//return utils.MapToSlice(permits, func(k string, v struct{}) string {
// return k
//}), nil
return m.accesses(ctx, teamId)
}
func (m *imlTeamPermitModule) OnComplete() {
@@ -59,7 +60,7 @@ func (m *imlTeamPermitModule) accesses(ctx context.Context, teamId string) ([]st
// 判断是否是访客,如果是,直接返回访客权限
if utils.GuestAllow() && utils.IsGuest(ctx) {
return access.GuestAccess(role.SystemTarget()), nil
return access.GuestAccess(role.GroupTeam), nil
}
uid := utils.UserId(ctx)
roleMembers, err := m.roleMemberService.List(ctx, role.TeamTarget(teamId), uid)
+16 -17
View File
@@ -2,33 +2,33 @@ package core
import (
"net/http"
plugin_cluster "github.com/APIParkLab/APIPark/controller/plugin-cluster"
"github.com/APIParkLab/APIPark/controller/cluster"
"github.com/eolinker/ap-account/controller/role"
"github.com/APIParkLab/APIPark/controller/common"
dynamic_module "github.com/APIParkLab/APIPark/controller/dynamic-module"
"github.com/APIParkLab/APIPark/controller/release"
application_authorization "github.com/APIParkLab/APIPark/controller/application-authorization"
"github.com/APIParkLab/APIPark/controller/subscribe"
"github.com/APIParkLab/APIPark/controller/api"
"github.com/APIParkLab/APIPark/controller/upstream"
"github.com/APIParkLab/APIPark/controller/service"
"github.com/APIParkLab/APIPark/controller/catalogue"
"github.com/APIParkLab/APIPark/controller/my_team"
"github.com/APIParkLab/APIPark/controller/certificate"
"github.com/APIParkLab/APIPark/controller/team_manager"
"github.com/eolinker/go-common/autowire"
@@ -47,7 +47,7 @@ func (d *Driver) Access() map[string][]string {
}
func (d *Driver) Create() (pm3.IPlugin, error) {
p := new(plugin)
autowire.Autowired(p)
return p, nil
@@ -76,7 +76,6 @@ type plugin struct {
}
func (p *plugin) OnComplete() {
p.apis = append(p.apis, p.partitionApi()...)
p.apis = append(p.apis, p.certificateApi()...)
p.apis = append(p.apis, p.clusterApi()...)
p.apis = append(p.apis, p.TeamManagerApi()...)
@@ -89,7 +88,7 @@ func (p *plugin) OnComplete() {
p.apis = append(p.apis, p.projectAuthorizationApis()...)
p.apis = append(p.apis, p.releaseApis()...)
p.apis = append(p.apis, p.DynamicModuleApis()...)
p.apis = append(p.apis, p.PartitionPluginApi()...)
p.apis = append(p.apis, p.commonApis()...)
}
+2 -1
View File
@@ -10,7 +10,8 @@ func (p *plugin) MyTeamApi() []pm3.Api {
return []pm3.Api{
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/team", []string{"context", "query:team"}, []string{"team"}, p.myTeamController.GetTeam),
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/teams", []string{"context", "query:keyword"}, []string{"teams"}, p.myTeamController.Search),
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/simple/teams/mine", []string{"context", "query:keyword"}, []string{"teams"}, p.myTeamController.SimpleTeams),
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/simple/teams/mine", []string{"context", "query:keyword"}, []string{"teams"}, p.myTeamController.MySimpleTeams),
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/simple/teams", []string{"context", "query:keyword"}, []string{"teams"}, p.myTeamController.SimpleTeams),
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/team/members/simple", []string{"context", "query:team", "query:keyword"}, []string{"teams"}, p.myTeamController.SimpleMembers),
pm3.CreateApiWidthDoc(http.MethodPut, "/api/v1/team", []string{"context", "query:team", "body"}, []string{"team"}, p.myTeamController.EditTeam),
pm3.CreateApiWidthDoc(http.MethodPost, "/api/v1/team/member", []string{"context", "query:team", "body"}, nil, p.myTeamController.AddMember),
-17
View File
@@ -1,17 +0,0 @@
package core
import (
"github.com/eolinker/go-common/pm3"
)
func (p *plugin) partitionApi() []pm3.Api {
return []pm3.Api{
//pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/partitions", []string{"context", "query:keyword"}, []string{"partitions"}, p.partitionController.Search),
//pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/partition", []string{"context", "query:id"}, []string{"partition"}, p.partitionController.Info),
//pm3.CreateApiWidthDoc(http.MethodPost, "/api/v1/partition", []string{"context", "body"}, []string{"partition", "id", "update_time"}, p.partitionController.Create),
//pm3.CreateApiWidthDoc(http.MethodPut, "/api/v1/partition", []string{"context", "query:id", "body"}, []string{"partition"}, p.partitionController.Update),
//pm3.CreateApiWidthDoc(http.MethodDelete, "/api/v1/partition", []string{"context", "query:id"}, []string{"id"}, p.partitionController.Delete),
//pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/simple/partitions", []string{"context"}, []string{"partitions"}, p.partitionController.Simple),
//pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/simple/partitions/cluster", []string{"context"}, []string{"partitions"}, p.partitionController.SimpleWithCluster),
}
}
-2
View File
@@ -290,7 +290,6 @@ team:
cname: 管理
value: 'manager'
apis:
- "GET:/api/v1/service/info"
- "PUT:/api/v1/service/info"
- "POST:/api/v1/team/service"
- "DELETE:/api/v1/team/service"
@@ -342,7 +341,6 @@ team:
cname: 管理
value: 'manager'
apis:
- "GET:/api/v1/app/info"
- "PUT:/api/v1/app/info"
- "POST:/api/v1/team/app"
- "DELETE:/api/v1/app"