Related to openwisp/openwisp-wifi-login-pages#863.
The goal of this ticket is to modify OpenWISP RADIUS to return the counter reset period in the API.
Relevant parts of the code:
|
@method_decorator( |
|
name="get", |
|
decorator=swagger_auto_schema( |
|
operation_description=""" |
|
**Requires the user auth token (Bearer Token).** |
|
Returns the user's RADIUS usage and limit for the organization. |
|
It executes the relevant counters and returns returns information that |
|
shows how much time and/or traffic the user has consumed. |
|
""", |
|
), |
|
) |
|
class UserRadiusUsageView(ThrottledAPIMixin, DispatchOrgMixin, RetrieveAPIView): |
|
authentication_classes = (BearerAuthentication, SessionAuthentication) |
|
permission_classes = (IsAuthenticated,) |
|
queryset = User.objects.none() |
|
serializer_class = UserRadiusUsageSerializer |
|
|
|
def get_object(self): |
|
return self.request.user |
|
class UserGroupCheckSerializer(serializers.ModelSerializer): |
|
result = serializers.SerializerMethodField() |
|
type = serializers.SerializerMethodField() |
|
|
|
class Meta: |
|
model = RadiusGroupCheck |
|
fields = ("attribute", "op", "value", "result", "type") |
|
|
|
def get_result(self, obj): |
|
try: |
|
Counter = app_settings.CHECK_ATTRIBUTE_COUNTERS_MAP[obj.attribute] |
|
counter = Counter( |
|
user=self.context["user"], |
|
group=self.context["group"], |
|
group_check=obj, |
|
) |
|
consumed = counter.consumed() |
|
value = int(obj.value) |
|
if consumed > value: |
|
consumed = value |
|
return consumed |
|
except (SkipCheck, ValueError, KeyError): |
|
return None |
|
resets = { |
|
"daily": _daily, |
|
"weekly": _weekly, |
|
"monthly": _monthly, |
|
"monthly_subscription": _monthly_subscription, |
|
"never": _never, |
|
} |
I would add a reset property in the API response which returns the date time of the next reset, this means we need to use the "reset" attribute to calculate it.
Related to openwisp/openwisp-wifi-login-pages#863.
The goal of this ticket is to modify OpenWISP RADIUS to return the counter reset period in the API.
Relevant parts of the code:
openwisp-radius/openwisp_radius/api/views.py
Lines 452 to 470 in 1caa57f
openwisp-radius/openwisp_radius/api/serializers.py
Lines 297 to 319 in 1caa57f
openwisp-radius/openwisp_radius/counters/resets.py
Lines 52 to 58 in 1caa57f
I would add a
resetproperty in the API response which returns the date time of the next reset, this means we need to use the "reset" attribute to calculate it.