Refactor existing code to use the new access module
Instead of ending up with many different ways to do
access control, we end up having only one centralized
place wher access control is done.
Patch by: Sverre Rabbelier
Reviewed by: Pawel Solyga, Augie Fackler, Todd Larsen
Reviewed at: http://codereviews.googleopensourceprograms.com/1601
Review id: 1601
--- a/app/soc/views/site/docs/edit.py Thu Oct 09 23:38:27 2008 +0000
+++ b/app/soc/views/site/docs/edit.py Thu Oct 09 23:48:20 2008 +0000
@@ -31,6 +31,7 @@
from soc.logic import document
from soc.logic import out_of_band
from soc.logic import path_linkname
+from soc.logic.helper import access
from soc.logic.site import id_user
from soc.views import helper
import soc.views.helper.forms
@@ -92,34 +93,15 @@
A subclass of django.http.HttpResponse which either contains the form to
be filled out, or a redirect to the correct view in the interface.
"""
- # create default template context for use with any templates
+
+ try:
+ access.checkIsDeveloper(request)
+ except soc.logic.out_of_band.AccessViolationResponse, alt_response:
+ return alt_response.response()
+
+# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
-
logged_in_id = users.get_current_user()
-
- alt_response = simple.getAltResponseIfNotDeveloper(request, context,
- id=logged_in_id)
- if alt_response:
- # not a developer
- return alt_response
-
- alt_response = simple.getAltResponseIfNotLoggedIn(request, context,
- id=logged_in_id)
- if alt_response:
- # not logged in
- return alt_response
-
- alt_response = simple.getAltResponseIfNotUser(request, context,
- id = logged_in_id)
- if alt_response:
- # no existing User entity for logged in Google Account. User entity is
- # required for creating Documents
- return alt_response
-
- alt_response = simple.getAltResponseIfNotDeveloper(request,
- context=context)
- if alt_response:
- return alt_response
doc = None # assume that no Document entity will be found
@@ -241,21 +223,16 @@
A subclass of django.http.HttpResponse which either contains the form to
be filled out, or a redirect to the correct view in the interface.
"""
+
+ try:
+ access.checkIsDeveloper(request)
+ except soc.logic.out_of_band.AccessViolationResponse, alt_response:
+ return alt_response.response()
+
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
-
logged_in_id = users.get_current_user()
- alt_response = simple.getAltResponseIfNotDeveloper(request,
- context=context,
- id=logged_in_id)
- if alt_response:
- return alt_response
-
- alt_response = simple.getAltResponseIfNotDeveloper(request,
- context=context)
- if alt_response:
- return alt_response
if request.method == 'POST':
form = CreateForm(request.POST)
--- a/app/soc/views/site/docs/list.py Thu Oct 09 23:38:27 2008 +0000
+++ b/app/soc/views/site/docs/list.py Thu Oct 09 23:48:20 2008 +0000
@@ -23,6 +23,7 @@
from soc.logic import works
+from soc.logic.helper import access
from soc.views import simple
from soc.views import helper
import soc.views.helper.lists
@@ -45,14 +46,15 @@
A subclass of django.http.HttpResponse which either contains the form to
be filled out, or a redirect to the correct view in the interface.
"""
+
+ try:
+ access.checkIsDeveloper(request)
+ except soc.logic.out_of_band.AccessViolationResponse, alt_response:
+ return alt_response.response()
+
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
- alt_response = simple.getAltResponseIfNotDeveloper(request,
- context=context)
- if alt_response:
- return alt_response
-
offset, limit = helper.lists.cleanListParameters(
offset=request.GET.get('offset'), limit=request.GET.get('limit'))
--- a/app/soc/views/site/home.py Thu Oct 09 23:38:27 2008 +0000
+++ b/app/soc/views/site/home.py Thu Oct 09 23:48:20 2008 +0000
@@ -36,6 +36,7 @@
from soc.logic import out_of_band
from soc.logic import validate
from soc.logic.site import id_user
+from soc.logic.helper import access
from soc.views import simple
from soc.views import helper
import soc.views.helper.forms
@@ -131,30 +132,15 @@
Returns:
A subclass of django.http.HttpResponse with generated template.
"""
+
+ try:
+ access.checkIsDeveloper(request)
+ except soc.logic.out_of_band.AccessViolationResponse, alt_response:
+ return alt_response.response()
+
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
-
- logged_in_id = users.get_current_user()
-
- alt_response = simple.getAltResponseIfNotDeveloper(request, context,
- id=logged_in_id)
- if alt_response:
- # not a developer
- return alt_response
-
- alt_response = simple.getAltResponseIfNotLoggedIn(request, context,
- id=logged_in_id)
- if alt_response:
- # not logged in
- return alt_response
-
- alt_response = simple.getAltResponseIfNotUser(request, context,
- id = logged_in_id)
- if alt_response:
- # no existing User entity for logged in Google Account. User entity is
- # required for creating Documents
- return alt_response
-
+
settings_form = None
document_form = None
@@ -169,6 +155,8 @@
abstract = document_form.cleaned_data.get('abstract')
content = document_form.cleaned_data.get('content')
+ logged_in_id = users.get_current_user()
+
site_doc = soc.logic.document.updateOrCreateDocument(
partial_path=DEF_SITE_SETTINGS_PATH, link_name=link_name,
title=title, short_name=short_name, abstract=abstract,
--- a/app/soc/views/site/sponsor/list.py Thu Oct 09 23:38:27 2008 +0000
+++ b/app/soc/views/site/sponsor/list.py Thu Oct 09 23:48:20 2008 +0000
@@ -23,8 +23,8 @@
from soc.logic import sponsor
+from soc.logic.helper import access
from soc.views import simple
-
from soc.views import helper
import soc.views.helper.lists
import soc.views.helper.responses
@@ -35,14 +35,15 @@
def all(request, template=DEF_SITE_SPONSOR_LIST_ALL_TMPL):
"""Show a list of all Sponsors (limit rows per page).
"""
+
+ try:
+ access.checkIsDeveloper(request)
+ except soc.logic.out_of_band.AccessViolationResponse, alt_response:
+ return alt_response.response()
+
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
- alt_response = simple.getAltResponseIfNotDeveloper(request,
- context=context)
- if alt_response:
- return alt_response
-
offset, limit = helper.lists.cleanListParameters(
offset=request.GET.get('offset'), limit=request.GET.get('limit'))
--- a/app/soc/views/site/sponsor/profile.py Thu Oct 09 23:38:27 2008 +0000
+++ b/app/soc/views/site/sponsor/profile.py Thu Oct 09 23:48:20 2008 +0000
@@ -30,6 +30,7 @@
from soc.logic import validate
from soc.logic import out_of_band
from soc.logic import sponsor
+from soc.logic.helper import access
from soc.logic.site import id_user
from soc.views import helper
import soc.views.helper.forms
@@ -95,14 +96,15 @@
A subclass of django.http.HttpResponse which either contains the form to
be filled out, or a redirect to the correct view in the interface.
"""
+
+ try:
+ access.checkIsDeveloper(request)
+ except soc.logic.out_of_band.AccessViolationResponse, alt_response:
+ return alt_response.response()
+
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
- alt_response = simple.getAltResponseIfNotDeveloper(request,
- context=context)
- if alt_response:
- return alt_response
-
logged_in_id = users.get_current_user()
user = id_user.getUserFromId(logged_in_id)
sponsor_form = None
@@ -208,14 +210,15 @@
A subclass of django.http.HttpResponse which redirects
to /site/sponsor/list.
"""
+
+ try:
+ access.checkIsDeveloper(request)
+ except soc.logic.out_of_band.AccessViolationResponse, alt_response:
+ return alt_response.response()
+
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
- alt_response = simple.getAltResponseIfNotDeveloper(request,
- context=context)
- if alt_response:
- return alt_response
-
existing_sponsor = None
# try to fetch Sponsor entity corresponding to linkname if one exists
--- a/app/soc/views/site/user/list.py Thu Oct 09 23:38:27 2008 +0000
+++ b/app/soc/views/site/user/list.py Thu Oct 09 23:48:20 2008 +0000
@@ -22,6 +22,7 @@
]
+from soc.logic.helper import access
from soc.logic.site import id_user
from soc.views import simple
from soc.views import helper
@@ -45,14 +46,15 @@
A subclass of django.http.HttpResponse which either contains the form to
be filled out, or a redirect to the correct view in the interface.
"""
+
+ try:
+ access.checkIsDeveloper(request)
+ except soc.logic.out_of_band.AccessViolationResponse, alt_response:
+ return alt_response.response()
+
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
- alt_response = simple.getAltResponseIfNotDeveloper(request,
- context=context)
- if alt_response:
- return alt_response
-
offset, limit = helper.lists.cleanListParameters(
offset=request.GET.get('offset'), limit=request.GET.get('limit'))
--- a/app/soc/views/site/user/profile.py Thu Oct 09 23:38:27 2008 +0000
+++ b/app/soc/views/site/user/profile.py Thu Oct 09 23:48:20 2008 +0000
@@ -30,6 +30,7 @@
from soc.logic import validate
from soc.logic import out_of_band
+from soc.logic.helper import access
from soc.logic.site import id_user
from soc.views import simple
from soc.views import helper
@@ -103,14 +104,15 @@
A subclass of django.http.HttpResponse which either contains the form to
be filled out, or a redirect to the correct view in the interface.
"""
+
+ try:
+ access.checkIsDeveloper(request)
+ except soc.logic.out_of_band.AccessViolationResponse, alt_response:
+ return alt_response.response()
+
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
- alt_response = simple.getAltResponseIfNotDeveloper(request,
- context=context)
- if alt_response:
- return alt_response
-
user = None # assume that no User entity will be found
form = None # assume blank form needs to be displayed
lookup_message = ugettext_lazy('Enter information to look up a User.')
@@ -249,14 +251,15 @@
A subclass of django.http.HttpResponse which either contains the form to
be filled out, or a redirect to the correct view in the interface.
"""
+
+ try:
+ access.checkIsDeveloper(request)
+ except soc.logic.out_of_band.AccessViolationResponse, alt_response:
+ return alt_response.response()
+
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
- alt_response = simple.getAltResponseIfNotDeveloper(request,
- context=context)
- if alt_response:
- return alt_response
-
user = None # assume that no User entity will be found
# try to fetch User entity corresponding to linkname if one exists
@@ -391,14 +394,15 @@
A subclass of django.http.HttpResponse which either contains the form to
be filled out, or a redirect to the correct view in the interface.
"""
+
+ try:
+ access.checkIsDeveloper(request)
+ except soc.logic.out_of_band.AccessViolationResponse, alt_response:
+ return alt_response.response()
+
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
- alt_response = simple.getAltResponseIfNotDeveloper(request,
- context=context)
- if alt_response:
- return alt_response
-
if request.method == 'POST':
form = CreateForm(request.POST)