don't apply changesets that have problems

This commit is contained in:
Laura Klünder 2024-12-02 12:11:52 +01:00
parent d82670a537
commit ad252bf6c6
3 changed files with 9 additions and 2 deletions

View file

@ -173,7 +173,8 @@ class ChangeSet(models.Model):
return self.author_id == request.user.pk and self.state in ('proposed', 'reproposed') return self.author_id == request.user.pk and self.state in ('proposed', 'reproposed')
def can_commit(self, request): def can_commit(self, request):
return self.can_edit(request) and not self.proposed and self.changes and self.can_review(request) return (self.can_edit(request) and self.can_review(request)
and not self.proposed and self.changes and not self.problems.any)
def has_space_access_on_all_objects(self, request, force=False): def has_space_access_on_all_objects(self, request, force=False):
# todo: reimplement this # todo: reimplement this
@ -266,6 +267,9 @@ class ChangeSet(models.Model):
def can_end_review(self, request): def can_end_review(self, request):
return self.can_review(request) and self.state == 'review' and self.assigned_to == request.user return self.can_review(request) and self.state == 'review' and self.assigned_to == request.user
def can_apply(self, request):
return self.can_end_review(request) and not self.problems.any
def can_unreject(self, request): def can_unreject(self, request):
return (self.can_review(request) and self.state in ('rejected', 'finallyrejected') and return (self.can_review(request) and self.state in ('rejected', 'finallyrejected') and
self.assigned_to == request.user) self.assigned_to == request.user)
@ -332,6 +336,8 @@ class ChangeSet(models.Model):
self.save() self.save()
def apply(self, user): def apply(self, user):
if self.problems.any:
raise ValueError("Can't apply if there's still problems!")
with MapUpdate.lock(): with MapUpdate.lock():
# todo: reimplement # todo: reimplement
update = self.updates.create(user=user, state='applied') update = self.updates.create(user=user, state='applied')

View file

@ -143,7 +143,7 @@
{% endif %} {% endif %}
{% if can_end_review %} {% if can_end_review %}
<button type="submit" class="btn btn-danger" name="reject" value="1">{% trans 'Reject' %}</button> <button type="submit" class="btn btn-danger" name="reject" value="1">{% trans 'Reject' %}</button>
<button type="submit" class="btn btn-success" name="apply" value="1">{% trans 'Accept' %}</button> <button type="submit" {% if not can_apply %}disabled="disabled" {% endif %}class="btn btn-success" name="apply" value="1">{% trans 'Accept' %}</button>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if can_start_review %} {% if can_start_review %}

View file

@ -219,6 +219,7 @@ def changeset_detail(request, pk):
'can_unpropose': changeset.can_unpropose(request), 'can_unpropose': changeset.can_unpropose(request),
'can_start_review': changeset.can_start_review(request), 'can_start_review': changeset.can_start_review(request),
'can_end_review': changeset.can_end_review(request), 'can_end_review': changeset.can_end_review(request),
'can_apply': changeset.can_apply(request),
'can_unreject': changeset.can_unreject(request), 'can_unreject': changeset.can_unreject(request),
'active': active, 'active': active,
} }