mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	Only return logs that exist
This commit is contained in:
		@@ -38,14 +38,14 @@ export class LogsComponent implements OnInit, AfterViewChecked {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  reloadLogs() {
 | 
					  reloadLogs() {
 | 
				
			||||||
    this.logService.get(this.activeLog).subscribe(
 | 
					    this.logService.get(this.activeLog).subscribe({
 | 
				
			||||||
      (result) => {
 | 
					      next: (result) => {
 | 
				
			||||||
        this.logs = result
 | 
					        this.logs = result
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      (error) => {
 | 
					      error: () => {
 | 
				
			||||||
        this.logs = []
 | 
					        this.logs = []
 | 
				
			||||||
      }
 | 
					      },
 | 
				
			||||||
    )
 | 
					    })
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  getLogLevel(log: string) {
 | 
					  getLogLevel(log: string) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1590,10 +1590,23 @@ class TestDocumentApi(DirectoriesMixin, APITestCase):
 | 
				
			|||||||
        self.assertEqual(v1.filter_rules.count(), 0)
 | 
					        self.assertEqual(v1.filter_rules.count(), 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_get_logs(self):
 | 
					    def test_get_logs(self):
 | 
				
			||||||
 | 
					        log_data = "test\ntest2\n"
 | 
				
			||||||
 | 
					        with open(os.path.join(settings.LOGGING_DIR, "mail.log"), "w") as f:
 | 
				
			||||||
 | 
					            f.write(log_data)
 | 
				
			||||||
 | 
					        with open(os.path.join(settings.LOGGING_DIR, "paperless.log"), "w") as f:
 | 
				
			||||||
 | 
					            f.write(log_data)
 | 
				
			||||||
        response = self.client.get("/api/logs/")
 | 
					        response = self.client.get("/api/logs/")
 | 
				
			||||||
        self.assertEqual(response.status_code, status.HTTP_200_OK)
 | 
					        self.assertEqual(response.status_code, status.HTTP_200_OK)
 | 
				
			||||||
        self.assertCountEqual(response.data, ["mail", "paperless"])
 | 
					        self.assertCountEqual(response.data, ["mail", "paperless"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_get_logs_only_when_exist(self):
 | 
				
			||||||
 | 
					        log_data = "test\ntest2\n"
 | 
				
			||||||
 | 
					        with open(os.path.join(settings.LOGGING_DIR, "paperless.log"), "w") as f:
 | 
				
			||||||
 | 
					            f.write(log_data)
 | 
				
			||||||
 | 
					        response = self.client.get("/api/logs/")
 | 
				
			||||||
 | 
					        self.assertEqual(response.status_code, status.HTTP_200_OK)
 | 
				
			||||||
 | 
					        self.assertCountEqual(response.data, ["paperless"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_get_invalid_log(self):
 | 
					    def test_get_invalid_log(self):
 | 
				
			||||||
        response = self.client.get("/api/logs/bogus_log/")
 | 
					        response = self.client.get("/api/logs/bogus_log/")
 | 
				
			||||||
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
 | 
					        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -593,11 +593,14 @@ class LogViewSet(ViewSet):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    log_files = ["paperless", "mail"]
 | 
					    log_files = ["paperless", "mail"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_log_filename(self, log):
 | 
				
			||||||
 | 
					        return os.path.join(settings.LOGGING_DIR, f"{log}.log")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def retrieve(self, request, pk=None, *args, **kwargs):
 | 
					    def retrieve(self, request, pk=None, *args, **kwargs):
 | 
				
			||||||
        if pk not in self.log_files:
 | 
					        if pk not in self.log_files:
 | 
				
			||||||
            raise Http404()
 | 
					            raise Http404()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        filename = os.path.join(settings.LOGGING_DIR, f"{pk}.log")
 | 
					        filename = self.get_log_filename(pk)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if not os.path.isfile(filename):
 | 
					        if not os.path.isfile(filename):
 | 
				
			||||||
            raise Http404()
 | 
					            raise Http404()
 | 
				
			||||||
@@ -608,7 +611,10 @@ class LogViewSet(ViewSet):
 | 
				
			|||||||
        return Response(lines)
 | 
					        return Response(lines)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def list(self, request, *args, **kwargs):
 | 
					    def list(self, request, *args, **kwargs):
 | 
				
			||||||
        return Response(self.log_files)
 | 
					        exist = [
 | 
				
			||||||
 | 
					            log for log in self.log_files if os.path.isfile(self.get_log_filename(log))
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					        return Response(exist)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SavedViewViewSet(ModelViewSet, PassUserMixin):
 | 
					class SavedViewViewSet(ModelViewSet, PassUserMixin):
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user