Add SelectOwnProfile handler to allow users to choose from available access profiles. Store selected profile ID per device in settings table with device_access_profile category. Implement GetSelectedProfileID and SetSelectedProfileID repository methods using JSONB storage. Add ListSelectableProfiles to policy repository and service to query user/group/device-specific profiles ordered by priority. Filter gateway
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package policy
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type Service struct {
|
|
repo Repository
|
|
}
|
|
|
|
func NewService(repo Repository) *Service {
|
|
return &Service{repo: repo}
|
|
}
|
|
|
|
func (s *Service) List(ctx context.Context) ([]Policy, error) {
|
|
return s.repo.List(ctx)
|
|
}
|
|
|
|
func (s *Service) Create(ctx context.Context, actorID uuid.UUID, input CreateRequest) (Policy, error) {
|
|
if input.Priority == 0 {
|
|
input.Priority = 100
|
|
}
|
|
if input.Effect == "" {
|
|
input.Effect = "allow"
|
|
}
|
|
return s.repo.Create(ctx, input, actorID)
|
|
}
|
|
|
|
func (s *Service) Update(ctx context.Context, policyID uuid.UUID, input UpdateRequest) (Policy, error) {
|
|
return s.repo.Update(ctx, policyID, input)
|
|
}
|
|
|
|
func (s *Service) Delete(ctx context.Context, policyID uuid.UUID) error {
|
|
return s.repo.Delete(ctx, policyID)
|
|
}
|
|
|
|
func (s *Service) ResolveDestinations(ctx context.Context, userID uuid.UUID, deviceID *uuid.UUID) ([]string, error) {
|
|
return s.repo.ResolveDestinations(ctx, userID, deviceID)
|
|
}
|
|
|
|
func (s *Service) ListSelectableProfiles(ctx context.Context, userID uuid.UUID, deviceID *uuid.UUID) ([]SelectableProfile, error) {
|
|
return s.repo.ListSelectableProfiles(ctx, userID, deviceID)
|
|
}
|