@@ -5,12 +5,14 @@ import (
55 "strings"
66
77 "github.com/goto/shield/core/action"
8+ "github.com/goto/shield/core/group"
89 "github.com/goto/shield/core/namespace"
910 "github.com/goto/shield/core/organization"
1011 "github.com/goto/shield/core/project"
1112 "github.com/goto/shield/core/relation"
1213 "github.com/goto/shield/core/user"
1314 "github.com/goto/shield/internal/schema"
15+ "github.com/goto/shield/pkg/uuid"
1416)
1517
1618type RelationService interface {
@@ -28,21 +30,33 @@ type ProjectService interface {
2830 Get (ctx context.Context , id string ) (project.Project , error )
2931}
3032
33+ type OrganizationService interface {
34+ Get (ctx context.Context , id string ) (organization.Organization , error )
35+ }
36+
37+ type GroupService interface {
38+ Get (ctx context.Context , id string ) (group.Group , error )
39+ }
40+
3141type Service struct {
32- repository Repository
33- configRepository ConfigRepository
34- relationService RelationService
35- userService UserService
36- projectService ProjectService
42+ repository Repository
43+ configRepository ConfigRepository
44+ relationService RelationService
45+ userService UserService
46+ projectService ProjectService
47+ organizationService OrganizationService
48+ groupService GroupService
3749}
3850
39- func NewService (repository Repository , configRepository ConfigRepository , relationService RelationService , userService UserService , projectService ProjectService ) * Service {
51+ func NewService (repository Repository , configRepository ConfigRepository , relationService RelationService , userService UserService , projectService ProjectService , organizationService OrganizationService , groupService GroupService ) * Service {
4052 return & Service {
41- repository : repository ,
42- configRepository : configRepository ,
43- relationService : relationService ,
44- userService : userService ,
45- projectService : projectService ,
53+ repository : repository ,
54+ configRepository : configRepository ,
55+ relationService : relationService ,
56+ userService : userService ,
57+ projectService : projectService ,
58+ organizationService : organizationService ,
59+ groupService : groupService ,
4660 }
4761}
4862
@@ -158,6 +172,28 @@ func (s Service) CheckAuthz(ctx context.Context, res Resource, act action.Action
158172 fetchedResource := res
159173
160174 if isSystemNS {
175+ if ! uuid .IsValid (res .Name ) {
176+ switch res .NamespaceID {
177+ case namespace .DefinitionProject .ID :
178+ project , err := s .projectService .Get (ctx , res .Name )
179+ if err != nil {
180+ return false , err
181+ }
182+ res .Name = project .ID
183+ case namespace .DefinitionOrg .ID :
184+ organization , err := s .organizationService .Get (ctx , res .Name )
185+ if err != nil {
186+ return false , err
187+ }
188+ res .Name = organization .ID
189+ case namespace .DefinitionTeam .ID :
190+ group , err := s .groupService .Get (ctx , res .Name )
191+ if err != nil {
192+ return false , err
193+ }
194+ res .Name = group .ID
195+ }
196+ }
161197 fetchedResource .Idxa = res .Name
162198 } else {
163199 fetchedResource , err = s .repository .GetByNamespace (ctx , res .Name , res .NamespaceID )
0 commit comments