Skip to content
Browse files

Merge pull request #10 from sergiocharpineljr/bug_591353

Bug 591353: Allow to pin down some important configs of big ISPs
  • Loading branch information...
2 parents 09b65b1 + 2a6c948 commit 6d3e8a7cd21b80852e6e2854e5875455cd27cb9b @bwinton bwinton committed Aug 20, 2012
View
9 ispdb/config/models.py
@@ -77,7 +77,7 @@ def __unicode__(self):
on_delete=models.SET_NULL)
last_update_datetime = models.DateTimeField(auto_now=True)
created_datetime = models.DateTimeField(auto_now_add=True)
- deleted_datetime = models.DateTimeField(null=True)
+ deleted_datetime = models.DateTimeField(null=True, blank=True)
CONFIG_CHOICES = [
("requested", "requested"),
("suggested", "suggested"),
@@ -86,8 +86,9 @@ def __unicode__(self):
("deleted", "deleted"),
]
status = models.CharField(max_length=20, choices = CONFIG_CHOICES)
- last_status = models.CharField(max_length=20, choices = CONFIG_CHOICES)
- email_provider_id = models.CharField(max_length=50)
+ last_status = models.CharField(max_length=20, choices = CONFIG_CHOICES,
+ blank=True)
+ email_provider_id = models.CharField(max_length=50, blank=True)
display_name = models.CharField(
max_length=100,
verbose_name="The name of this ISP",
@@ -171,6 +172,7 @@ def __unicode__(self):
flagged_as_incorrect = models.BooleanField()
flagged_by_email = models.EmailField(blank=True)
+ locked = models.BooleanField()
history = audit.AuditTrail()
@@ -739,6 +741,7 @@ class Meta:
'outgoing_add_this_server',
'outgoing_use_global_preferred_server',
'owner',
+ 'locked',
]
incoming_type = ChoiceField(widget=RadioSelect,
choices=Config.INCOMING_TYPE_CHOICES)
View
15 ispdb/config/views.py
@@ -143,6 +143,10 @@ def edit(request, config_id):
(config.status == 'requested' or config.status == 'suggested')
and config.owner == request.user)):
return HttpResponseRedirect(reverse('ispdb_login'))
+ if config.locked:
+ error = ("This configuration is locked. Only admins can unlock "
+ "it.")
+ return details(request, config.id, error=error)
# Get initial data
if config.domains.all():
model = Domain
@@ -290,6 +294,10 @@ def policy(request):
@permission_required("config.can_approve")
def approve(request, id):
config = get_object_or_404(Config, pk=id)
+ if config.locked:
+ error = ("This configuration is locked. Only admins can unlock "
+ "it.")
+ return details(request, config.id, error=error)
old_status = config.status
message = ''
if request.method == 'POST': # If the form has been submitted...
@@ -362,6 +370,10 @@ def delete(request, id):
(config.status == 'requested' or config.last_status == 'requested')
and config.owner == request.user)):
return HttpResponseRedirect(reverse('ispdb_login'))
+ if config.locked:
+ error = ("This configuration is locked. Only admins can unlock "
+ "it.")
+ return details(request, id, error=error)
if request.method == 'POST':
data = request.POST
if data.has_key('delete') and data['delete'] == "delete":
@@ -561,6 +573,9 @@ def show_issue(request, id):
elif data['action'] == 'merge':
if not issue.config.status == "approved":
error = "Can't merge into non approved configurations."
+ if issue.config.locked:
+ error = ("This configuration is locked. Only admins can unlock "
+ "it.")
elif issue.updated_config:
# check if any of the added domains are already bound to some
# approved configuration
View
12 ispdb/fixtures/domain_testdata.json
@@ -60,7 +60,8 @@
"outgoing_hostname": "test.com",
"incoming_type": "imap",
"deleted_datetime": null,
- "last_status": ""
+ "last_status": "",
+ "locked": "False"
}
},
{
@@ -90,7 +91,8 @@
"outgoing_hostname": "Valid Domain",
"incoming_type": "imap",
"deleted_datetime": null,
- "last_status": ""
+ "last_status": "",
+ "locked": "False"
}
},
{
@@ -120,7 +122,8 @@
"outgoing_hostname": "test.com",
"incoming_type": "imap",
"last_status": "",
- "deleted_datetime": null
+ "deleted_datetime": null,
+ "locked": "False"
}
},
{
@@ -150,7 +153,8 @@
"outgoing_hostname": "test.com",
"incoming_type": "imap",
"last_status": "",
- "deleted_datetime": null
+ "deleted_datetime": null,
+ "locked": "False"
}
},
{
View
3 ispdb/fixtures/xml_testdata.json
@@ -31,7 +31,8 @@
"last_update_datetime": "2012-05-31T21:08:11.305Z",
"incoming_username_form":"",
"outgoing_hostname":"hostname_out",
- "incoming_type":"imap"
+ "incoming_type":"imap",
+ "locked": "False"
}
},
{
View
15 ispdb/tests/test_approve.py
@@ -22,6 +22,21 @@ def test_unauthenticated_user(self):
goodRedirect = "/login/?next=%s" % (quote_plus("/approve/1"))
self.assertRedirects(result, goodRedirect)
+ def test_locked_config(self):
+ user_info = {"username": "test_admin", "password": "test"}
+ self.client.login(**user_info)
+ config = Config.objects.get(id=1)
+ config.locked = True
+ config.save()
+ result = self.client.post("/approve/1", {
+ "approved": True,
+ }, follow=True)
+ config = Config.objects.get(id=1)
+ # Should not have changed the config
+ assert_equal(config.status, 'requested')
+ assert_true("This configuration is locked. Only admins can unlock it."
+ in result.content)
+
def test_authenticated_user(self):
user_info = {"username": "test_admin", "password": "test"}
self.client.login(**user_info)
View
15 ispdb/tests/test_delete.py
@@ -42,6 +42,21 @@ def test_delete_no_superuser_domain(self):
goodRedirect = "/login/"
self.assertRedirects(res, goodRedirect)
+ def test_delete_locked_config(self):
+ config = models.Config.objects.get(pk=1)
+ config.locked = True
+ config.save()
+ self.client.login(username='test_admin', password='test')
+ config = models.Config.objects.get(pk=1)
+ assert_true(config.status != 'deleted')
+ res = self.client.post(reverse("ispdb_delete", args=[1]),
+ {'delete':'delete'})
+ self.client.logout()
+ config = models.Config.objects.get(pk=1)
+ assert_true(config.status != 'deleted')
+ assert_true("This configuration is locked. Only admins can unlock it."
+ in res.content)
+
def test_delete_domainrequest(self):
self.delete_domain(1)
config = models.Config.objects.get(pk=1)
View
16 ispdb/tests/test_edit.py
@@ -42,6 +42,22 @@ def test_edit_invalid_user(self):
goodRedirect = "/login/"
self.assertRedirects(res, goodRedirect)
+ def test_edit_locked_config(self):
+ self.add_domain()
+ config = models.Config.objects.get(pk=1)
+ config.locked = True
+ config.save()
+ form = adding_domain_form()
+ form["display_name"] = "testing2"
+ self.client.login(username='test', password='test')
+ res = self.client.post(reverse("ispdb_edit",args=[1]),
+ form,
+ follow=True)
+ config = models.Config.objects.get(pk=1)
+ assert_true(config.display_name != "testing2")
+ assert_true("This configuration is locked. Only admins can unlock it."
+ in res.content)
+
def test_edit_same_user(self):
self.add_domain()
self.client.login(username='test', password='test')
View
15 ispdb/tests/test_issue.py
@@ -96,6 +96,21 @@ def test_merge_issue_normal_user(self):
goodRedirect = "/login/"
self.assertRedirects(res, goodRedirect)
+ def test_merge_locked_config(self):
+ self.add_issue(updated_config=True)
+ issue = models.Issue.objects.get(title='Test')
+ issue.config.locked = True
+ issue.config.save()
+ self.client.login(username='test_admin', password='test')
+ res = self.client.post(reverse("ispdb_show_issue",args=[1]),
+ {"action":"merge"},
+ follow=True)
+ issue = models.Issue.objects.get(title='Test')
+ assert_equal(issue.status, "open")
+ assert_true(issue.config.display_name != "testing2")
+ assert_true("This configuration is locked. Only admins can unlock it."
+ in res.content)
+
def test_merge_issue_superuser(self):
self.add_issue(updated_config=True)
self.client.login(username='test_admin', password='test')

0 comments on commit 6d3e8a7

Please sign in to comment.
Something went wrong with that request. Please try again.