feat: agent devices/sessions filter by agent-associated users only

- Add created_by field to AppUser model to track who created the user
- Set created_by when agent creates users
- Extract getAgentUserIDs() helper: finds users who recharged with agent/sub-agent cards OR were created by agent/sub-agent
- Extract getAgentAppIDs() helper: finds agent's authorized applications
- Refactor handleGetUsers and checkAgentUserPermission to use getAgentUserIDs
- Create agent-specific handleGetDevices: filter by agent user IDs + app IDs
- Create agent-specific handleGetSessions: filter by agent user IDs + app IDs
- Replace admin handler references with agent-specific handlers for GET routes
This commit is contained in:
2026-05-11 11:53:43 +08:00
parent 853c22fdbe
commit ed73bb470c
2 changed files with 285 additions and 26 deletions
+1
View File
@@ -61,6 +61,7 @@ type AppUser struct {
IsTrialUser bool `gorm:"default:false" json:"is_trial_user"`
TrialStartAt *time.Time `json:"trial_start_at"`
TrialEndAt *time.Time `json:"trial_end_at"`
CreatedBy *uint `gorm:"index" json:"created_by"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`