4
0

queue.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  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 unfinished executions the user may view in the queue.
  17. func (e *Executor) GetActiveExecutionsACL(cfg *config.Config, user *authpublic.AuthenticatedUser) []*InternalLogEntry {
  18. e.logmutex.RLock()
  19. defer e.logmutex.RUnlock()
  20. active := make([]*InternalLogEntry, 0)
  21. for _, trackingID := range e.logsTrackingIdsByDate {
  22. entry := e.logs[trackingID]
  23. if isQueueEntryVisible(cfg, user, entry) {
  24. active = append(active, entry)
  25. }
  26. }
  27. return active
  28. }