Skip to content

Commit 86f0fcf

Browse files
committed
ref: 2.3.グループ管理連携機能開発: Fix travis error
1 parent 9ff9a13 commit 86f0fcf

4 files changed

Lines changed: 20 additions & 5 deletions

File tree

api_tests/nodes/views/test_node_mapcore_group_views.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def setUp(self):
2323
self.node = ProjectFactory(creator=self.admin_user, is_public=False)
2424
self.node.add_contributor(self.user, permissions='admin')
2525
self.node.add_contributor(self.read_only_user, permissions='read')
26+
self.node.add_addon('groups', auth=Auth(self.user)) # Enable groups addon
2627
self.node.save()
2728

2829
# Create auth groups for the node
@@ -766,8 +767,9 @@ def test_has_permission_mapcore_grants_and_denies(self):
766767
from osf.models.node import NodeGroupObjectPermission
767768

768769
node = ProjectFactory()
769-
# user that will be "in" the mapcore group
770770
mapcore_user = UserFactory()
771+
node.add_addon('groups', auth=Auth(mapcore_user)) # Enable groups addon
772+
# user that will be "in" the mapcore group
771773
# other user not in group
772774
other_user = UserFactory()
773775

@@ -796,7 +798,9 @@ def test_has_permission_by_is_admin_group_parent(self):
796798

797799
# Create a root node and a child node
798800
root = ProjectFactory()
801+
root.add_addon('groups', auth=Auth(root.creator)) # Enable groups addon on root
799802
child = NodeFactory(creator=root.creator, parent=root)
803+
child.add_addon('groups', auth=Auth(root.creator)) # Enable groups addon on child
800804

801805
# Users
802806
mapcore_user = UserFactory()
@@ -843,6 +847,7 @@ def test_get_permissions_mapcore_includes_and_excludes(self):
843847
from osf.models.node import NodeGroupObjectPermission
844848

845849
node = ProjectFactory()
850+
node.add_addon('groups', auth=Auth(node.creator)) # Enable groups addon
846851
mapcore_user = UserFactory()
847852
other_user = UserFactory()
848853

@@ -991,6 +996,7 @@ def test_has_permission_parent_admin_via_mapcore_groups_addon_disabled(self):
991996
from osf.models.node import NodeGroupObjectPermission
992997

993998
root = ProjectFactory()
999+
root.add_addon('groups', auth=Auth(root.creator)) # Enable groups addon on root
9941000
child = NodeFactory(creator=root.creator, parent=root)
9951001
mapcore_user = UserFactory()
9961002

osf/models/mixins.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,7 +1944,10 @@ def has_permission(self, user, permission, check_parent=True):
19441944
"""
19451945
object_type = self.guardian_object_type
19461946
group_perm = []
1947-
enabled_groups = self.mapcore_groups_addon_enabled()
1947+
enabled_groups = False
1948+
if hasattr(self, 'mapcore_groups_addon_enabled'):
1949+
enabled_groups = self.mapcore_groups_addon_enabled()
1950+
19481951
# Also check Auth Groups linked via MapCoreNodeGroup (by auth_group id)
19491952
if object_type == 'node' and enabled_groups:
19501953
try:
@@ -1999,7 +2002,9 @@ def get_permissions(self, user):
19992002
# Overrides guardian mixin - returns readable perms instead of literal perms
20002003
if isinstance(user, AnonymousUser):
20012004
return []
2002-
enabled_groups = self.mapcore_groups_addon_enabled()
2005+
enabled_groups = False
2006+
if hasattr(self, 'mapcore_groups_addon_enabled'):
2007+
enabled_groups = self.mapcore_groups_addon_enabled()
20032008
group_perms = []
20042009
# Also check Auth Groups linked via MapCoreNodeGroup (by auth_group id) if node and groups addon enabled
20052010
if enabled_groups:

website/project/views/node.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,9 @@ def _view_project(node, auth, primary=False,
921921
is_registration = node.is_registration
922922
timestamp_pattern = get_timestamp_pattern_division(auth, node)
923923
mapcore_groups = utils.serialize_mapcore_node_groups(node, visible_only=True)
924-
enabled_mapcore_groups = node.mapcore_groups_addon_enabled()
924+
enabled_mapcore_groups = False
925+
if hasattr(node, 'mapcore_groups_addon_enabled'):
926+
enabled_mapcore_groups = node.mapcore_groups_addon_enabled()
925927
data = {
926928
'node': {
927929
'disapproval_link': disapproval_link,

website/views.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ def serialize_node_summary(node, auth, primary=True, show_path=False):
141141
if node.can_view(auth):
142142
contributor_data = serialize_contributors_for_summary(node)
143143
mapcore_group_data = serialize_mapcore_group_for_summary(node)
144-
enabled_mapcore_groups = node.mapcore_groups_addon_enabled()
144+
enabled_mapcore_groups = False
145+
if hasattr(node, 'mapcore_groups_addon_enabled'):
146+
enabled_mapcore_groups = node.mapcore_groups_addon_enabled()
145147
summary.update({
146148
'can_view': True,
147149
'can_edit': node.can_edit(auth),

0 commit comments

Comments
 (0)