|
19 | 19 | from core.common.constants import HEAD, ACCESS_TYPE_NONE, INCLUDE_FACETS, \ |
20 | 20 | LIST_DEFAULT_LIMIT, HTTP_COMPRESS_HEADER, CSV_DEFAULT_LIMIT, FACETS_ONLY, INCLUDE_RETIRED_PARAM, \ |
21 | 21 | SEARCH_STATS_ONLY, INCLUDE_SEARCH_STATS, UPDATED_BY_USERNAME_PARAM, CHECKSUM_STANDARD_HEADER, \ |
22 | | - CHECKSUM_SMART_HEADER, SEARCH_LATEST_REPO_VERSION, SAME_STANDARD_CHECKSUM_ERROR |
| 22 | + CHECKSUM_SMART_HEADER, SEARCH_LATEST_REPO_VERSION, SAME_STANDARD_CHECKSUM_ERROR, ACCESS_TYPE_VIEW, ACCESS_TYPE_EDIT |
23 | 23 | from core.common.permissions import HasPrivateAccess, HasOwnership, CanViewConceptDictionary, \ |
24 | 24 | CanViewConceptDictionaryVersion |
25 | 25 | from .checksums import ChecksumModel |
@@ -508,6 +508,26 @@ def sources_url(self): |
508 | 508 | def collections_url(self): |
509 | 509 | return self.uri + 'collections/' |
510 | 510 |
|
| 511 | + def get_repo_events(self, private=False): |
| 512 | + def get_events_for(entity): |
| 513 | + return entity.events.filter(public=True) if private else entity.events |
| 514 | + |
| 515 | + queryset = self.__class__.objects.none() |
| 516 | + |
| 517 | + sources = self.source_set.filter(is_active=True) |
| 518 | + collections = self.collection_set.filter(is_active=True) |
| 519 | + |
| 520 | + if not private: |
| 521 | + sources = self.source_set.filter(public_access__in=[ACCESS_TYPE_VIEW, ACCESS_TYPE_EDIT]) |
| 522 | + collections = self.collection_set.filter(public_access__in=[ACCESS_TYPE_VIEW, ACCESS_TYPE_EDIT]) |
| 523 | + |
| 524 | + for source in sources: |
| 525 | + queryset = queryset.union(get_events_for(source)) |
| 526 | + for collection in collections: |
| 527 | + queryset = queryset.union(get_events_for(collection)) |
| 528 | + |
| 529 | + return queryset |
| 530 | + |
511 | 531 |
|
512 | 532 | class SourceChildMixin(ChecksumModel): |
513 | 533 | class Meta: |
|
0 commit comments