Skip to content
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

[feature] Added configuration variables to DeviceGroup #738 #779

Merged
merged 10 commits into from
Jul 14, 2023

Conversation

pandafy
Copy link
Member

@pandafy pandafy commented Jun 27, 2023

Closes #738

@pandafy
Copy link
Member Author

pandafy commented Jun 27, 2023

This part of the JS is affecting updating the "Configuration Variables" when the device group is changed in the admin.

Object.keys(defaultValues).forEach(function (key) {
if (!contextValue.hasOwnProperty(key) && !systemContextValue.hasOwnProperty(key)) {
contextValue[key] = defaultValues[key];
}
});

Consider the following scenario:

  1. There's a group. "Access points" which set the configuration variables as {'ssid': 'OpenWISP}.
  2. There's a template, "Wireless Radio", which set the configuration variable as {'ssid': 'placeholder}.
  3. You select the "Wireless Radio" template on a device, and you see the device configuration variables populated. This is correct.
  4. Now, change the group of the device to "Access Points".

Expected Result

You would expect the configuration variables to reflect {'ssid': 'OpenWISP}.

Actual Result

The configuration variables stay {'ssid': 'placeholder}

Why does this bug occur?

The aforementioned JS, only updates the configuration variables if the key is not defined in the System Defined Variables and not already defined in the Configuration Variables for the device.

So, when the configuration variables already has {'ssid': 'placeholder}, i.e. there's ssid key present before DeviceGroup was changed. Therefore, it does not update the configuration variable.

I guess, this was done to prevent overriding of configuration variables that were overridden by the user.

This bugs also appear when two templates have same configuration variable defined. The configuration variable field of the device does not update when we select the second template.

@nemesifier
Copy link
Member

This part of the JS is affecting updating the "Configuration Variables" when the device group is changed in the admin.

Object.keys(defaultValues).forEach(function (key) {
if (!contextValue.hasOwnProperty(key) && !systemContextValue.hasOwnProperty(key)) {
contextValue[key] = defaultValues[key];
}
});

Consider the following scenario:

  1. There's a group. "Access points" which set the configuration variables as {'ssid': 'OpenWISP}.
  2. There's a template, "Wireless Radio", which set the configuration variable as {'ssid': 'placeholder}.
  3. You select the "Wireless Radio" template on a device, and you see the device configuration variables populated. This is correct.
  4. Now, change the group of the device to "Access Points".

Expected Result

You would expect the configuration variables to reflect {'ssid': 'OpenWISP}.

Actual Result

The configuration variables stay {'ssid': 'placeholder}

Why does this bug occur?

The aforementioned JS, only updates the configuration variables if the key is not defined in the System Defined Variables and not already defined in the Configuration Variables for the device.

So, when the configuration variables already has {'ssid': 'placeholder}, i.e. there's ssid key present before DeviceGroup was changed. Therefore, it does not update the configuration variable.

I guess, this was done to prevent overriding of configuration variables that were overridden by the user.

Makes sense.

What about adding a new section called just "Group variables"?

So the new precedence order would be:

  1. System variables
  2. Template default values
  3. Organization variables ([feature] Convert group metadata to variables #738)
  4. Group variables
  5. Device variables

This bugs also appears when two templates have same configuration variable defined. The configuration variable field of the device does not update when we select the second template.

For this please open a new issue and add a reference to this discussion.

Preview config

Can you make sure the preview takes into account the group too?
E.g.: selecting a group and hitting preview should cause the group variables to be used in the preview.

@pandafy
Copy link
Member Author

pandafy commented Jun 28, 2023

@nemesifier having a new "Group variable" section would not solve the problem I shared in my previous comment. I think, we would eventually have to address #781.

Having a separate section would only benefit UI aspects.

@coveralls
Copy link

coveralls commented Jun 28, 2023

Coverage Status

coverage: 98.899%. first build when pulling 4134800 on issues/738-group-metadata-variables into 89a501d on 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.

Documentation recommendations:

  • add a reference to group variables in the explanation of configuration variables
  • explain the precedence of the different type of variables (look at the code first) - I think this should go in the configuration variables section, we said we can have a list in the beginning of "How to use configuration variables" and link each section, then reorder the sections to make sure they follow the same order
  • in the group section, please explain the differences between context and meta data (when to use one and when to use the other one), explain that both end up being available as variables, make sure to mention that both are available via REST API

README.rst Show resolved Hide resolved
README.rst Outdated
@@ -934,6 +937,7 @@ for the devices of an organization:
information across all groups using `"OPENWISP_CONTROLLER_DEVICE_GROUP_SCHEMA" <#openwisp-controller-device-group-schema>`_
Copy link
Member

Choose a reason for hiding this comment

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

maybe this can become one shorter point which refers to a new section below

README.rst Show resolved Hide resolved
@pandafy pandafy force-pushed the issues/738-group-metadata-variables branch 2 times, most recently from 61e0a5a to 279717d Compare July 3, 2023 14:32
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.

I tried this on a device which already had a group assigned:

  • I defined a variable in a template and set a default value for it
  • I selected this template in the device just mentioned

I expected the configuration variables section of the device to show this.
However, this is not happening.

It works properly if the group is not assigned yet and I assign it.
Or if the group is already assigned and I unassign it and reassign it.

openwisp_controller/config/base/device.py Outdated Show resolved Hide resolved
@pandafy
Copy link
Member Author

pandafy commented Jul 10, 2023

@nemesifier When a device already has a group assigned, then the group's configuration variable is added to the "System Defined Variables" in the configuration section. Since the "System Defined Variables" have higher priority than "Default Values/Configuration Variables", therefore those variables are not added to the UI.

@pandafy pandafy force-pushed the issues/738-group-metadata-variables branch from 279717d to 37fcfe0 Compare July 10, 2023 12:54
README.rst Outdated

1. `User defined device variables <#user-defined-device-variables>`_
2. `Predefined device variables <#predefined-device-variables>`_
3. `Global variables <#global-variables>`_
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure global variables would override group variables? I think it should be the opposite, group variables should override any global variable.

README.rst Show resolved Hide resolved
'meta_data',
'created',
'modified',
]
search_fields = ['name', 'description', 'meta_data']
search_fields = ['name', 'description', 'meta_data', 'context']
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure of this? We don't have context as search fields in the other models.
Looking through too many textfields could make the search slow if there's many rows in the DB.
For consistency I would remove it.

@pandafy pandafy force-pushed the issues/738-group-metadata-variables branch 4 times, most recently from cb3fd36 to c172123 Compare July 14, 2023 09:59
@pandafy pandafy force-pushed the issues/738-group-metadata-variables branch from c172123 to 6c67145 Compare July 14, 2023 10:19
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.

Great! 👍

@nemesifier nemesifier merged commit f396d07 into master Jul 14, 2023
@nemesifier nemesifier deleted the issues/738-group-metadata-variables branch July 14, 2023 17:50
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] Convert group metadata to variables
3 participants