-
-
Notifications
You must be signed in to change notification settings - Fork 206
[change] Allow counters to return multiple replies #634 #647
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
[change] Allow counters to return multiple replies #634 #647
Conversation
openwisp_radius/counters/base.py
Outdated
def get_reset_timestamps(self): | ||
try: | ||
return resets[self.reset](self.user) | ||
return resets[self.reset](self.user, self) |
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.
Passing the counter object to the reset allows flexibility to perform operation on user, group and group_check objects.
@nemesifier can you suggest me how can I incorporate this implementation detail in https://openwisp.io/docs/dev/radius/user/enforcing_limits.html? |
ab40470
to
2ddafa9
Compare
openwisp_radius/counters/base.py
Outdated
# BACKWARD COMPATIBILITY: In previous versions of openwisp-radius, | ||
# the Counter.reply_name was a string instead of a tuple. Thus, | ||
# we need to convert it to a tuple if it's a string. | ||
if not hasattr(self, "reply_name"): |
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.
AFAIK, getattr
and hasattr
have the same computing cost, so it's better to use getattr
if we need to use the result later.
if not hasattr(self, "reply_name"): | |
reply_name = getattr(self, "reply_name", None) | |
if not reply_name: |
openwisp_radius/counters/base.py
Outdated
raise NotImplementedError( | ||
"Counter classes must define 'reply_names' property." | ||
) | ||
if isinstance(self.reply_name, str): |
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.
if isinstance(self.reply_name, str): | |
if isinstance(reply_name, str): |
openwisp_radius/counters/base.py
Outdated
"Counter classes must define 'reply_names' property." | ||
) | ||
if isinstance(self.reply_name, str): | ||
return (self.reply_name,) |
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.
return (self.reply_name,) | |
return (reply_name,) |
openwisp_radius/counters/base.py
Outdated
) | ||
if isinstance(self.reply_name, str): | ||
return (self.reply_name,) | ||
return self.reply_name |
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.
return self.reply_name | |
return reply_name |
2ddafa9
to
b27a5b7
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.
There's a conflict, please update this PR.
b27a5b7
to
d142269
Compare
.github/workflows/ci.yml
Outdated
# TODO: Remove before merging | ||
- issues/643-coa |
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.
# TODO: Remove before merging | |
- issues/643-coa |
openwisp_radius/api/serializers.py
Outdated
if consumed > int(obj.value): | ||
consumed = int(obj.value) |
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.
if consumed > int(obj.value): | |
consumed = int(obj.value) | |
value = int(obj.value) | |
if consumed > value: | |
consumed = value |
openwisp_radius/counters/base.py
Outdated
return row[0] or 0 | ||
|
||
def check(self, gigawords=gigawords): | ||
def check(self, gigawords=True): |
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.
def check(self, gigawords=True): | |
def check(self): |
openwisp_radius/counters/resets.py
Outdated
|
||
|
||
def _daily(user=None): | ||
def _daily(user=None, counter=None): |
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.
def _daily(user=None, counter=None): | |
def _daily(user=None, **kwargs): |
openwisp_radius/counters/resets.py
Outdated
|
||
|
||
def _weekly(user=None): | ||
def _weekly(user=None, counter=None): |
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.
def _weekly(user=None, counter=None): | |
def _weekly(user=None, **kwargs): |
openwisp_radius/counters/resets.py
Outdated
|
||
|
||
def _monthly(user=None): | ||
def _monthly(user=None, counter=None): |
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.
def _monthly(user=None, counter=None): | |
def _monthly(user=None, **kwargs): |
openwisp_radius/counters/resets.py
Outdated
return _timestamp(start, end) | ||
|
||
|
||
def _monthly_subscription(user): |
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.
def _monthly_subscription(user, **kwargs): |
openwisp_radius/counters/resets.py
Outdated
|
||
|
||
def _never(user=None): | ||
def _never(user=None, counter=None): |
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.
def _never(user=None, counter=None): | |
def _never(user=None, **kwargs): |
e53b0a4
to
13c223a
Compare
Checklist
Reference to Existing Issue
Closes #634
Blockers