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 device groups #203 #492

Merged
merged 15 commits into from
Jul 15, 2021
Merged

Conversation

pandafy
Copy link
Member

@pandafy pandafy commented Jun 15, 2021

A group can be specified for devices, i.e. DeviceGroup.
DeviceGroup contains metadata about group of deivces in form of JSON.
JSONSchema can be set systemwide for validation of entered metadata.

Added REST API endpoint for listing, creating and retrieving DeviceGroups.

Closes #203


  • Add a DeviceGroup or Group model and admin (maybe we should call it DeviceGroup to avoid confusion with other models that are called Group, like django's auth.Group model), the model shall have fields like (organization, using OrgMixin), name, description, meta_data, created, modified.
  • Add an optional "group" field to Device, the field should be a ForeignKey to DeviceGroup.
  • Emit a signal when the group field of a device is change and document the new signal.
  • Add the group relation to the DeviceAdmin class, using the django admin autocomplete feature.
  • Add a setting which allows to define the schema for DeviceGroup.meta_data and document it.
  • Ensure meta_data field is JSON formatted field which will leverage the work we did with JSON schema to show the UI, by default the schema will be empty and allow any property so the user can add what they need.
  • Both adminstrators and operators user types shall be able to edit config.Group.
  • Add group REST API list and detail endpoints, eg: /api/v1/controller/group/, /api/v1/controller/group/{id}/, authentication and permission checks should be consistent with the REST API endpoints added recently in [feature] REST API for main controller features #379 #386 and the ones being added in [api] Rest API for PKI app #455.

@pandafy pandafy force-pushed the issues/203-device-group-model branch from 7e03a07 to bad4070 Compare June 15, 2021 18:19
@pandafy pandafy self-assigned this Jun 15, 2021
@pandafy pandafy force-pushed the issues/203-device-group-model branch from bad4070 to c9aed4e Compare June 15, 2021 18:39
@coveralls
Copy link

coveralls commented Jun 15, 2021

Coverage Status

Coverage decreased (-0.1%) to 98.702% when pulling 702be03 on issues/203-device-group-model into 030fc9d 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.

Great progress @pandafy! Here's a first code-only review.

README.rst Show resolved Hide resolved
README.rst Show resolved Hide resolved
openwisp_controller/config/admin.py Outdated Show resolved Hide resolved
openwisp_controller/config/base/device.py Outdated Show resolved Hide resolved
openwisp_controller/config/base/device_group.py Outdated Show resolved Hide resolved
openwisp_controller/config/base/device_group.py Outdated Show resolved Hide resolved
openwisp_controller/config/tests/test_api.py Outdated Show resolved Hide resolved
openwisp_controller/config/admin.py Outdated Show resolved Hide resolved
openwisp_controller/config/admin.py Show resolved Hide resolved
@pandafy pandafy force-pushed the issues/203-device-group-model branch 2 times, most recently from 0e524a7 to 6014c98 Compare June 16, 2021 21:04
@pandafy pandafy marked this pull request as ready for review June 18, 2021 13:54
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.

There's one failing test.

@pandafy pandafy force-pushed the issues/203-device-group-model branch from 0dc4dd5 to 4d036d1 Compare July 5, 2021 17:06
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.

The screenshot shows "Configuration menu" and "Advanced mode" buttons, which shouldn't be included, is that screenshot outdated or are those buttons not disabled? It should be possible to remove them, see how it's done in credentials for reference.

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.

Does the metadata without any schema defined look weird to you as well?

Screenshot from 2021-07-08 13-38-46

Device group detail API URL

Getting the detail of a group returns me the groups, wierd..

Screenshot from 2021-07-08 13-41-56

Also, there's no DELETE/PUT/PATCH for group detail but only get and POST, seems a replica of the list view.

Menu

Please also register a menu group, we'll adapt this in #493.

pagination_class = ListViewPagination


class DeviceGroupDetailView(ProtectedAPIMixin, ListCreateAPIView):
Copy link
Member

Choose a reason for hiding this comment

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

here you're inherting ListCreateAPIView.

Please spend a bit more time testing this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I caught this on in #500. Forgot to push changes on this PR.

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.

The API is missing the UUID of the group, without that it's not possible to determine the detail URL easily when browsing the API.

The registration of a new menu item is pending.

Also, I think I understood more the issue with the config editor.

I think we should set the default schema to be an object which allows any property, not an empty schema.

I'll take care of the rest with the CSS on that part.

@pandafy pandafy force-pushed the issues/203-device-group-model branch from c67fdf1 to 8de60b2 Compare July 12, 2021 18:15
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.

In the admin page of the device, the label of the group field is "Device group", but since we are in the device edit page we don't need to repeat the word "Device" there, can you ensure it's named just "Group"? I think it could be done at model level to simplify things, it's always gonna be like that (the group attribute of a device is the device group).

README.rst Outdated
@@ -628,8 +628,8 @@ Allows to specify backend URL for API requests, if the frontend is hosted separa
Allows to specify a `list` of tuples for adding commands as described in
`'How to add commands" <#how-to-add-commands>`_ section.

``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.

Hey, why this change? It was better before!

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes it consistent with VPNCLIENT and explicitly show that DeviceGroup is it's own separate thing.

@pandafy pandafy force-pushed the issues/203-device-group-model branch from 9cbcf24 to e2e725a Compare July 13, 2021 19:25
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.

Please revert 8de60b2 as discussed recently.

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 did the reverting.

@nemesifier nemesifier merged commit 734a6c8 into master Jul 15, 2021
@nemesifier nemesifier deleted the issues/203-device-group-model branch July 15, 2021 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[controller/feature] Add DeviceGroup model
3 participants