4
0

queue.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package executor
  2. import (
  3. acl "github.com/OliveTin/OliveTin/internal/acl"
  4. authpublic "github.com/OliveTin/OliveTin/internal/auth/authpublic"
  5. config "github.com/OliveTin/OliveTin/internal/config"
  6. )
  7. func isActiveQueueEntry(entry *InternalLogEntry) bool {
  8. return entry != nil && !entry.ExecutionFinished
  9. }
  10. func isQueueEntryVisible(cfg *config.Config, user *authpublic.AuthenticatedUser, entry *InternalLogEntry) bool {
  11. if !isActiveQueueEntry(entry) || !isValidLogEntryForACL(entry) {
  12. return false
  13. }
  14. return acl.IsAllowedLogs(cfg, user, entry.Binding.Action)
  15. }
  16. // GetActiveExecutionsACL returns copies of unfinished executions the user may view in the queue.
  17. // The executor keeps writing to running entries, so callers must not share them.
  18. func (e *Executor) GetActiveExecutionsACL(cfg *config.Config, user *authpublic.AuthenticatedUser) []*InternalLogEntry {
  19. e.logmutex.RLock()
  20. defer e.logmutex.RUnlock()
  21. active := make([]*InternalLogEntry, 0)
  22. for _, trackingID := range e.logsTrackingIdsByDate {
  23. entry := e.logs[trackingID]
  24. if isQueueEntryVisible(cfg, user, entry) {
  25. active = append(active, cloneInternalLogEntry(entry))
  26. }
  27. }
  28. return active
  29. }