Skip to content
Snippets Groups Projects
Select Git revision
  • 5172bab8cc90b84b0c83f28ecaa4d3f6d75d53ec
  • master default protected
  • feature/PRXS-3106-NoCache
  • feature/PRXS-3043-NewURLFormat
  • feature/2781-SpacesLoggingMiddleware
  • feature/PRXS-2974-FillImageDimensions
  • feature/PRXS-3143-3235-ReferenceOptions
  • feature/PRXS-3056-LocalesFromToMap
  • feature/PRXS-3421-ImplementNewRefAPI
  • feature/PRXS-3143-LimitReferenceFields
  • feature/PRXS-3234-FeaturePruneIdents
  • PRXS-3421-RecursiveReferences
  • feature/3109-SerializeFeature
  • release/0.33
  • feature/3109-RecoverySchema
  • feature/3109-feature
  • fix/PRXS-3369-ValidateFields
  • refactor/PRXS-3306-MovePkgGroup1
  • refactor/6-pkg-refactor-expr
  • fix/PRXS-3360-TemplateBuilderPatch
  • feature/3293-MongoV2
  • v0.33.1
  • v0.32.0
  • v0.31.1
  • v0.31.0
  • v0.30.0
  • v0.29.0
  • v0.28.0
  • v0.27.0-alpha.1+16
  • v0.27.0-alpha.1+15
  • v0.27.0-alpha.1+14
  • v0.27.0-alpha.1+13
  • v0.27.0-alpha.1+12
  • v0.27.0-alpha.1+11
  • v0.27.0-alpha.1+10
  • v0.27.0-alpha.1+9
  • v0.27.0-alpha.1+8
  • v0.27.0-alpha.1+7
  • v0.27.0-alpha.1+6
  • v0.27.0-alpha.1+5
  • v0.27.0-alpha.1+4
41 results

channel_core_test.go

Blame
  • service.go 2.13 KiB
    package roles
    
    import (
    	"context"
    
    	"git.perx.ru/perxis/perxis-go/pkg/data"
    	"git.perx.ru/perxis/perxis-go/pkg/environments"
    	"git.perx.ru/perxis/perxis-go/pkg/permission"
    )
    
    const (
    	AnonymousRole  = "anonymous"
    	AuthorizedRole = "authorized"
    	ViewRole       = "view"
    )
    
    type Role struct {
    	// Внутренний идентификатор роли
    	ID string `json:"id" bson:"_id"`
    
    	// Идентификатор пространства
    	SpaceID string `json:"spaceId" bson:"-"`
    
    	// Описание роли, назначение
    	Description string `json:"description" bson:"description"`
    
    	// Список доступных окружений (ID или Alias)
    	Environments []string `json:"environments" bson:"environments"`
    
    	// Список правил доступа к коллекциям
    	Rules permission.Rules `json:"rules" bson:"rules"`
    
    	// Разрешить доступ API управления
    	AllowManagement bool `json:"allow_management" bson:"allow_management"`
    }
    
    // @microgen grpc
    // @protobuf git.perx.ru/perxis/perxis-go/proto/roles
    // @grpc-addr content.roles.Roles
    type Roles interface {
    	Create(ctx context.Context, role *Role) (created *Role, err error)
    	Get(ctx context.Context, spaceId, roleId string) (role *Role, err error)
    	List(ctx context.Context, spaceId string) (roles []*Role, err error)
    	Update(ctx context.Context, role *Role) (err error)
    	Delete(ctx context.Context, spaceId, roleId string) (err error)
    }
    
    func (r Role) CanAccessEnvironment(ctx context.Context, service environments.Environments, spaceID, envID string) bool {
    	if spaceID == "" || envID == "" {
    		return false
    	}
    
    	// Если явно не указаны доступные окружения - доступ по умолчанию к окружению master
    	if len(r.Environments) == 0 {
    		r.Environments = []string{environments.DefaultEnvironment}
    	}
    
    	if data.Contains(envID, r.Environments) {
    		return true
    	}
    
    	e, err := service.Get(ctx, spaceID, envID)
    	if err != nil || e == nil {
    		return false
    	}
    
    	aliases := append(e.Aliases, e.ID)
    
    	for _, ce := range r.Environments {
    		if data.Contains(ce, aliases) {
    			return true
    		}
    	}
    
    	return false
    }