IsEnabled returns whether debug logging is enabled for the given chat.
( ctx context.Context, chatID uuid.UUID, ownerID uuid.UUID, )
| 217 | |
| 218 | // IsEnabled returns whether debug logging is enabled for the given chat. |
| 219 | func (s *Service) IsEnabled( |
| 220 | ctx context.Context, |
| 221 | chatID uuid.UUID, |
| 222 | ownerID uuid.UUID, |
| 223 | ) bool { |
| 224 | if s == nil { |
| 225 | return false |
| 226 | } |
| 227 | if s.alwaysEnable { |
| 228 | return true |
| 229 | } |
| 230 | if s.db == nil { |
| 231 | return false |
| 232 | } |
| 233 | |
| 234 | authCtx := chatdContext(ctx) |
| 235 | |
| 236 | allowUsers, err := s.db.GetChatDebugLoggingAllowUsers(authCtx) |
| 237 | if err != nil { |
| 238 | if errors.Is(err, sql.ErrNoRows) { |
| 239 | return false |
| 240 | } |
| 241 | s.log.Warn(ctx, "failed to load runtime admin chat debug logging setting", |
| 242 | slog.Error(err), |
| 243 | ) |
| 244 | return false |
| 245 | } |
| 246 | if !allowUsers { |
| 247 | return false |
| 248 | } |
| 249 | |
| 250 | if ownerID == uuid.Nil { |
| 251 | s.log.Warn(ctx, "missing chat owner for debug logging enablement check", |
| 252 | slog.F("chat_id", chatID), |
| 253 | ) |
| 254 | return false |
| 255 | } |
| 256 | |
| 257 | enabled, err := s.db.GetUserChatDebugLoggingEnabled(authCtx, ownerID) |
| 258 | if err == nil { |
| 259 | return enabled |
| 260 | } |
| 261 | if errors.Is(err, sql.ErrNoRows) { |
| 262 | return false |
| 263 | } |
| 264 | |
| 265 | s.log.Warn(ctx, "failed to load user chat debug logging setting", |
| 266 | slog.Error(err), |
| 267 | slog.F("chat_id", chatID), |
| 268 | slog.F("owner_id", ownerID), |
| 269 | ) |
| 270 | return false |
| 271 | } |
| 272 | |
| 273 | // CreateRun inserts a new debug run and emits a run update event. |
| 274 | func (s *Service) CreateRun( |