Skip to content

Commit 5ee6ab1

Browse files
authored
Wire CanManageAgentSession through VideoGrant (#1557)
* wire CanManageAgentSession through VideoGrant The proto field was added in #1390 but never wired into the VideoGrant, so the permission was silently dropped when set via token. Also fixes Clone missing the deep-copy for CanSubscribeMetrics. * Create rotten-chairs-deliver.md
1 parent ec9bddc commit 5ee6ab1

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
3+
---
4+
5+
Wire CanManageAgentSession through VideoGrant

auth/grants.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ type VideoGrant struct {
278278
// if a participant can subscribe to metrics
279279
CanSubscribeMetrics *bool `json:"canSubscribeMetrics,omitempty"`
280280

281+
// if a participant can manage an agent session via RemoteSession
282+
CanManageAgentSession *bool `json:"canManageAgentSession,omitempty"`
283+
281284
// destination room which this participant can forward to
282285
DestinationRoom string `json:"destinationRoom,omitempty"`
283286
}
@@ -309,6 +312,10 @@ func (v *VideoGrant) SetCanSubscribeMetrics(val bool) {
309312
v.CanSubscribeMetrics = &val
310313
}
311314

315+
func (v *VideoGrant) SetCanManageAgentSession(val bool) {
316+
v.CanManageAgentSession = &val
317+
}
318+
312319
func (v *VideoGrant) GetCanPublish() bool {
313320
if v.CanPublish == nil {
314321
return true
@@ -373,6 +380,13 @@ func (v *VideoGrant) GetCanSubscribeMetrics() bool {
373380
return *v.CanSubscribeMetrics
374381
}
375382

383+
func (v *VideoGrant) GetCanManageAgentSession() bool {
384+
if v.CanManageAgentSession == nil {
385+
return false
386+
}
387+
return *v.CanManageAgentSession
388+
}
389+
376390
func (v *VideoGrant) MatchesPermission(permission *livekit.ParticipantPermission) bool {
377391
if permission == nil {
378392
return false
@@ -405,6 +419,9 @@ func (v *VideoGrant) MatchesPermission(permission *livekit.ParticipantPermission
405419
if v.GetCanSubscribeMetrics() != permission.CanSubscribeMetrics {
406420
return false
407421
}
422+
if v.GetCanManageAgentSession() != permission.CanManageAgentSession {
423+
return false
424+
}
408425

409426
return true
410427
}
@@ -423,6 +440,7 @@ func (v *VideoGrant) UpdateFromPermission(permission *livekit.ParticipantPermiss
423440
v.Recorder = permission.Recorder
424441
v.Agent = permission.Agent
425442
v.SetCanSubscribeMetrics(permission.CanSubscribeMetrics)
443+
v.SetCanManageAgentSession(permission.CanManageAgentSession)
426444
}
427445

428446
func (v *VideoGrant) ToPermission() *livekit.ParticipantPermission {
@@ -435,7 +453,8 @@ func (v *VideoGrant) ToPermission() *livekit.ParticipantPermission {
435453
Hidden: v.Hidden,
436454
Recorder: v.Recorder,
437455
Agent: v.Agent,
438-
CanSubscribeMetrics: v.GetCanSubscribeMetrics(),
456+
CanSubscribeMetrics: v.GetCanSubscribeMetrics(),
457+
CanManageAgentSession: v.GetCanManageAgentSession(),
439458
}
440459
}
441460

@@ -471,6 +490,16 @@ func (v *VideoGrant) Clone() *VideoGrant {
471490
clone.CanUpdateOwnMetadata = &canUpdateOwnMetadata
472491
}
473492

493+
if v.CanSubscribeMetrics != nil {
494+
canSubscribeMetrics := *v.CanSubscribeMetrics
495+
clone.CanSubscribeMetrics = &canSubscribeMetrics
496+
}
497+
498+
if v.CanManageAgentSession != nil {
499+
canManageAgentSession := *v.CanManageAgentSession
500+
clone.CanManageAgentSession = &canManageAgentSession
501+
}
502+
474503
return &clone
475504
}
476505

@@ -508,6 +537,7 @@ func (v *VideoGrant) MarshalLogObject(e zapcore.ObjectEncoder) error {
508537
logBoolPtr("Agent", &v.Agent)
509538

510539
logBoolPtr("CanSubscribeMetrics", v.CanSubscribeMetrics)
540+
logBoolPtr("CanManageAgentSession", v.CanManageAgentSession)
511541
e.AddString("DestinationRoom", v.DestinationRoom)
512542
return nil
513543
}

0 commit comments

Comments
 (0)