Skip to content

Commit

Permalink
add timeline user count stats (#1504), add plugin tests (#1506)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Oct 21, 2024
1 parent 4bce71e commit f5be1cc
Show file tree
Hide file tree
Showing 4 changed files with 347 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Unreleased
Added
-----

- **Timeline**
- User count in siteinfo stats (#1504)
- Plugin tests (#1506)
- **Userprofile**
- Authentication type in user details (#1500)

Expand Down
1 change: 1 addition & 0 deletions docs/source/major_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Release Highlights
==================

- Add auth type in user profile details card
- Add user count in timeline siteinfo statistics
- Fix requiring deprecated SODAR API settings in tests


Expand Down
44 changes: 27 additions & 17 deletions timeline/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
from timeline.urls import urls_ui_project, urls_ui_site, urls_ui_admin


# Local constants
STATS_DESC_USER_COUNT = 'Amount of users who have initiated events'


class ProjectAppPlugin(ProjectAppPluginPoint):
"""Plugin for registering app with Projectroles"""

Expand Down Expand Up @@ -69,29 +73,35 @@ class ProjectAppPlugin(ProjectAppPluginPoint):
#: Names of plugin specific Django settings to display in siteinfo
info_settings = ['TIMELINE_PAGINATION', 'TIMELINE_SEARCH_LIMIT']

@classmethod
def _check_permission(cls, user, event):
"""Check if user has permission to view event"""
if event.project and event.classified:
return user.has_perm(
'timeline.view_classified_event', event.project
)
elif event.project:
return user.has_perm('timeline.view_timeline', event.project)
elif event.classified:
return user.has_perm('timeline.view_classified_site_event')
return user.has_perm('timeline.view_site_timeline')

def get_statistics(self):
return {
'event_count': {
'label': 'Events',
'value': TimelineEvent.objects.all().count(),
}
},
'user_count': {
'label': 'Users',
'description': STATS_DESC_USER_COUNT,
'value': TimelineEvent.objects.exclude(user__isnull=True)
.values('user')
.distinct()
.count(),
},
}

def check_permission(self, user, event):
"""Check if user has permission to view event"""
if event.project is not None:
if event.classified:
return user.has_perm(
'timeline.view_classified_event', event.project
)
else:
return user.has_perm('timeline.view_timeline', event.project)
else:
if event.classified:
return user.has_perm('timeline.view_classified_site_event')
else:
return user.has_perm('timeline.view_site_timeline')

def search(self, search_terms, user, search_type=None, keywords=None):
"""
Return app items based on one or more search terms, user, optional type
Expand All @@ -107,7 +117,7 @@ def search(self, search_terms, user, search_type=None, keywords=None):
items = []
if not search_type or search_type == 'timeline':
events = list(TimelineEvent.objects.find(search_terms, keywords))
items = [e for e in events if self.check_permission(user, e)]
items = [e for e in events if self._check_permission(user, e)]
ret = PluginSearchResult(
category='all',
title='Timeline Events',
Expand Down
Loading

0 comments on commit f5be1cc

Please sign in to comment.