-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[change] Delivery address #12056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SchrodingersGat
wants to merge
24
commits into
inventree:master
Choose a base branch
from
SchrodingersGat:delivery-address
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+634
−48
Open
[change] Delivery address #12056
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
ba32138
Allow 'company' field of Address model to be null
SchrodingersGat 2384a99
Add API filtering
SchrodingersGat bb39b19
Migrate address fields for order models
SchrodingersGat 2b917d0
Adjust UI forms
SchrodingersGat cb4113b
Refactor address table
SchrodingersGat 3b77c41
Admin table for internal addresses
SchrodingersGat 97caa20
New unit tests for order addresses
SchrodingersGat a92e2f7
Adjust admin interface
SchrodingersGat 28ef786
Documentation updates
SchrodingersGat 6f4312d
Tweak text
SchrodingersGat 8afae9d
Add fallback for primary address
SchrodingersGat 801d244
Update CHANGELOG
SchrodingersGat 22f94d3
lazy load address table
SchrodingersGat 10b93d2
Display address on PurchaseOrderDetail page
SchrodingersGat 296ee10
Bump API version
SchrodingersGat e1acec9
only staff users can manipulate internal addresses
SchrodingersGat 755a724
Fix CHANGELOG
SchrodingersGat 3b1ba84
Test for new API filter
SchrodingersGat 4a7ba6a
docs fix
SchrodingersGat 2730775
Adjust address fallback
SchrodingersGat 27767bb
Merge branch 'master' into delivery-address
SchrodingersGat 90fba96
Update migration
SchrodingersGat 95b8202
Merge commit 'd38af61ba2fb3c87143da57ddd92bc4845f85a7c' into delivery…
SchrodingersGat 2c8d511
Merge branch 'delivery-address' of github.com:SchrodingersGat/InvenTr…
SchrodingersGat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
|
|
||
| import django_filters.rest_framework.filters as rest_filters | ||
| from django_filters.rest_framework.filterset import FilterSet | ||
| from rest_framework.exceptions import PermissionDenied | ||
|
|
||
| import part.models | ||
| from data_exporter.mixins import DataExportViewMixin | ||
|
|
@@ -105,27 +106,67 @@ class ContactDetail(RetrieveUpdateDestroyAPI): | |
| serializer_class = ContactSerializer | ||
|
|
||
|
|
||
| class AddressFilter(FilterSet): | ||
| """Custom API filters for the Address list endpoint.""" | ||
|
|
||
| class Meta: | ||
| """Metaclass options.""" | ||
|
|
||
| model = Address | ||
| fields = ['company'] | ||
|
|
||
| internal = rest_filters.BooleanFilter( | ||
| label=_('Internal Address'), field_name='company', lookup_expr='isnull' | ||
| ) | ||
|
SchrodingersGat marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def _require_staff_for_internal_address(request, address_company) -> None: | ||
| """Raise PermissionDenied if the address is internal and the user is not staff.""" | ||
| if address_company is None and not request.user.is_staff: | ||
| raise PermissionDenied(_('Only staff users can modify internal addresses')) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this forces ppl to use staff accounts - which are well-known sources for security issues; imo this should be a seperate permissions |
||
|
|
||
|
|
||
| class AddressList(DataExportViewMixin, ListCreateDestroyAPIView): | ||
| """API endpoint for list view of Address model.""" | ||
|
|
||
| queryset = Address.objects.all() | ||
| serializer_class = AddressSerializer | ||
| filterset_class = AddressFilter | ||
|
SchrodingersGat marked this conversation as resolved.
|
||
|
|
||
| filter_backends = SEARCH_ORDER_FILTER | ||
|
|
||
| filterset_fields = ['company'] | ||
|
|
||
| ordering_fields = ['title'] | ||
|
|
||
| ordering = 'title' | ||
|
|
||
| def perform_create(self, serializer): | ||
| """Enforce staff-only creation of internal addresses.""" | ||
| company = serializer.validated_data.get('company', None) | ||
| _require_staff_for_internal_address(self.request, company) | ||
| super().perform_create(serializer) | ||
|
|
||
| def validate_delete(self, queryset, request) -> None: | ||
| """Prevent non-staff users from bulk-deleting internal addresses.""" | ||
| if not request.user.is_staff and queryset.filter(company__isnull=True).exists(): | ||
| raise PermissionDenied(_('Only staff users can delete internal addresses')) | ||
|
|
||
|
|
||
| class AddressDetail(RetrieveUpdateDestroyAPI): | ||
| """API endpoint for a single Address object.""" | ||
|
|
||
| queryset = Address.objects.all() | ||
| serializer_class = AddressSerializer | ||
|
|
||
| def perform_update(self, serializer): | ||
| """Enforce staff-only updates to internal addresses.""" | ||
| _require_staff_for_internal_address(self.request, serializer.instance.company) | ||
| super().perform_update(serializer) | ||
|
|
||
| def perform_destroy(self, instance): | ||
| """Enforce staff-only deletion of internal addresses.""" | ||
| _require_staff_for_internal_address(self.request, instance.company) | ||
| super().perform_destroy(instance) | ||
|
|
||
|
|
||
| class ManufacturerPartFilter(FilterSet): | ||
| """Custom API filters for the ManufacturerPart list endpoint.""" | ||
|
|
||
27 changes: 27 additions & 0 deletions
27
src/backend/InvenTree/company/migrations/0080_alter_address_company.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Generated by Django 5.2.14 on 2026-05-31 03:39 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("company", "0079_auto_20260212_1054"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name="address", | ||
| name="company", | ||
| field=models.ForeignKey( | ||
| blank=True, | ||
| help_text="Select company", | ||
| null=True, | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="addresses", | ||
| to="company.company", | ||
| verbose_name="Company", | ||
| ), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.