Skip to content

Conversation

@dee077
Copy link
Member

@dee077 dee077 commented May 7, 2025

Expose inherited variables (from templates, groups, and global) in API response via optional query param.

Fixes #818

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 #818.

Description of Changes

  • Added a parameter inherited_variables to the DeviceDetailView to optionally include the inherited variables field from related objects.
    1. Config
    2. Group
    3. Templates
    4. Global (not sure the added one is correct)
  • Not sure if the add way of serializing the object is the correct way.

Sample response

{
  'id': '8237003b-ecb9-46f0-80cf-bb3f5c407afb',
  'name': 'default.test.device',
  'organization': 'f5e0b4e0-629f-47c8-8115-6ffaf89cd54c',
  'group': '2132c6b5-e85d-4d6a-bb3e-a9c6ba744dc3',
  'mac_address': '00:11:22:33:44:55',
  'key': 'XxtYUJsxaGAZAl7KuIE7lnFnKluUzshG',
  'last_ip': None,
  'management_ip': None,
  'is_deactivated': False,
  'model': 'TP-Link TL-WDR4300 v1',
  'os': 'LEDE Reboot 17.01-SNAPSHOT r3313-c2999ef',
  'system': '',
  'notes': '',
  'config': {
    'status': 'modified',
    'error_reason': '',
    'backend': 'netjsonconfig.OpenWrt',
    'templates': ['9ad08f5e-ca41-4f84-be38-523bca731989'],
    'context': {},
    'config': {
      'general': {}
    }
  },
  'created': '2025-05-07T13:31:03.711252+02:00',
  'modified': '2025-05-07T13:31:03.711252+02:00',
  
  // Newly added field
  
  'inherited_variables': {
    'global': {
      'vpnserver1': 'vpn.testdomain.com'
    },
    'group': {
      'id': '2132c6b5-e85d-4d6a-bb3e-a9c6ba744dc3',
      'name': 'Routers',
      'organization': 'f5e0b4e0-629f-47c8-8115-6ffaf89cd54c',
      'description': 'Group for all routers',
      'templates': [],
      'context': {},
      'meta_data': {},
      'created': '2025-05-07T13:31:03.708412+02:00',
      'modified': '2025-05-07T13:31:03.708412+02:00'
    },
    'config': {
      'status': 'modified',
      'error_reason': '',
      'backend': 'netjsonconfig.OpenWrt',
      'templates': ['9ad08f5e-ca41-4f84-be38-523bca731989'],
      'context': {},
      'config': {
        'general': {}
      }
    },
    'templates': [
      {
        'id': '9ad08f5e-ca41-4f84-be38-523bca731989',
        'name': 'test-template',
        'organization': 'f5e0b4e0-629f-47c8-8115-6ffaf89cd54c',
        'type': 'generic',
        'backend': 'netjsonconfig.OpenWrt',
        'vpn': None,
        'tags': [],
        'default': False,
        'required': False,
        'default_values': {},
        'config': {
          'interfaces': [
            {
              'name': 'eth0',
              'type': 'ethernet'
            }
          ]
        },
        'created': '2025-05-07T13:31:03.736374+02:00',
        'modified': '2025-05-07T13:31:03.736374+02:00'
      }
    ]
  }
}

…nwisp#818

Expose inherited variables (from templates, groups, and global) in API response via optional query param.

Fixes openwisp#818
@coveralls
Copy link

Coverage Status

coverage: 98.825% (+0.001%) from 98.824%
when pulling 86996bf on dee077:issues/818-show-inherited-vars
into f8e721f on openwisp:master.

Copy link
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.

@dee077 thanks for bringing this up!

The response shouldn't contain the full objects, only the variables. However, I think we cannot move forward on this until we have an internal discussion and decide on the right course.

Copy link
Member

@pandafy pandafy left a comment

Choose a reason for hiding this comment

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

I and @nemesifier agreed that we need to discuss the implementation details before proceeding on this issue. Moreover, with GSoC running in parallel, this might not be the right time to divert your resources @dee077.

@pandafy pandafy added wontfix blocked Blocked by another issue / pr or task and removed wontfix labels Jun 17, 2025
@nemesifier
Copy link
Member

Closing this for now.

@nemesifier nemesifier closed this Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked Blocked by another issue / pr or task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] Allow showing variables devices inherit from related objects in REST API

4 participants