Skip to content
Snippets Groups Projects
Commit 17f1ebaf authored by Alena Petraki's avatar Alena Petraki
Browse files

Revert лишних изменений

parent 52813347
No related branches found
No related tags found
No related merge requests found
......@@ -143,7 +143,7 @@ func (c *ClientPrincipal) Client(ctx context.Context) (*clients.Client, error) {
}
func (c *ClientPrincipal) HasEnvironmentAccess(ctx context.Context, spaceID, envID string) bool {
return c.Role(ctx, spaceID).CanAccessEnvironment(WithSystem(ctx), c.environments, spaceID, envID)
return hasEnvironmentAccess(ctx, c.environments, c.Role(ctx, spaceID), envID)
}
func (c *ClientPrincipal) getRoleID(ctx context.Context, spaceID string) (string, bool) {
......@@ -203,7 +203,7 @@ func (c *ClientPrincipal) Rules(ctx context.Context, spaceID, envID string) perm
return permission.PrivilegedRuleset{}
}
if role.CanAccessEnvironment(WithSystem(ctx), c.environments, spaceID, envID) {
if hasEnvironmentAccess(ctx, c.environments, role, envID) {
return role.Rules
}
return nil
......
......@@ -45,42 +45,42 @@ type OrganizationAccessor interface {
Member(ctx context.Context) members.Role
}
//func hasEnvironmentAccess(ctx context.Context, envsrv environments.Environments, role *roles.Role, envID string) bool {
// if role == nil || role.SpaceID == "" || envID == "" {
// return false
// }
//
// if role.AllowManagement {
// return true
// }
//
// envs := role.Environments
//
// // Если явно не указаны доступные окружения - доступ по умолчанию к окружению master
// if len(envs) == 0 {
// envs = []string{environments.DefaultEnvironment}
// }
//
// for _, ce := range envs {
// if envID == ce || util.GlobMatch(envID, ce) {
// return true
// }
// }
//
// e, err := envsrv.Get(WithSystem(ctx), role.SpaceID, envID)
// if err != nil || e == nil {
// return false
// }
//
// aliases := append(e.Aliases, e.ID)
//
// for _, ce := range envs {
// for _, al := range aliases {
// if al == ce || util.GlobMatch(al, ce) {
// return true
// }
// }
// }
//
// return false
//}
func hasEnvironmentAccess(ctx context.Context, envsrv environments.Environments, role *roles.Role, envID string) bool {
if role == nil || role.SpaceID == "" || envID == "" {
return false
}
if role.AllowManagement {
return true
}
envs := role.Environments
// Если явно не указаны доступные окружения - доступ по умолчанию к окружению master
if len(envs) == 0 {
envs = []string{environments.DefaultEnvironment}
}
for _, ce := range envs {
if envID == ce || util.GlobMatch(envID, ce) {
return true
}
}
e, err := envsrv.Get(WithSystem(ctx), role.SpaceID, envID)
if err != nil || e == nil {
return false
}
aliases := append(e.Aliases, e.ID)
for _, ce := range envs {
for _, al := range aliases {
if al == ce || util.GlobMatch(al, ce) {
return true
}
}
}
return false
}
......@@ -12,7 +12,6 @@ import (
"git.perx.ru/perxis/perxis-go/pkg/roles"
"git.perx.ru/perxis/perxis-go/pkg/spaces"
"git.perx.ru/perxis/perxis-go/pkg/users"
"git.perx.ru/perxis/perxis/services"
)
type UserPrincipal struct {
......@@ -306,7 +305,7 @@ func (u *UserPrincipal) Rules(ctx context.Context, spaceID, envID string) permis
return nil
}
if !role.CanAccessEnvironment(WithSystem(ctx), u.environments, spaceID, envID) {
if !hasEnvironmentAccess(ctx, u.environments, role, envID) {
return nil
}
......@@ -331,5 +330,5 @@ func User(ctx context.Context, p Principal) *users.User {
}
func (u *UserPrincipal) HasEnvironmentAccess(ctx context.Context, spaceID, env string) bool {
return u.Role(ctx, spaceID).CanAccessEnvironment(WithSystem(ctx), u.environments, spaceID, env)
return hasEnvironmentAccess(ctx, u.environments, u.Role(ctx, spaceID), env)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment