-
Notifications
You must be signed in to change notification settings - Fork 105
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 REST API for wifisession and wificlients #374 #382
[feature] Added REST API for wifisession and wificlients #374 #382
Conversation
I need your review (when you're free) @pandafy @nemesisdesign. This will let me know that I'm going on the right direction with this PR or not 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, please add at least one test for each endpoint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found some problems during testing.
Multitenancy test gave error
I tried logging in with a non superuser to test multitenancy but when I tried opening the wifi session list API endpoint I got this exception:
FieldError at /api/v1/monitoring/wifi-session/
Cannot resolve keyword 'organization' into field. Choices are: device, device_id, id, interface_name, modified, ssid, start_time, stop_time, wifi_client, wifi_client_id
The same happens for the wifi-client endpoint. Please test this on your end and look at the implementation of the multitenancy in other API endpoints, refer to https://github.com/openwisp/openwisp-users#organization_field and the other DRF utilities provided in OpenWISP Users.
Filters invalid name
Do you know why there's this "[invalid name]" here?
Browsable API selects for foreign keys
The wifi session API endpoint shows a select for "device" and "wifi client", however, these selects will be huge on production systems, slowing down the response time in the browsable API or even causing it to fail with a timeout error. For this reason, can you find a way to display this field using only the primary key?
See https://www.django-rest-framework.org/topics/browsable-api/#handling-choicefield-with-large-numbers-of-items for more info.
Todo :
|
268f065
to
40845bb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work @Aryamanz29! This PR is coming along well.
Other requested changes
- It is possible to create WifiSession with device_id from another organization. This is undesired. Add a failing test for this.
- Add tests for REST API filters
433d6ca
to
3074fea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add dedicated tests for multi-tenancy for each model:
- test_wifi_clients_multi_tenancy
- test_wifi_session_multi_tenancy
And test each operation (GET, POST, PUT, PATCH) within a subtest in these test cases.
- Added nested serializer. - Used select_related() to enhance API performance. - Added missing fields like modified, created, device_name, org_name etc.
… input - Fixed browsable API selects for foreign keys, Changed select field to input. - Fixed browsable API [Invalid name] attribute bug, Explicitly provided label for related model.
- Fixed multitenancy test error. - Added use of available API filter in README.
- Changed ordering in WifiClient class Meta to prevent DRF "UnorderedObjectListWarning: Pagination may yield inconsistent results with an unordered object_list"
- Improved tests. - Mentioned device_group in the README. - Added extra_kwargs in WifiSessionCreateUpdateSerializer.
- Chaneged device_organization filter to organization_slug filter. - Removed unused filters from README.
- Added comparison (gt, gte, lt, lte) for filtering with time. - Added tests for API filters.
eb9d404
to
385d69c
Compare
a36e71c
to
cdf00bb
Compare
…i session endpoint As per to code review: openwisp#382 (comment) - Removed wifi client endpoints. - Exposed only list wifi session endpoint. - Updated tests and docs.
…i session endpoint As per the code review: openwisp#382 (comment) - Removed wifi client endpoints. - Exposed only list wifi session endpoint. - Updated tests and docs.
475c786
to
51af136
Compare
…i session endpoint As per the code review: openwisp#382 (comment) - Removed wifi client endpoints. - Exposed only list wifi session endpoint. - Updated tests and docs.
51af136
to
1c673f0
Compare
… views of the admin view - Improved list and detail api response (similar to admin). - Added api tests.
cfcec98
to
5301a53
Compare
029ea5e
to
5f03f3a
Compare
|
5f03f3a
to
9832b80
Compare
- `ValidatedModelSerializer` and `FilterSerializerByOrgManaged` is not required for read-only API views.
9832b80
to
15260e2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Aryamanz29 the nested serialzier solution looks nice and clean!
Blockers
Closes #374
Peek.2022-05-27.16-24.mp4
GIF/Demo
Checks: