Skip to content

[admin/ipam] Add export all subnets CSV action #104#203

Open
Stoiicc wants to merge 1 commit into
openwisp:masterfrom
Stoiicc:issues/104-export-all-subnets
Open

[admin/ipam] Add export all subnets CSV action #104#203
Stoiicc wants to merge 1 commit into
openwisp:masterfrom
Stoiicc:issues/104-export-all-subnets

Conversation

@Stoiicc
Copy link
Copy Markdown

@Stoiicc Stoiicc commented Dec 13, 2025

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Reference to Existing Issue

Closes #104 .

Description of Changes

Please describe these changes.

This PR adds an Export Subnets action to the Subnet admin page, allowing administrators to export all subnets in CSV format.

The exported CSV uses the same structure as the existing import template, ensuring consistency between import and export workflows.

Ensured export order by sorting subnets by creation time.

Added an export button to the subnet admin page  to export
all subnets in CSV format . The export is ordered by creation time,
optimized with select_related and covered by tests verifying multi-
subnet CSV output.

Fixes openwisp#104
Copy link
Copy Markdown
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Stoiicc, the feature is welcome, but there is a multi-tenancy blocker that must be fixed before this can merge, plus some cleanup.

Blocker: it exports every organization's subnets

export_all_view uses Subnet.objects.all() and is gated on change_subnet, but it does not filter by the requesting user's organizations. A non-superuser operator who has change_subnet in their own org could export the subnets (and IP addresses) of every organization in the system. That is a cross-tenant data leak. Please restrict the export to the organizations the user manages, using the same org-scoped queryset the admin already applies via the multitenant mixin. Superusers should still see all.

Cleanup:

  1. Dead code. The fields = [IpAddress._meta.get_field("ip_address"), ...] list is built but never used. Please remove it.
  2. Lint. There is trailing whitespace on writer.writerow([]) and on the blank line after return render(...). That will fail flake8.
  3. Permission. Export is a read operation; view_subnet is arguably more appropriate than change_subnet. Please consider which permission should gate it.
  4. Format. Concatenating per-subnet CSV blocks separated by empty rows produces an unusual file. Confirm this is the intended format; a single consistent header + rows is usually friendlier for spreadsheet import.

Please fix the org scoping (the blocker), clean up the dead code and lint, and add a test asserting that an operator cannot export another org's subnets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] Allow importing/exporting everything

2 participants