-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: end user can rename instance or change owner
- Loading branch information
Showing
9 changed files
with
152 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 4.2.13 on 2024-05-21 13:46 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('service_catalog', '0041_operation_validators'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name='instance', | ||
options={'default_permissions': ('add', 'change', 'delete', 'view', 'list'), 'ordering': ['-last_updated'], 'permissions': [('archive_instance', 'Can archive instance'), ('unarchive_instance', 'Can unarchive instance'), ('request_on_instance', 'Can request a day2 operation on instance'), ('admin_request_on_instance', 'Can request an admin day2 operation on instance'), ('view_admin_spec_instance', 'Can view admin spec on instance'), ('change_admin_spec_instance', 'Can change admin spec on instance'), ('rename_instance', 'Can rename instance'), ('change_requester_on_instance', 'Can change owner of the instance')]}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
templates/service_catalog/buttons/instance_edit_button.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
{% has_perm request.user "service_catalog.rename_instance" object as can_rename_instance %} | ||
{% has_perm request.user "service_catalog.change_instance" object as can_change_requester_instance %} | ||
{% has_perm request.user "service_catalog.change_owner_instance" object as can_change_instance %} | ||
{% if can_rename_instance or can_change_requester_instance or can_change_instance %} | ||
<a href="{% url "service_catalog:instance_edit" object.id %}" | ||
class="btn btn-primary"> | ||
<i class="fas fa-pencil-alt"></i> | ||
</a> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
tests/test_service_catalog/test_forms/test_instance_form.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from profiles.models import Permission | ||
from service_catalog.forms import InstanceFormRestricted | ||
from tests.test_service_catalog.base_test_request import BaseTestRequest | ||
|
||
|
||
class TestInstanceForm(BaseTestRequest): | ||
|
||
def setUp(self): | ||
super(TestInstanceForm, self).setUp() | ||
|
||
def test_instance_form_restricted_with_admin(self): | ||
parameters = { | ||
'instance': self.test_instance, | ||
'user': self.standard_user | ||
} | ||
data = { | ||
'name': 'test_instance_updated', | ||
'requester': self.standard_user_2, | ||
} | ||
form = InstanceFormRestricted(data, **parameters) | ||
self.assertTrue(form.is_valid()) | ||
self.assertFalse('name' in form.fields) | ||
self.assertFalse('requester' in form.fields) | ||
self.team_member_role.permissions.add( | ||
Permission.objects.get_by_natural_key(codename="rename_instance", | ||
app_label="service_catalog", | ||
model="instance")) | ||
form = InstanceFormRestricted(data, **parameters) | ||
self.assertTrue(form.is_valid()) | ||
self.assertTrue('name' in form.fields) | ||
self.assertFalse('requester' in form.fields) | ||
self.team_member_role.permissions.add( | ||
Permission.objects.get_by_natural_key(codename="change_requester_on_instance", | ||
app_label="service_catalog", | ||
model="instance")) | ||
form = InstanceFormRestricted(data, **parameters) | ||
self.assertTrue('name' in form.fields) | ||
self.assertTrue('requester' in form.fields) | ||
# standard user 2 not part of the team yet so not a valid choice | ||
self.assertFalse(form.is_valid()) | ||
# add standard user 2 to the team | ||
self.test_quota_scope.add_user_in_role(self.standard_user_2, self.team_member_role) | ||
self.test_quota_scope_team.add_user_in_role(self.standard_user_2, self.team_member_role) | ||
form = InstanceFormRestricted(data, **parameters) | ||
self.assertIn(self.standard_user_2, list(form.fields["requester"].queryset)) | ||
self.assertTrue(form.is_valid()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters