Skip to content

Commit

Permalink
remove project star timeline events (#1294), fix object creation (#1416)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Apr 19, 2024
1 parent b06970a commit 6ace1aa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Fixed
- ``SODARUser.update_full_name()`` not working with existing name (#1371)
- Legacy public guest access in child category breaks category updating (#1404)
- Incorrect DAL widget highlight colour after upgrade (#1412)
- ``ProjectStarringAjaxView`` creating redundant database objects (#1416)
- **Sodarcache**
- REST API set view ``app_name`` incorrectly set (#1405)

Expand All @@ -94,6 +95,7 @@ Removed
- **Projectroles**
- ``PROJECTROLES_HIDE_APP_LINKS`` setting (#1143)
- ``CORE_API_*`` Django settings (#1278)
- Project starring timeline event creation (#1294)


v0.13.4 (2024-02-16)
Expand Down
10 changes: 10 additions & 0 deletions projectroles/tests/test_views_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from test_plus.test import TestCase

from projectroles.app_settings import AppSettingAPI
from projectroles.models import AppSetting
from projectroles.tests.test_models import (
ProjectMixin,
RoleAssignmentMixin,
Expand Down Expand Up @@ -413,6 +414,12 @@ class TestProjectStarringAjaxView(
):
"""Tests for ProjectStarringAjaxView"""

def _assert_setting_count(self, count):
qs = AppSetting.objects.filter(
app_plugin=None, project=self.project, name='project_star'
)
self.assertEqual(qs.count(), count)

def setUp(self):
super().setUp()
self.project = self.make_project(
Expand All @@ -424,6 +431,7 @@ def setUp(self):

def test_project_star(self):
"""Test Starring a Project"""
self._assert_setting_count(0)
with self.login(self.user):
response = self.client.post(
reverse(
Expand All @@ -432,6 +440,7 @@ def test_project_star(self):
)
)
self.assertEqual(response.status_code, 200)
self._assert_setting_count(1)
star = app_settings.get(
'projectroles', 'project_star', self.project, self.user
)
Expand All @@ -448,6 +457,7 @@ def test_project_star(self):
star = app_settings.get(
'projectroles', 'project_star', self.project, self.user
)
self._assert_setting_count(1)
self.assertEqual(star, False)


Expand Down
41 changes: 12 additions & 29 deletions projectroles/views_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
CAT_DELIMITER,
ROLE_RANKING,
)
from projectroles.plugins import get_active_plugins, get_backend_api
from projectroles.plugins import get_active_plugins
from projectroles.utils import get_display_name
from projectroles.views import ProjectAccessMixin, APP_NAME, User
from projectroles.views import ProjectAccessMixin, User
from projectroles.views_api import (
SODARAPIProjectPermission,
CurrentUserRetrieveAPIView,
Expand Down Expand Up @@ -414,38 +414,21 @@ def post(self, request, *args, **kwargs):
# HACK: Manually refuse access to anonymous as this view is an exception
if request.user.is_anonymous:
return Response({'detail': 'Anonymous access denied'}, status=401)

project = self.get_project()
user = request.user
timeline = get_backend_api('timeline_backend')
project_star = app_settings.get(
'projectroles', 'project_star', project, user
)
action_str = '{}star'.format('un' if project_star else '')
if project_star:
app_settings.delete('projectroles', 'project_star', project, user)
else:
app_settings.set(
plugin_name='projectroles',
setting_name='project_star',
value=True,
project=project,
user=user,
validate=False,
)

# Add event in Timeline
if timeline:
timeline.add_event(
project=project,
app_name=APP_NAME,
user=user,
event_name='project_{}'.format(action_str),
description='{} project'.format(action_str),
classified=True,
status_type='INFO',
)
return Response(0 if project_star else 1, status=200)
value = False if project_star else True
app_settings.set(
plugin_name='projectroles',
setting_name='project_star',
value=value,
project=project,
user=user,
validate=False,
)
return Response(1 if value else 0, status=200)


class CurrentUserRetrieveAjaxView(
Expand Down

0 comments on commit 6ace1aa

Please sign in to comment.