Skip to content

Commit 7db75df

Browse files
Merge pull request #151 from netboxlabs/develop
Release v0.5.1
2 parents 0e66ed3 + 2f76ba0 commit 7db75df

File tree

23 files changed

+277
-147
lines changed

23 files changed

+277
-147
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PLUGINS = [
3838
]
3939
```
4040

41-
5. Create `local_settings.py` to override the `DATABASES` & `DATABASE_ROUTERS` settings. This enables dynamic schema support.
41+
5. Create `local_settings.py` (in the same directory as `settings.py`) to override the `DATABASES` & `DATABASE_ROUTERS` settings. This enables dynamic schema support.
4242

4343
```python
4444
from netbox_branching.utilities import DynamicSchemaDict

docs/changelog.md

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,95 @@
11
# Change Log
22

3+
## v0.5.1
4+
5+
### Enhancements
6+
7+
* [#123](https://github.com/netboxlabs/netbox-branching/issues/123) - Introduce template tags for branch action buttons
8+
* [#129](https://github.com/netboxlabs/netbox-branching/issues/129) - Implement pre-event signals for branch actions
9+
10+
### Bug Fixes
11+
12+
* [#98](https://github.com/netboxlabs/netbox-branching/issues/98) - Cable changes in branch should not impact main schema
13+
* [#119](https://github.com/netboxlabs/netbox-branching/issues/119) - Fix the dynamic selection of related objects in forms while a branch is active
14+
* [#120](https://github.com/netboxlabs/netbox-branching/issues/120) - `max_branches` config parameter should disregard archived branches
15+
* [#138](https://github.com/netboxlabs/netbox-branching/issues/138) - Fix rendering the ID column of the change diffs table
16+
* [#140](https://github.com/netboxlabs/netbox-branching/issues/140) - Fix representation of branch status in REST API
17+
* [#142](https://github.com/netboxlabs/netbox-branching/issues/142) - Fix tab record counts for archived branches
18+
19+
---
20+
321
## v0.5.0
422

523
### Enhancements
624

7-
* [#83](https://github.com/netboxlabs/nbl-netbox-branching/issues/83) - Add a "share" button under object views when a branch is active
8-
* [#84](https://github.com/netboxlabs/nbl-netbox-branching/issues/84) - Introduce the `max_working_branches` configuration parameter
9-
* [#88](https://github.com/netboxlabs/nbl-netbox-branching/issues/88) - Add branching support for NetBox's graphQL API
10-
* [#90](https://github.com/netboxlabs/nbl-netbox-branching/issues/90) - Introduce the ability to archive & deprovision merged branches without deleting them
11-
* [#97](https://github.com/netboxlabs/nbl-netbox-branching/issues/97) - Introduce the `exempt_models` config parameter to disable branching support for plugin models
12-
* [#116](https://github.com/netboxlabs/nbl-netbox-branching/issues/116) - Disable branching support for applicable core models
25+
* [#83](https://github.com/netboxlabs/netbox-branching/issues/83) - Add a "share" button under object views when a branch is active
26+
* [#84](https://github.com/netboxlabs/netbox-branching/issues/84) - Introduce the `max_working_branches` configuration parameter
27+
* [#88](https://github.com/netboxlabs/netbox-branching/issues/88) - Add branching support for NetBox's graphQL API
28+
* [#90](https://github.com/netboxlabs/netbox-branching/issues/90) - Introduce the ability to archive & deprovision merged branches without deleting them
29+
* [#97](https://github.com/netboxlabs/netbox-branching/issues/97) - Introduce the `exempt_models` config parameter to disable branching support for plugin models
30+
* [#116](https://github.com/netboxlabs/netbox-branching/issues/116) - Disable branching support for applicable core models
1331

1432
### Bug Fixes
1533

16-
* [#81](https://github.com/netboxlabs/nbl-netbox-branching/issues/81) - Fix event rule triggering for the `branch_reverted` event
17-
* [#91](https://github.com/netboxlabs/nbl-netbox-branching/issues/91) - Disregard the active branch (if any) when alerting on changes under object views
18-
* [#94](https://github.com/netboxlabs/nbl-netbox-branching/issues/94) - Fix branch merging after modifying an object with custom field data
19-
* [#101](https://github.com/netboxlabs/nbl-netbox-branching/issues/101) - Permit (but warn about) database queries issued before branching support has been initialized
20-
* [#102](https://github.com/netboxlabs/nbl-netbox-branching/issues/102) - Record individual object actions in branch job logs
34+
* [#81](https://github.com/netboxlabs/netbox-branching/issues/81) - Fix event rule triggering for the `branch_reverted` event
35+
* [#91](https://github.com/netboxlabs/netbox-branching/issues/91) - Disregard the active branch (if any) when alerting on changes under object views
36+
* [#94](https://github.com/netboxlabs/netbox-branching/issues/94) - Fix branch merging after modifying an object with custom field data
37+
* [#101](https://github.com/netboxlabs/netbox-branching/issues/101) - Permit (but warn about) database queries issued before branching support has been initialized
38+
* [#102](https://github.com/netboxlabs/netbox-branching/issues/102) - Record individual object actions in branch job logs
2139

2240
---
2341

2442
## v0.4.0
2543

2644
### Enhancements
2745

28-
* [#52](https://github.com/netboxlabs/nbl-netbox-branching/issues/52) - Introduce the `max_branches` config parameter
29-
* [#71](https://github.com/netboxlabs/nbl-netbox-branching/issues/71) - Ensure the consistent application of logging messages
30-
* [#76](https://github.com/netboxlabs/nbl-netbox-branching/issues/76) - Validate required configuration items on initialization
46+
* [#52](https://github.com/netboxlabs/netbox-branching/issues/52) - Introduce the `max_branches` config parameter
47+
* [#71](https://github.com/netboxlabs/netbox-branching/issues/71) - Ensure the consistent application of logging messages
48+
* [#76](https://github.com/netboxlabs/netbox-branching/issues/76) - Validate required configuration items on initialization
3149

3250
### Bug Fixes
3351

34-
* [#57](https://github.com/netboxlabs/nbl-netbox-branching/issues/57) - Avoid recording ChangeDiff records for unsupported object types
35-
* [#59](https://github.com/netboxlabs/nbl-netbox-branching/issues/59) - `BranchAwareRouter` should consider branching support for model when determining database connection to use
36-
* [#61](https://github.com/netboxlabs/nbl-netbox-branching/issues/61) - Fix transaction rollback when performing a dry run sync
37-
* [#66](https://github.com/netboxlabs/nbl-netbox-branching/issues/66) - Capture object representation on ChangeDiff when creating a new object within a branch
38-
* [#69](https://github.com/netboxlabs/nbl-netbox-branching/issues/69) - Represent null values for ChangeDiff fields consistently in REST API
39-
* [#73](https://github.com/netboxlabs/nbl-netbox-branching/issues/73) - Ensure all relevant branch diffs are updated when an object is modified in main
52+
* [#57](https://github.com/netboxlabs/netbox-branching/issues/57) - Avoid recording ChangeDiff records for unsupported object types
53+
* [#59](https://github.com/netboxlabs/netbox-branching/issues/59) - `BranchAwareRouter` should consider branching support for model when determining database connection to use
54+
* [#61](https://github.com/netboxlabs/netbox-branching/issues/61) - Fix transaction rollback when performing a dry run sync
55+
* [#66](https://github.com/netboxlabs/netbox-branching/issues/66) - Capture object representation on ChangeDiff when creating a new object within a branch
56+
* [#69](https://github.com/netboxlabs/netbox-branching/issues/69) - Represent null values for ChangeDiff fields consistently in REST API
57+
* [#73](https://github.com/netboxlabs/netbox-branching/issues/73) - Ensure all relevant branch diffs are updated when an object is modified in main
4058

4159
---
4260

4361
## v0.3.1
4462

4563
### Bug Fixes
4664

47-
* [#42](https://github.com/netboxlabs/nbl-netbox-branching/issues/42) - Fix exception raised when viewing custom scripts
48-
* [#44](https://github.com/netboxlabs/nbl-netbox-branching/issues/44) - Handle truncated SQL sequence names to avoid exceptions during branch provisioning
49-
* [#48](https://github.com/netboxlabs/nbl-netbox-branching/issues/48) - Ensure background job is terminated in the event branch provisioning errors
50-
* [#50](https://github.com/netboxlabs/nbl-netbox-branching/issues/50) - Branch state should remain as "merged" after dry-run revert
65+
* [#42](https://github.com/netboxlabs/netbox-branching/issues/42) - Fix exception raised when viewing custom scripts
66+
* [#44](https://github.com/netboxlabs/netbox-branching/issues/44) - Handle truncated SQL sequence names to avoid exceptions during branch provisioning
67+
* [#48](https://github.com/netboxlabs/netbox-branching/issues/48) - Ensure background job is terminated in the event branch provisioning errors
68+
* [#50](https://github.com/netboxlabs/netbox-branching/issues/50) - Branch state should remain as "merged" after dry-run revert
5169

5270
---
5371

5472
## v0.3.0
5573

5674
### Enhancements
5775

58-
* [#2](https://github.com/netboxlabs/nbl-netbox-branching/issues/2) - Enable the ability to revert a previously merged branch
59-
* [#3](https://github.com/netboxlabs/nbl-netbox-branching/issues/3) - Require review & acknowledgment of conflicts before syncing or merging a branch
60-
* [#4](https://github.com/netboxlabs/nbl-netbox-branching/issues/4) - Include a three-way diff summary in the REST API representation of a modified object
61-
* [#13](https://github.com/netboxlabs/nbl-netbox-branching/issues/13) - Add a link to the active branch in the branch selector dropdown
62-
* [#15](https://github.com/netboxlabs/nbl-netbox-branching/issues/15) - Default to performing a "dry run" for branch sync & merge
63-
* [#17](https://github.com/netboxlabs/nbl-netbox-branching/issues/17) - Utilize NetBox's `JobRunner` class for background jobs
64-
* [#29](https://github.com/netboxlabs/nbl-netbox-branching/issues/29) - Register a branch column on NetBox's global changelog table
65-
* [#36](https://github.com/netboxlabs/nbl-netbox-branching/issues/36) - Run the branch provisioning process within an isolated transaction
76+
* [#2](https://github.com/netboxlabs/netbox-branching/issues/2) - Enable the ability to revert a previously merged branch
77+
* [#3](https://github.com/netboxlabs/netbox-branching/issues/3) - Require review & acknowledgment of conflicts before syncing or merging a branch
78+
* [#4](https://github.com/netboxlabs/netbox-branching/issues/4) - Include a three-way diff summary in the REST API representation of a modified object
79+
* [#13](https://github.com/netboxlabs/netbox-branching/issues/13) - Add a link to the active branch in the branch selector dropdown
80+
* [#15](https://github.com/netboxlabs/netbox-branching/issues/15) - Default to performing a "dry run" for branch sync & merge
81+
* [#17](https://github.com/netboxlabs/netbox-branching/issues/17) - Utilize NetBox's `JobRunner` class for background jobs
82+
* [#29](https://github.com/netboxlabs/netbox-branching/issues/29) - Register a branch column on NetBox's global changelog table
83+
* [#36](https://github.com/netboxlabs/netbox-branching/issues/36) - Run the branch provisioning process within an isolated transaction
6684

6785
### Bug Fixes
6886

69-
* [#10](https://github.com/netboxlabs/nbl-netbox-branching/issues/10) - Fix branch merge failure when deleted object was modified in another branch
70-
* [#11](https://github.com/netboxlabs/nbl-netbox-branching/issues/11) - Fix quick search functionality for branch diffs tab
71-
* [#16](https://github.com/netboxlabs/nbl-netbox-branching/issues/16) - Fix support for many-to-many assignments
72-
* [#24](https://github.com/netboxlabs/nbl-netbox-branching/issues/24) - Correct the REST API schema for the sync, merge, and revert branch endpoints
73-
* [#30](https://github.com/netboxlabs/nbl-netbox-branching/issues/30) - Include only unmerged branches with relevant changes in object view notifications
74-
* [#31](https://github.com/netboxlabs/nbl-netbox-branching/issues/31) - Prevent the deletion of a branch in a transitional state
87+
* [#10](https://github.com/netboxlabs/netbox-branching/issues/10) - Fix branch merge failure when deleted object was modified in another branch
88+
* [#11](https://github.com/netboxlabs/netbox-branching/issues/11) - Fix quick search functionality for branch diffs tab
89+
* [#16](https://github.com/netboxlabs/netbox-branching/issues/16) - Fix support for many-to-many assignments
90+
* [#24](https://github.com/netboxlabs/netbox-branching/issues/24) - Correct the REST API schema for the sync, merge, and revert branch endpoints
91+
* [#30](https://github.com/netboxlabs/netbox-branching/issues/30) - Include only unmerged branches with relevant changes in object view notifications
92+
* [#31](https://github.com/netboxlabs/netbox-branching/issues/31) - Prevent the deletion of a branch in a transitional state
7593

7694
---
7795

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ PLUGINS = [
124124

125125
This plugin employs dynamic schema resolution, which requires that we override two low-level Django settings. First, we'll wrap NetBox's configured `DATABASE` parameter with `DynamicSchemaDict` to support dynamic schemas. Second, we'll employ the plugin's custom database router.
126126

127-
Create a new file named `local_settings.py` in the same directory as `configuration.py`, and add the content below.
127+
Create a new file named `local_settings.py` in the same directory as `settings.py`, and add the content below.
128128

129129
```python
130130
from netbox_branching.utilities import DynamicSchemaDict

netbox_branching/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class AppConfig(PluginConfig):
99
name = 'netbox_branching'
1010
verbose_name = 'NetBox Branching'
1111
description = 'A git-like branching implementation for NetBox'
12-
version = '0.5.0'
12+
version = '0.5.1'
1313
base_url = 'branching'
1414
min_version = '4.1'
1515
middleware = [

netbox_branching/api/serializers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from netbox.api.exceptions import SerializerNotFound
66
from netbox.api.fields import ChoiceField, ContentTypeField
77
from netbox.api.serializers import NetBoxModelSerializer
8-
from netbox_branching.choices import BranchEventTypeChoices
8+
from netbox_branching.choices import BranchEventTypeChoices, BranchStatusChoices
99
from netbox_branching.models import ChangeDiff, Branch, BranchEvent
1010
from users.api.serializers import UserSerializer
1111
from utilities.api import get_serializer_for_model
@@ -30,6 +30,9 @@ class BranchSerializer(NetBoxModelSerializer):
3030
nested=True,
3131
read_only=True
3232
)
33+
status = ChoiceField(
34+
choices=BranchStatusChoices
35+
)
3336

3437
class Meta:
3538
model = Branch

netbox_branching/constants.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
# URL query parameter name
1111
QUERY_PARAM = '_branch'
1212

13+
# Tables which must be replicated within a branch even though their
14+
# models don't directly support branching.
15+
REPLICATE_TABLES = (
16+
'dcim_cablepath',
17+
)
18+
1319
# Models for which branching support is explicitly disabled
1420
EXEMPT_MODELS = (
1521
# Exempt applicable core NetBox models

netbox_branching/database.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ def _get_db(self, model, **hints):
2121
warnings.warn(f"Routing database query for {model} before branching support is initialized.")
2222
return
2323

24-
# Bail if the model does not support branching
25-
app_label, model_name = model._meta.label.lower().split('.')
26-
if model_name not in registry['model_features']['branching'].get(app_label, []):
27-
return
28-
2924
# Return the schema for the active branch (if any)
3025
if branch := active_branch.get():
3126
return f'schema_{branch.schema_name}'

netbox_branching/middleware.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .choices import BranchStatusChoices
99
from .constants import COOKIE_NAME, BRANCH_HEADER, QUERY_PARAM
1010
from .models import Branch
11-
from .utilities import activate_branch
11+
from .utilities import activate_branch, is_api_request
1212

1313
__all__ = (
1414
'BranchMiddleware',
@@ -45,13 +45,12 @@ def get_active_branch(request):
4545
"""
4646
Return the active Branch (if any).
4747
"""
48-
# The active Branch is specified by HTTP header for REST & GraphQL API requests.
49-
if request.path_info.startswith(reverse('api-root')) or request.path_info.startswith(reverse('graphql')):
50-
if schema_id := request.headers.get(BRANCH_HEADER):
51-
branch = Branch.objects.get(schema_id=schema_id)
52-
if not branch.ready:
53-
return HttpResponseBadRequest(f"Branch {branch} is not ready for use (status: {branch.status})")
54-
return branch
48+
# The active Branch may be specified by HTTP header for REST & GraphQL API requests.
49+
if is_api_request(request) and BRANCH_HEADER in request.headers:
50+
branch = Branch.objects.get(schema_id=request.headers.get(BRANCH_HEADER))
51+
if not branch.ready:
52+
return HttpResponseBadRequest(f"Branch {branch} is not ready for use (status: {branch.status})")
53+
return branch
5554

5655
# Branch activated/deactivated by URL query parameter
5756
elif QUERY_PARAM in request.GET:

0 commit comments

Comments
 (0)