Skip to content
This repository was archived by the owner on Jan 26, 2021. It is now read-only.

Stop volunteers from accessing each other's urls. #408

Merged
merged 1 commit into from
Jan 26, 2017

Conversation

necessary129
Copy link
Contributor

@necessary129 necessary129 commented Dec 9, 2016

Related to #326

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 91.557% when pulling cf35353b140089e2e4cdfc88520c98da5a2347d1 on necessary129:vol-acc-fix into 3804832 on systers:develop.

def vol_id_check(func):
@wraps(func)
def wrapped_view(request, volunteer_id):
vol = getattr(request.user, 'volunteer', hasattr(request.user, 'administrator'))
Copy link
Contributor

Choose a reason for hiding this comment

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

@necessary129 Why use a default value here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@smarshy Because it also checks if the user is an admin. if the user is a volunteer,it returns the volunteer object, if an admin, it returns true, and if not both, false

Copy link
Contributor

Choose a reason for hiding this comment

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

@necessary129 Yes, but what I meant was why not simply check if the user has volunteer attribute. If they don't , then simply display the no rights page. And in case he/she is a volunteer, the ids are checked. Did you intend to allow the administrator to view these pages? Because currently, they are able to and you haven't handled the case where vol=True (i.e. he/she is an administrator)
Don't make changes yet for this, I just want to know your views on it. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aah, I thought the admin also needed to access this, heh :P

return render(request, 'vms/no_volunteer_access.html', status=403)
elif vol != True:
volunteer = get_volunteer_by_id(volunteer_id)
if not volunteer:
Copy link
Contributor

Choose a reason for hiding this comment

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

@necessary129 Why have this? It reveals to the user the number of volunteers present in the system. Why not simply display a no volunteers page if the ids don't match?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing it!

vol = getattr(request.user, 'volunteer', hasattr(request.user, 'administrator'))
if not vol:
return render(request, 'vms/no_volunteer_access.html', status=403)
elif vol != True:
Copy link
Contributor

Choose a reason for hiding this comment

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

@necessary129 Could we not have a simple else clause here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see the reply to the default value one

@wraps(func)
def wrapped_view(request, volunteer_id):
vol = getattr(request.user, 'volunteer', hasattr(request.user, 'administrator'))
if not vol:
Copy link
Contributor

Choose a reason for hiding this comment

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

@necessary129 You have this check to ensure if the user is logged in, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but also if the user was added through the admin interface, where they aren't an admin or a volunteer, it will display a no rights page

Copy link
Contributor

Choose a reason for hiding this comment

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

@necessary129 I did not understand how this is possible. A user can be added through the admin interface by another admin. If a user is added to the system they are necessarily either an admin or a volunteer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well.. in my local db, there is a user who is neither an admin nor a volunteer. ie, only a django.contrib.auth.models.User. It happens when you add a user by python manage.py createsuperuser or like accessing the /admin page and adding only a user.

Copy link
Contributor

@smarshy smarshy Dec 10, 2016

Choose a reason for hiding this comment

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

@necessary129 Ok, don't change this yet

@smarshy
Copy link
Contributor

smarshy commented Dec 10, 2016

@necessary129 One test fails. Most probably, the test would be updated rather than your code to fix that. Also, I need to verify whether admins should be able to view these pages or not. So, there could be possible changes required later to get this merged.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 91.557% when pulling e1ae1799a207085d2b5a32c7458b6c1fc633a55a on necessary129:vol-acc-fix into 282b3b2 on systers:develop.

@necessary129
Copy link
Contributor Author

@smarshy Fixed the tests!

@smarshy
Copy link
Contributor

smarshy commented Jan 26, 2017

@necessary129 Could you please change 'fixes' to 'related to' or something similar in the description and commit message? A few more urls have been added to the issue which haven't been handled in this PR.

Related to #326
also fix the test.
@necessary129
Copy link
Contributor Author

Aye aye!

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 91.748% when pulling d750aa8 on necessary129:vol-acc-fix into 6751c3b on systers:develop.

@smarshy smarshy merged commit 880a3c8 into anitab-org:develop Jan 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants