Skip to content

Commit

Permalink
more project api refactoring, fix test role init (#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Mar 13, 2023
1 parent 4b3c0a6 commit 65bb633
Show file tree
Hide file tree
Showing 21 changed files with 375 additions and 262 deletions.
2 changes: 2 additions & 0 deletions docs/source/major_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ effected code accordingly.
``RoleAssignment`` model queries.
- ``Project.get_all_roles()`` has been removed. ``Project.get_roles()`` should
be used in its place.
- ``Project.get_delegates()`` returns a ``list`` instead of a ``QuerySet``. The
method signature has also been changed.

Base Classes for Tests Updated
------------------------------
Expand Down
11 changes: 8 additions & 3 deletions filesfolders/tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
from test_plus.test import TestCase

# Projectroles dependency
from projectroles.models import Role, SODAR_CONSTANTS
from projectroles.models import SODAR_CONSTANTS
from projectroles.plugins import ProjectAppPluginPoint
from projectroles.tests.test_models import ProjectMixin, RoleAssignmentMixin
from projectroles.tests.test_models import (
ProjectMixin,
RoleMixin,
RoleAssignmentMixin,
)

from filesfolders.urls import urlpatterns
from filesfolders.tests.test_models import (
Expand Down Expand Up @@ -36,6 +40,7 @@

class TestPlugins(
ProjectMixin,
RoleMixin,
FolderMixin,
FileMixin,
HyperLinkMixin,
Expand All @@ -51,7 +56,7 @@ def setUp(self):
self.user.is_superuser = True
self.user.save()
# Init roles
self.role_owner = Role.objects.get_or_create(name=PROJECT_ROLE_OWNER)[0]
self.init_roles()
# Init project and owner role
self.project = self.make_project(
'TestProject', PROJECT_TYPE_PROJECT, None
Expand Down
24 changes: 13 additions & 11 deletions filesfolders/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
from test_plus.test import TestCase

# Projectroles dependency
from projectroles.models import Role, SODAR_CONSTANTS
from projectroles.tests.test_models import ProjectMixin, RoleAssignmentMixin
from projectroles.models import SODAR_CONSTANTS
from projectroles.tests.test_models import (
ProjectMixin,
RoleMixin,
RoleAssignmentMixin,
)
from projectroles.app_settings import AppSettingAPI

from filesfolders.models import File, Folder, HyperLink
Expand Down Expand Up @@ -43,19 +47,17 @@


class TestViewsBaseMixin(
ProjectMixin, RoleAssignmentMixin, FileMixin, FolderMixin, HyperLinkMixin
ProjectMixin,
RoleMixin,
RoleAssignmentMixin,
FileMixin,
FolderMixin,
HyperLinkMixin,
):
def setUp(self):
self.req_factory = RequestFactory()
# Init roles
self.role_owner = Role.objects.get_or_create(name=PROJECT_ROLE_OWNER)[0]
self.role_delegate = Role.objects.get_or_create(
name=PROJECT_ROLE_DELEGATE
)[0]
self.role_contributor = Role.objects.get_or_create(
name=PROJECT_ROLE_CONTRIBUTOR
)[0]
self.role_guest = Role.objects.get_or_create(name=PROJECT_ROLE_GUEST)[0]
self.init_roles()
# Init superuser
self.user = self.make_user('superuser')
self.user.is_staff = True
Expand Down
6 changes: 3 additions & 3 deletions projectroles/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ def clean(self):
# Ensure delegate limit is not exceeded
if (
del_limit != 0
and self.project.get_delegates(exclude_inherited=True).count()
and len(self.project.get_delegates(inherited=False))
>= del_limit
):
self.add_error(
Expand Down Expand Up @@ -887,7 +887,7 @@ def clean_old_owner_role(self):
del_limit != 0
and new_owner_role
and new_owner_role.role.name != PROJECT_ROLE_DELEGATE
and self.project.get_delegates(exclude_inherited=True).count()
and len(self.project.get_delegates(inherited=False))
>= del_limit
):
raise forms.ValidationError(
Expand Down Expand Up @@ -1026,7 +1026,7 @@ def clean(self):
# Ensure delegate limit is not exceeded
if (
del_limit != 0
and self.project.get_delegates(exclude_inherited=True).count()
and len(self.project.get_delegates(inherited=False))
>= del_limit
):
self.add_error(
Expand Down
4 changes: 2 additions & 2 deletions projectroles/management/commands/batchupdateroles.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def _update_role(self, project, user, role):
logger.info(
'Updating role of user {} to {}..'.format(user.username, role.name)
)
# TODO: Update to handle other inherited users
if user in [a.user for a in project.get_owners(inherited_only=True)]:
logger.info('Skipping as user has inherited ownership')
return
Expand Down Expand Up @@ -145,8 +146,7 @@ def _handle_list_row(self, project, role_name, email):
if (
role == self.del_role
and del_limit != 0
and project.get_delegates(exclude_inherited=True).count()
>= del_limit
and len(project.get_delegates(inherited=False)) >= del_limit
):
raise Exception(
'Delegate limit of {} has been reached'.format(del_limit)
Expand Down
Loading

0 comments on commit 65bb633

Please sign in to comment.