-
Notifications
You must be signed in to change notification settings - Fork 4
Stop volunteers from accessing each other's urls. #408
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% extends "vms/base.html" %} | ||
|
||
{% load i18n %} | ||
|
||
{% block content %} | ||
<div class="spacer"></div> | ||
|
||
{% csrf_token %} | ||
<div class="panel panel-danger"> | ||
<div class="panel-heading"> | ||
<h3 class="panel-title">{% trans "No Access" %}</h3> | ||
</div> | ||
<div class="panel-body"> | ||
<br> | ||
{% trans "You don't have the necessary rights to access this page." %} | ||
<br> | ||
<br> | ||
<input type="button" class="btn btn-default" value="{% blocktrans %}Return to Previous Page{% endblocktrans %}" onClick="javascript:history.go(-1);"> | ||
</div> | ||
</div> | ||
|
||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from functools import wraps | ||
from django.shortcuts import render | ||
from django.http import Http404 | ||
from volunteer.services import get_volunteer_by_id | ||
|
||
def vol_id_check(func): | ||
@wraps(func) | ||
def wrapped_view(request, volunteer_id): | ||
vol = getattr(request.user, 'volunteer', hasattr(request.user, 'administrator')) | ||
if not vol: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @necessary129 Ok, don't change this yet |
||
return render(request, 'vms/no_volunteer_access.html', status=403) | ||
elif vol != True: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @necessary129 Could we not have a simple else clause here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see the reply to the default value one |
||
volunteer = get_volunteer_by_id(volunteer_id) | ||
if not volunteer: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing it! |
||
return render(request, 'vms/no_volunteer_access.html', status=403) | ||
if not int(volunteer.id) == vol.id: | ||
return render(request, 'vms/no_volunteer_access.html', status=403) | ||
return func(request, volunteer_id=volunteer_id) | ||
return wrapped_view |
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.
@necessary129 Why use a default value here?
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.
@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
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.
@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. :)
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.
Aah, I thought the admin also needed to access this, heh :P