diff --git a/docs/models/branch.md b/docs/models/branch.md index 560c87e..1ecbf59 100644 --- a/docs/models/branch.md +++ b/docs/models/branch.md @@ -29,6 +29,7 @@ The current status of the branch. This must be one of the following values. | Merging | A job is running to merge changes from the branch into main | | Reverting | A job is running to revert previously merged changes in main | | Merged | Changes from this branch have been successfully merged into main | +| Archived | A merged branch which has been deprovisioned in the database | | Failed | Provisioning the schema for this branch has failed | ### Last Sync diff --git a/docs/using-branches/reverting-a-branch.md b/docs/using-branches/reverting-a-branch.md index 5de33b5..68be470 100644 --- a/docs/using-branches/reverting-a-branch.md +++ b/docs/using-branches/reverting-a-branch.md @@ -2,8 +2,8 @@ Once a branch has been merged, it is generally no longer needed, and can no longer be activated. However, occasionally you may find it necessary to undo the changes from a branch (due to an error or an otherwise undesired state). This can be done by _reverting_ the branch. Only merged branches can be reverted. -!!! note - Only branches which have not yet been deleted can be reverted. Once a branch is deleted, reversion is no longer possible. +!!! warning + Only branches which have not yet been archived or deleted can be reverted. Once a branch's schema has been deprovisioned, it can no longer be reverted. Before reverting a branch, review the changes listed under its "Merged Changes" tab. NetBox will attempt to undo these specific changes when reverting the branch. diff --git a/docs/using-branches/syncing-merging.md b/docs/using-branches/syncing-merging.md index 27d5a55..af3c8f9 100644 --- a/docs/using-branches/syncing-merging.md +++ b/docs/using-branches/syncing-merging.md @@ -22,6 +22,8 @@ While a branch is being merged, its status will show "merging." !!! tip You can check on the status of the merging job under the "Jobs" tab of the branch view. +Once a branch has been merged, it can be [reverted](./reverting-a-branch.md), archived, or deleted. Archiving a branch removes its associated schema from the PostgreSQL database to deallocate space. An archived branch cannot be restored, however the branch record is retained for future reference. + ## Dealing with Conflicts In the event an object has been modified in both your branch _and_ in main in a diverging manner, this will be flagged as a conflict. For example, if both you and another user have modified the description of an interface to two different values in main and in the branch, this represents a conflict. diff --git a/netbox_branching/choices.py b/netbox_branching/choices.py index db8c9c8..6e49d2f 100644 --- a/netbox_branching/choices.py +++ b/netbox_branching/choices.py @@ -11,6 +11,7 @@ class BranchStatusChoices(ChoiceSet): MERGING = 'merging' REVERTING = 'reverting' MERGED = 'merged' + ARCHIVED = 'archived' FAILED = 'failed' CHOICES = ( @@ -21,6 +22,7 @@ class BranchStatusChoices(ChoiceSet): (MERGING, _('Merging'), 'orange'), (REVERTING, _('Reverting'), 'orange'), (MERGED, _('Merged'), 'blue'), + (ARCHIVED, _('Archived'), 'gray'), (FAILED, _('Failed'), 'red'), ) @@ -37,10 +39,12 @@ class BranchEventTypeChoices(ChoiceSet): SYNCED = 'synced' MERGED = 'merged' REVERTED = 'reverted' + ARCHIVED = 'archived' CHOICES = ( (PROVISIONED, _('Provisioned'), 'green'), (SYNCED, _('Synced'), 'cyan'), (MERGED, _('Merged'), 'blue'), (REVERTED, _('Reverted'), 'orange'), + (ARCHIVED, _('Archived'), 'gray'), ) diff --git a/netbox_branching/forms/misc.py b/netbox_branching/forms/misc.py index 2177f2f..ad895cb 100644 --- a/netbox_branching/forms/misc.py +++ b/netbox_branching/forms/misc.py @@ -5,6 +5,7 @@ __all__ = ( 'BranchActionForm', + 'ConfirmationForm', ) @@ -36,3 +37,10 @@ def clean(self): raise forms.ValidationError(_("All conflicts must be acknowledged in order to merge the branch.")) return self.cleaned_data + + +class ConfirmationForm(forms.Form): + confirm = forms.BooleanField( + required=True, + label=_('Confirm') + ) diff --git a/netbox_branching/models/branches.py b/netbox_branching/models/branches.py index b337ab1..140182a 100644 --- a/netbox_branching/models/branches.py +++ b/netbox_branching/models/branches.py @@ -417,7 +417,7 @@ def revert(self, user, commit=True): # Disconnect the signal receiver post_save.disconnect(handler, sender=ObjectChange_) - merge.alters_data = True + revert.alters_data = True def provision(self, user): """ @@ -512,6 +512,18 @@ def provision(self, user): provision.alters_data = True + def archive(self, user): + """ + Deprovision the Branch and set its status to "archived." + """ + self.deprovision() + + # Update the branch's status to "archived" + Branch.objects.filter(pk=self.pk).update(status=BranchStatusChoices.ARCHIVED) + BranchEvent.objects.create(branch=self, user=user, type=BranchEventTypeChoices.ARCHIVED) + + archive.alters_data = True + def deprovision(self): """ Delete the Branch's schema and all its tables from the database. diff --git a/netbox_branching/template_content.py b/netbox_branching/template_content.py index 2d2c154..c0233d5 100644 --- a/netbox_branching/template_content.py +++ b/netbox_branching/template_content.py @@ -17,7 +17,9 @@ class BranchSelector(PluginTemplateExtension): def navbar(self): return self.render('netbox_branching/inc/branch_selector.html', extra_context={ 'active_branch': active_branch.get(), - 'branches': Branch.objects.exclude(status=BranchStatusChoices.MERGED), + 'branches': Branch.objects.exclude( + status__in=[BranchStatusChoices.MERGED, BranchStatusChoices.ARCHIVED] + ), }) diff --git a/netbox_branching/templates/netbox_branching/branch.html b/netbox_branching/templates/netbox_branching/branch.html index 5d8d6b1..75edc00 100644 --- a/netbox_branching/templates/netbox_branching/branch.html +++ b/netbox_branching/templates/netbox_branching/branch.html @@ -51,6 +51,15 @@ {% trans "Revert" %} {% endif %} + {% if perms.netbox_branching.archive_branch %} + + {% trans "Archive" %} + + {% else %} + + {% endif %} {% endif %} {% endblock %} diff --git a/netbox_branching/templates/netbox_branching/branch_archive.html b/netbox_branching/templates/netbox_branching/branch_archive.html new file mode 100644 index 0000000..8849acc --- /dev/null +++ b/netbox_branching/templates/netbox_branching/branch_archive.html @@ -0,0 +1,43 @@ +{% extends 'generic/_base.html' %} +{% load form_helpers %} +{% load i18n %} + +{% block title %}{% trans "Archive" %} {{ branch }}{% endblock %} + +{% block tabs %} +
+{% endblock tabs %} + +{% block content %} + {# Form tab #} +