Skip to content

Commit 6b38725

Browse files
committed
Feedbacks | Events | guest events to not include following events | user/org events to include its repo/version events
1 parent bd697f4 commit 6b38725

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

core/common/mixins.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from core.common.constants import HEAD, ACCESS_TYPE_NONE, INCLUDE_FACETS, \
2020
LIST_DEFAULT_LIMIT, HTTP_COMPRESS_HEADER, CSV_DEFAULT_LIMIT, FACETS_ONLY, INCLUDE_RETIRED_PARAM, \
2121
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
2323
from core.common.permissions import HasPrivateAccess, HasOwnership, CanViewConceptDictionary, \
2424
CanViewConceptDictionaryVersion
2525
from .checksums import ChecksumModel
@@ -508,6 +508,26 @@ def sources_url(self):
508508
def collections_url(self):
509509
return self.uri + 'collections/'
510510

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+
511531

512532
class SourceChildMixin(ChecksumModel):
513533
class Meta:

core/events/models.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Event(models.Model):
1717
FOLLOWED = 'Followed'
1818
UNFOLLOWED = 'Unfollowed'
1919
JOINED = 'Joined'
20-
HIGHLIGHT_EVENT_TYPES = [CREATED, RELEASED, FOLLOWED]
20+
HIGHLIGHT_EVENT_TYPES = [CREATED, RELEASED]
2121

2222
@property
2323
def is_joined_ocl(self):
@@ -49,16 +49,17 @@ def get_events_for_following(cls, following_queryset, private=False, **event_kwa
4949
def get_user_organization_events(cls, user, private=False):
5050
queryset = cls.objects.none()
5151
for org in user.organizations.filter():
52-
events = org.events
53-
if not private:
54-
events = events.filter(public=True)
55-
queryset = queryset.union(events)
52+
queryset = queryset.union(
53+
org.events.filter(public=True) if private else org.events
54+
).union(org.get_repo_events(private))
55+
5656
return queryset
5757

5858
@classmethod
5959
def get_user_all_events(cls, user, private=False):
6060
return cls.get_user_organization_events(user, private).union(
61-
cls.get_user_following_events(user, private))
61+
cls.get_user_following_events(user, private)
62+
).union(user.get_repo_events(private))
6263

6364
@property
6465
def type(self):

0 commit comments

Comments
 (0)