-
Notifications
You must be signed in to change notification settings - Fork 132
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
Add management command to increase an ODKTokens lifetime #1847
Conversation
d8b677d
to
290d29a
Compare
99e73a7
to
6cf5edc
Compare
1f826dd
to
dcfed84
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.
Generally looks good. I've added a few queries
onadata/apps/api/models/odk_token.py
Outdated
instance.expires = instance.created + timedelta( | ||
days=ODK_TOKEN_LIFETIME) | ||
instance.expires = instance.expires.astimezone( | ||
instance.created.tzinfo) |
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.
Why are we overriding instance.expires
in line 101? Also, will instance.expires
in line 99 still have the value assigned to it even though it hasn't been saved and it's being used in line 101? Let me know if my questions make sense
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.
Overriding the value to make sure that the date-time object saved in the field is timezone aware(Usually Django saves it's datetime
objects with the UTC timezone when Timezones are enabled. Didn't want to deviate from that)
The instance will still have the expires
value assigned to the object in line 99 and the value will be accessible in line 101, I believe. I'll update this though and set the expires
field in one line, just in case.
onadata/libs/utils/logger_tools.py
Outdated
if username: | ||
if isinstance(form_id, XForm): | ||
root = form_id.survey.name | ||
else: | ||
try: | ||
form = XForm.objects.filter( | ||
id_string__iexact=form_id, | ||
user__username__iexact=username, | ||
deleted_at__isnull=True).first() | ||
root = form.survey.name | ||
except XForm.DoesNotExist: | ||
root = 'data' | ||
else: | ||
root = 'data' |
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.
Why have we changed the value assigned to root
from form_id
(which seems to be an xform object) to a string value (data
)? Also, i'm not very conversant with this part of the code. I'd like @ukanga's eye on this change as well
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.
My bad, these are changes meant for another pull request. I didn't notice the commits were rebased into this one. I'll update the PR
dcfed84
to
348c03c
Compare
The 'expires' field will enable one to increment / decrement the expiry date of an ODKToken easily. Included the '_post_save_set_expiry_date' function to set the 'expires' field value post_save in order to have access to the 'created' field value - Update 'test_fails_authentication_past_odk_token_expiry' test
348c03c
to
4d3bd89
Compare
Changes / Features implemented
expires
date-time field for ODKToken classincrease_odk_token_lifetime
Steps taken to verify this change does what is intended
Side effects of implementing this change
ODKTokens
created before this change will not have theexpires
date set. Which might cause issues. All ODKTokens should be invalidated/regenerated.Closes #1747