Skip to content

Commit

Permalink
add RemoteSite.owner_modifiable field (#817)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Jun 11, 2024
1 parent a0808d9 commit 40f315a
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Added
- ``is_source_site()`` and ``is_target_site()`` rule predicates
- ``settings_link`` kwarg in ``send_generic_email()`` (#1418)
- ``addremotesite`` and ``syncgroups`` command tests (#352)
- ``RemoteSite.owner_modifiable`` field (#817)
- **Timeline**
- ``sodar_uuid`` field in ``TimelineEventObjectRef`` model (#1415)
- REST API views (#1350)
Expand Down
11 changes: 10 additions & 1 deletion projectroles/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,14 @@ class RemoteSiteForm(SODARModelForm):

class Meta:
model = RemoteSite
fields = ['name', 'url', 'description', 'user_display', 'secret']
fields = [
'name',
'url',
'description',
'user_display',
'owner_modifiable',
'secret',
]

def __init__(self, current_user=None, *args, **kwargs):
"""Override for form initialization"""
Expand All @@ -1199,8 +1206,10 @@ def __init__(self, current_user=None, *args, **kwargs):
if settings.PROJECTROLES_SITE_MODE == SITE_MODE_SOURCE:
self.fields['secret'].widget.attrs['readonly'] = True
self.fields['user_display'].widget = forms.CheckboxInput()
self.fields['owner_modifiable'].widget = forms.CheckboxInput()
elif settings.PROJECTROLES_SITE_MODE == SITE_MODE_TARGET:
self.fields['user_display'].widget = forms.HiddenInput()
self.fields['owner_modifiable'].widget = forms.HiddenInput()
self.fields['user_display'].initial = True

# Creation
Expand Down
26 changes: 26 additions & 0 deletions projectroles/migrations/0031_remotesite_owner_modifiable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.11 on 2024-06-11 14:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("projectroles", "0030_populate_sodaruseradditionalemail"),
]

operations = [
migrations.AddField(
model_name="remotesite",
name="owner_modifiable",
field=models.BooleanField(
default=True,
help_text="Allow owners and delegates to modify project access for this site",
),
),
migrations.AlterField(
model_name="remotesite",
name="user_display",
field=models.BooleanField(default=True, help_text="Display site to users"),
),
]
18 changes: 13 additions & 5 deletions projectroles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,18 +1144,26 @@ class RemoteSite(models.Model):
help_text='Secret token for connecting to the source site',
)

#: RemoteSite visibilty to users
user_display = models.BooleanField(
default=True, unique=False, help_text='Display site to users'
)

#: RemoteSite project access modifiability for owners and delegates
owner_modifiable = models.BooleanField(
default=True,
unique=False,
help_text='Allow owners and delegates to modify project access for '
'this site',
)

#: RemoteSite relation UUID (local)
sodar_uuid = models.UUIDField(
default=uuid.uuid4,
unique=True,
help_text='RemoteSite relation UUID (local)',
)

#: RemoteSite's link visibilty for users
user_display = models.BooleanField(
default=True, unique=False, help_text='RemoteSite visibility to users'
)

class Meta:
ordering = ['name']
unique_together = ['url', 'mode', 'secret']
Expand Down
1 change: 1 addition & 0 deletions projectroles/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def test_add(self):
'secret': REMOTE_SITE_SECRET,
'sodar_uuid': site.sodar_uuid,
'user_display': True,
'owner_modifiable': True,
}
self.assertEqual(model_to_dict(site), expected)
self.assertEqual(TimelineEvent.objects.filter(**tl_kwargs).count(), 1)
Expand Down
3 changes: 3 additions & 0 deletions projectroles/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def make_site(
name,
url,
user_display=REMOTE_SITE_USER_DISPLAY,
owner_modifiable=True,
mode=SODAR_CONSTANTS['SITE_MODE_TARGET'],
description='',
secret=build_secret(),
Expand All @@ -217,6 +218,7 @@ def make_site(
'description': description,
'secret': secret,
'user_display': user_display,
'owner_modifiable': owner_modifiable,
}
site = RemoteSite(**values)
site.save()
Expand Down Expand Up @@ -1347,6 +1349,7 @@ def test_initialization(self):
'secret': REMOTE_SITE_SECRET,
'sodar_uuid': self.site.sodar_uuid,
'user_display': REMOTE_SITE_USER_DISPLAY,
'owner_modifiable': True,
}
self.assertEqual(model_to_dict(self.site), expected)

Expand Down
3 changes: 3 additions & 0 deletions projectroles/tests/test_remote_project_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,7 @@ def test_create(self):
'secret': None,
'sodar_uuid': uuid.UUID(PEER_SITE_UUID),
'user_display': PEER_SITE_USER_DISPLAY,
'owner_modifiable': True,
}
peer_site_dict = model_to_dict(peer_site_obj)
peer_site_dict.pop('id')
Expand Down Expand Up @@ -1845,6 +1846,7 @@ def test_update(self):
'description': NEW_PEER_DESC,
'secret': None,
'user_display': NEW_PEER_USER_DISPLAY,
'owner_modifiable': True,
}
peer_site_dict = model_to_dict(peer_site_obj)
peer_site_dict.pop('id')
Expand Down Expand Up @@ -2353,6 +2355,7 @@ def test_update_no_changes(self):
'secret': None,
'sodar_uuid': uuid.UUID(PEER_SITE_UUID),
'user_display': PEER_SITE_USER_DISPLAY,
'owner_modifiable': True,
}
peer_site_dict = model_to_dict(peer_site_obj)
peer_site_dict.pop('id')
Expand Down
7 changes: 7 additions & 0 deletions projectroles/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
REMOTE_SITE_DESC = 'description'
REMOTE_SITE_SECRET = build_secret()
REMOTE_SITE_USER_DISPLAY = True
REMOTE_SITE_OWNER_MODIFY = True
REMOTE_SITE_NEW_NAME = 'New name'
REMOTE_SITE_NEW_URL = 'https://new.url'
REMOTE_SITE_NEW_DESC = 'New description'
Expand Down Expand Up @@ -4949,6 +4950,7 @@ def test_post_source(self):
'description': REMOTE_SITE_DESC,
'secret': REMOTE_SITE_SECRET,
'user_display': REMOTE_SITE_USER_DISPLAY,
'owner_modifiable': REMOTE_SITE_OWNER_MODIFY,
}
with self.login(self.user):
response = self.client.post(self.url, data)
Expand All @@ -4964,6 +4966,7 @@ def test_post_source(self):
'secret': REMOTE_SITE_SECRET,
'sodar_uuid': site.sodar_uuid,
'user_display': REMOTE_SITE_USER_DISPLAY,
'owner_modifiable': REMOTE_SITE_OWNER_MODIFY,
}
model_dict = model_to_dict(site)
self.assertEqual(model_dict, expected)
Expand All @@ -4989,6 +4992,7 @@ def test_post_target(self):
'description': REMOTE_SITE_DESC,
'secret': REMOTE_SITE_SECRET,
'user_display': REMOTE_SITE_USER_DISPLAY,
'owner_modifiable': REMOTE_SITE_OWNER_MODIFY,
}
with self.login(self.user):
response = self.client.post(self.url, data)
Expand All @@ -5005,6 +5009,7 @@ def test_post_target(self):
'secret': REMOTE_SITE_SECRET,
'sodar_uuid': site.sodar_uuid,
'user_display': REMOTE_SITE_USER_DISPLAY,
'owner_modifiable': REMOTE_SITE_OWNER_MODIFY,
}
model_dict = model_to_dict(site)
self.assertEqual(model_dict, expected)
Expand Down Expand Up @@ -5096,6 +5101,7 @@ def test_post(self):
'description': REMOTE_SITE_NEW_DESC,
'secret': REMOTE_SITE_SECRET,
'user_display': REMOTE_SITE_USER_DISPLAY,
'owner_modifiable': REMOTE_SITE_OWNER_MODIFY,
}
with self.login(self.user):
response = self.client.post(self.url, data)
Expand All @@ -5111,6 +5117,7 @@ def test_post(self):
'secret': REMOTE_SITE_SECRET,
'sodar_uuid': site.sodar_uuid,
'user_display': REMOTE_SITE_USER_DISPLAY,
'owner_modifiable': REMOTE_SITE_OWNER_MODIFY,
}
model_dict = model_to_dict(site)
self.assertEqual(model_dict, expected)
Expand Down

0 comments on commit 40f315a

Please sign in to comment.