created tracker api endpoint and created UI interface for trackers

This commit is contained in:
dtv
2025-10-04 20:18:59 +03:00
parent 269b098f0d
commit 2b863776ae
16 changed files with 597 additions and 8 deletions

View File

@@ -35,3 +35,32 @@ func DeviceAccessFilter() gin.HandlerFunc {
c.Next()
}
}
// TrackerAccessFilter middleware sets filtering context for tracker access
func TrackerAccessFilter() gin.HandlerFunc {
return func(c *gin.Context) {
userContext, exists := c.Get("user")
if !exists {
c.JSON(401, gin.H{"error": "unauthorized"})
c.Abort()
return
}
user, ok := userContext.(handlers.UserContext)
if !ok {
c.JSON(401, gin.H{"error": "invalid user data"})
c.Abort()
return
}
// Set filter flag and user ID in context (mirrors devices)
if user.Role == models.RoleAdmin {
c.Set("filterTrackers", false) // Admin sees all trackers
} else {
c.Set("filterTrackers", true) // Regular user needs filtering
c.Set("userID", user.ID) // Store user ID for filtering (same key as devices)
}
c.Next()
}
}