Repository: mozmeao/snippets-service

Issue:
Ability to Edit Job After Scheduling
Hi Giorgos,

I know this isn't essential, but a nice to have. We have a use case for this as someone wants for us to pause certain snippets during September 11, which usually is a sensitive day for folks since its the anniversary of the World Trade Center attacks in the United States.

Since we don't currently have a pause or edit function, I can just create a new job for any snippets we stop on that day. But that would break off data from that specific campaign into two sets. 

The main need here is to edit a job after publishing (date, targeting, etc)

If it's not something that can be available in the near future that isn't a huge issue as we can work around it in the short-term. Just want to check to be sure. Thank you!




Discussion:
Noted. I will take a look when I start working on Freq Capping b/c those are related. Thanks!

Resolving patch:
diff --git a/snippets/base/admin/adminmodels.py b/snippets/base/admin/adminmodels.py
--- a/snippets/base/admin/adminmodels.py
+++ b/snippets/base/admin/adminmodels.py
@@ -4,6 +4,7 @@
 
 from django.conf import settings
 from django.contrib import admin, messages
+from django.contrib.admin.utils import flatten_fieldsets
 from django.contrib.humanize.templatetags.humanize import intcomma
 from django.db.models import Sum, TextField, Q
 from django.http import HttpResponseRedirect
@@ -1110,6 +1111,26 @@ def snippet_name_linked(self, obj):
         )
     snippet_name_linked.short_description = 'Link to Snippet'
 
+    def get_readonly_fields(self, request, obj):
+        fields = copy.copy(self.readonly_fields)
+
+        # If Completed or Cancelled make all fields read-only.
+        if obj.status in [models.Job.CANCELED, models.Job.COMPLETED]:
+            fields = flatten_fieldsets(self.get_fieldsets(request, obj))
+
+        # If Published only changing of Publish End, Client Impression
+        # Limits and Global Impression, Click, Block Limits.
+        if obj.status in [models.Job.PUBLISHED]:
+            fields = flatten_fieldsets(self.get_fieldsets(request, obj))
+            for field in [
+                    'publish_end', 'client_limit_lifetime',
+                    'client_limit_per_hour', 'client_limit_per_day',
+                    'client_limit_per_week', 'client_limit_per_fortnight',
+                    'client_limit_per_month', 'limit_impressions', 'limit_clicks',
+                    'limit_blocks']:
+                fields.remove(field)
+        return fields
+
     def target_list(self, obj):
         return mark_safe(
             '<ul>' +
@@ -1197,12 +1218,6 @@ def save_model(self, request, obj, form, change):
             obj.creator = request.user
         super().save_model(request, obj, form, change)
 
-    def has_change_permission(self, request, obj=None):
-        """ Allow edit only during Draft stage. """
-        if obj and obj.status == models.Job.DRAFT:
-            return True
-        return False
-
     def has_delete_permission(self, request, obj=None):
         """ Allow deletion only during Draft stage. """
         if obj and obj.status == models.Job.DRAFT:


Test patch: