author | Pawel Solyga <Pawel.Solyga@gmail.com> |
Tue, 20 Jan 2009 21:00:55 +0000 | |
changeset 848 | 07fd6a603c24 |
parent 814 | 25ffebd9fa8f |
child 872 | 70e0b6d8ff73 |
permissions | -rw-r--r-- |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
2 |
# |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
4 |
# |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
8 |
# |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
10 |
# |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
16 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
17 |
"""Access control helper. |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
18 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
19 |
The functions in this module can be used to check access control |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
20 |
related requirements. When the specified required conditions are not |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
21 |
met, an exception is raised. This exception contains a views that |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
22 |
either prompts for authentication, or informs the user that they |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
23 |
do not meet the required criteria. |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
24 |
""" |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
25 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
26 |
__authors__ = [ |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
27 |
'"Todd Larsen" <tlarsen@google.com>', |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
28 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
726 | 29 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
30 |
'"Pawel Solyga" <pawel.solyga@gmail.com>', |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
31 |
] |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
32 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
33 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
34 |
from google.appengine.api import users |
315
c4f1a07ee340
Add missing blank lines between imports in access.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
309
diff
changeset
|
35 |
|
746
018efb9863dc
Fix import sorting in soc.views.helper.access module and rename 'host' to 'Program Administrator'.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
729
diff
changeset
|
36 |
from django.core import urlresolvers |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
37 |
from django.utils.translation import ugettext_lazy |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
38 |
|
481
94834a1e6c01
Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents:
448
diff
changeset
|
39 |
from soc.logic import accounts |
720
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
40 |
from soc.logic import dicts |
709
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
41 |
from soc.logic.models import host as host_logic |
726 | 42 |
from soc.logic.models import notification as notification_logic |
791
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
43 |
from soc.logic.models import group_app as group_app_logic |
525
1dc62d570eff
Created a checkIsInvited method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
508
diff
changeset
|
44 |
from soc.logic.models import user as user_logic |
1dc62d570eff
Created a checkIsInvited method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
508
diff
changeset
|
45 |
from soc.logic.models import request as request_logic |
508
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
46 |
from soc.views import helper |
543
280a1ac6bcc1
Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents:
525
diff
changeset
|
47 |
from soc.views import out_of_band |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
48 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
49 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
50 |
DEF_NO_USER_LOGIN_MSG_FMT = ugettext_lazy( |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
51 |
'Please create <a href="/user/edit">User Profile</a>' |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
52 |
' in order to view this page.') |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
53 |
|
320
a0a86306e7f6
Some indentations fixes and ugettext_lazy() wrap up for DEF_DEV_LOGOUT_LOGIN_MSG_FMT in access.py.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
315
diff
changeset
|
54 |
DEF_DEV_LOGOUT_LOGIN_MSG_FMT = ugettext_lazy( |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
55 |
'Please <a href="%%(sign_out)s">sign out</a>' |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
56 |
' and <a href="%%(sign_in)s">sign in</a>' |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
57 |
' again as %(role)s to view this page.') |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
58 |
|
508
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
59 |
DEF_PAGE_DENIED_MSG = ugettext_lazy( |
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
60 |
'Access to this page has been restricted') |
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
61 |
|
590
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
62 |
DEF_LOGOUT_MSG_FMT = ugettext_lazy( |
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
63 |
'Please <a href="%(sign_out)s">sign out</a> in order to view this page') |
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
64 |
|
508
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
65 |
|
612
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
66 |
def checkAccess(access_type, request, rights): |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
67 |
"""Runs all the defined checks for the specified type. |
612
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
68 |
|
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
69 |
Args: |
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
70 |
access_type: the type of request (such as 'list' or 'edit') |
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
71 |
request: the Django request object |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
72 |
rights: a dictionary containing access check functions |
612
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
73 |
|
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
74 |
Rights usage: |
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
75 |
The rights dictionary is used to check if the current user is allowed |
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
76 |
to view the page specified. The functions defined in this dictionary |
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
77 |
are always called with the django request object as argument. On any |
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
78 |
request, regardless of what type, the functions in the 'any_access' value |
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
79 |
are called. If the specified type is not in the rights dictionary, all |
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
80 |
the functions in the 'unspecified' value are called. When the specified |
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
81 |
type _is_ in the rights dictionary, all the functions in that access_type's |
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
82 |
value are called. |
612
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
83 |
|
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
84 |
Returns: |
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
85 |
True: If all the required access checks have been made successfully |
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
86 |
False: If a check failed, in this case self._response will contain |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
87 |
the response provided by the failed access check. |
612
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
88 |
""" |
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
89 |
|
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
90 |
# Call each access checker |
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
91 |
for check in rights['any_access']: |
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
92 |
check(request) |
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
93 |
|
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
94 |
if access_type not in rights: |
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
95 |
for check in rights['unspecified']: |
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
96 |
# No checks defined, so do the 'generic' checks and bail out |
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
97 |
check(request) |
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
98 |
return |
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
99 |
|
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
100 |
for check in rights[access_type]: |
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
101 |
check(request) |
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
102 |
|
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
590
diff
changeset
|
103 |
|
508
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
104 |
def allow(request): |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
105 |
"""Never returns an alternate HTTP response. |
508
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
106 |
|
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
107 |
Args: |
543
280a1ac6bcc1
Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents:
525
diff
changeset
|
108 |
request: a Django HTTP request |
508
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
109 |
""" |
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
110 |
|
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
111 |
return |
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
112 |
|
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
113 |
def deny(request): |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
114 |
"""Returns an alternate HTTP response. |
508
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
115 |
|
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
116 |
Args: |
543
280a1ac6bcc1
Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents:
525
diff
changeset
|
117 |
request: a Django HTTP request |
508
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
118 |
|
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
119 |
Returns: |
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
120 |
a subclass of django.http.HttpResponse which contains the |
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
121 |
alternate response that should be returned by the calling view. |
508
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
122 |
""" |
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
123 |
|
709
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
124 |
context = {} |
543
280a1ac6bcc1
Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents:
525
diff
changeset
|
125 |
context['title'] = 'Access denied' |
508
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
126 |
|
543
280a1ac6bcc1
Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents:
525
diff
changeset
|
127 |
raise out_of_band.AccessViolation(DEF_PAGE_DENIED_MSG, context=context) |
508
2b90baceac88
Add a access.deny and access.allow method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
128 |
|
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
129 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
130 |
def checkIsLoggedIn(request): |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
131 |
"""Returns an alternate HTTP response if Google Account is not logged in. |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
132 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
133 |
Args: |
543
280a1ac6bcc1
Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents:
525
diff
changeset
|
134 |
request: a Django HTTP request |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
135 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
136 |
Raises: |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
137 |
AccessViolationResponse: if the required authorization is not met |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
138 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
139 |
Returns: |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
140 |
None if the user is logged in, or a subclass of |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
141 |
django.http.HttpResponse which contains the alternate response |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
142 |
that should be returned by the calling view. |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
143 |
""" |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
144 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
145 |
if users.get_current_user(): |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
146 |
return |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
147 |
|
543
280a1ac6bcc1
Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents:
525
diff
changeset
|
148 |
raise out_of_band.LoginRequest() |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
149 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
150 |
|
590
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
151 |
def checkNotLoggedIn(request): |
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
152 |
"""Returns an alternate HTTP response if Google Account is not logged in. |
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
153 |
|
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
154 |
Args: |
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
155 |
request: a Django HTTP request |
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
156 |
|
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
157 |
Raises: |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
158 |
AccessViolationResponse: if the required authorization is not met |
590
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
159 |
|
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
160 |
Returns: |
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
161 |
None if the user is logged in, or a subclass of |
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
162 |
django.http.HttpResponse which contains the alternate response |
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
163 |
that should be returned by the calling view. |
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
164 |
""" |
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
165 |
|
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
166 |
if not users.get_current_user(): |
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
167 |
return |
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
168 |
|
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
169 |
raise out_of_band.LoginRequest(message_fmt=DEF_LOGOUT_MSG_FMT) |
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
170 |
|
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
171 |
|
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
172 |
def checkIsUser(request): |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
173 |
"""Returns an alternate HTTP response if Google Account has no User entity. |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
174 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
175 |
Args: |
543
280a1ac6bcc1
Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents:
525
diff
changeset
|
176 |
request: a Django HTTP request |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
177 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
178 |
Raises: |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
179 |
AccessViolationResponse: if the required authorization is not met |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
180 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
181 |
Returns: |
481
94834a1e6c01
Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents:
448
diff
changeset
|
182 |
None if User exists for a Google Account, or a subclass of |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
183 |
django.http.HttpResponse which contains the alternate response |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
184 |
should be returned by the calling view. |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
185 |
""" |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
186 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
187 |
checkIsLoggedIn(request) |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
188 |
|
525
1dc62d570eff
Created a checkIsInvited method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
508
diff
changeset
|
189 |
user = user_logic.logic.getForFields( |
481
94834a1e6c01
Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents:
448
diff
changeset
|
190 |
{'account': users.get_current_user()}, unique=True) |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
191 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
192 |
if user: |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
193 |
return |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
194 |
|
543
280a1ac6bcc1
Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents:
525
diff
changeset
|
195 |
raise out_of_band.LoginRequest(message_fmt=DEF_NO_USER_LOGIN_MSG_FMT) |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
196 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
197 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
198 |
def checkIsDeveloper(request): |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
199 |
"""Returns an alternate HTTP response if Google Account is not a Developer. |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
200 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
201 |
Args: |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
202 |
request: a Django HTTP request |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
203 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
204 |
Raises: |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
205 |
AccessViolationResponse: if the required authorization is not met |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
206 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
207 |
Returns: |
481
94834a1e6c01
Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents:
448
diff
changeset
|
208 |
None if Google Account is logged in and logged-in user is a Developer, |
94834a1e6c01
Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents:
448
diff
changeset
|
209 |
or a subclass of django.http.HttpResponse which contains the alternate |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
210 |
response should be returned by the calling view. |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
211 |
""" |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
212 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
213 |
checkIsUser(request) |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
214 |
|
481
94834a1e6c01
Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents:
448
diff
changeset
|
215 |
if accounts.isDeveloper(account=users.get_current_user()): |
699
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
639
diff
changeset
|
216 |
return |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
217 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
218 |
login_message_fmt = DEF_DEV_LOGOUT_LOGIN_MSG_FMT % { |
746
018efb9863dc
Fix import sorting in soc.views.helper.access module and rename 'host' to 'Program Administrator'.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
729
diff
changeset
|
219 |
'role': 'a Site Developer '} |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
220 |
|
543
280a1ac6bcc1
Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents:
525
diff
changeset
|
221 |
raise out_of_band.LoginRequest(message_fmt=login_message_fmt) |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
222 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
223 |
|
709
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
224 |
def checkIsHost(request): |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
225 |
"""Returns an alternate HTTP response if Google Account has no Host entity |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
226 |
for the specified program. |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
227 |
|
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
228 |
Args: |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
229 |
request: a Django HTTP request |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
230 |
|
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
231 |
Raises: |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
232 |
AccessViolationResponse: if the required authorization is not met |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
233 |
|
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
234 |
Returns: |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
235 |
None if Host exists for the specified program, or a subclass of |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
236 |
django.http.HttpResponse which contains the alternate response |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
237 |
should be returned by the calling view. |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
238 |
""" |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
239 |
|
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
240 |
try: |
720
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
241 |
# if the current user is invited to create a host profile we allow access |
709
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
242 |
checkIsInvited(request) |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
243 |
return |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
244 |
except out_of_band.Error: |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
245 |
pass |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
246 |
|
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
247 |
checkIsUser(request) |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
248 |
|
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
249 |
user = user_logic.logic.getForFields( |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
250 |
{'account': users.get_current_user()}, unique=True) |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
251 |
|
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
252 |
host = host_logic.logic.getForFields( |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
253 |
{'user': user}, unique=True) |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
254 |
|
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
255 |
if host: |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
256 |
return |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
257 |
|
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
258 |
login_message_fmt = DEF_DEV_LOGOUT_LOGIN_MSG_FMT % { |
746
018efb9863dc
Fix import sorting in soc.views.helper.access module and rename 'host' to 'Program Administrator'.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
729
diff
changeset
|
259 |
'role': 'a Program Administrator '} |
709
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
260 |
|
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
261 |
raise out_of_band.LoginRequest(message_fmt=login_message_fmt) |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
262 |
|
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
263 |
|
814
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
264 |
def checkIsClubAdminForClub(request): |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
265 |
"""Returns an alternate HTTP response if Google Account has no Club Admin |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
266 |
entity for the specified club. |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
267 |
|
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
268 |
Args: |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
269 |
request: a Django HTTP request |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
270 |
|
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
271 |
Raises: |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
272 |
AccessViolationResponse: if the required authorization is not met |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
273 |
|
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
274 |
Returns: |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
275 |
None if Club Admin exists for the specified club, or a subclass of |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
276 |
django.http.HttpResponse which contains the alternate response |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
277 |
should be returned by the calling view. |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
278 |
""" |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
279 |
|
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
280 |
try: |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
281 |
# if the current user is invited to create a host profile we allow access |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
282 |
checkIsDeveloper(request) |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
283 |
return |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
284 |
except out_of_band.Error: |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
285 |
pass |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
286 |
|
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
287 |
checkIsUser(request) |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
288 |
|
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
289 |
# TODO(srabbelier) implement this |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
290 |
|
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
291 |
login_message_fmt = DEF_DEV_LOGOUT_LOGIN_MSG_FMT % { |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
292 |
'role': 'a Club Admin for this Club'} |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
293 |
|
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
294 |
raise out_of_band.LoginRequest(message_fmt=login_message_fmt) |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
295 |
|
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
296 |
|
617
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
297 |
def checkIsInvited(request): |
389
9b873166d7d5
Fix identions, too long lines, unused imports and some other mistakes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
361
diff
changeset
|
298 |
"""Returns an alternate HTTP response if Google Account has no Host entity |
9b873166d7d5
Fix identions, too long lines, unused imports and some other mistakes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
361
diff
changeset
|
299 |
for the specified program. |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
300 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
301 |
Args: |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
302 |
request: a Django HTTP request |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
303 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
304 |
Raises: |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
633
diff
changeset
|
305 |
AccessViolationResponse: if the required authorization is not met |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
306 |
|
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
307 |
Returns: |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
308 |
None if Host exists for the specified program, or a subclass of |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
309 |
django.http.HttpResponse which contains the alternate response |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
310 |
should be returned by the calling view. |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
311 |
""" |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
312 |
|
633
899ec5d546bd
Allow developers access to anything that does a checkIsInvited.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
617
diff
changeset
|
313 |
try: |
899ec5d546bd
Allow developers access to anything that does a checkIsInvited.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
617
diff
changeset
|
314 |
# if the current user is a developer we allow access |
709
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
315 |
checkIsDeveloper(request) |
633
899ec5d546bd
Allow developers access to anything that does a checkIsInvited.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
617
diff
changeset
|
316 |
return |
899ec5d546bd
Allow developers access to anything that does a checkIsInvited.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
617
diff
changeset
|
317 |
except out_of_band.Error: |
899ec5d546bd
Allow developers access to anything that does a checkIsInvited.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
617
diff
changeset
|
318 |
pass |
709
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
319 |
|
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
320 |
checkIsUser(request) |
e71b20847eb0
Add checkIsHost in access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
699
diff
changeset
|
321 |
|
617
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
322 |
login_message_fmt = DEF_DEV_LOGOUT_LOGIN_MSG_FMT % { |
746
018efb9863dc
Fix import sorting in soc.views.helper.access module and rename 'host' to 'Program Administrator'.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
729
diff
changeset
|
323 |
'role': 'a Program Administrator for this Program'} |
617
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
324 |
|
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
325 |
splitpath = request.path.split('/') |
713
bcd480745f44
Thinkofix in access.checkIsInvited
Sverre Rabbelier <srabbelier@gmail.com>
parents:
709
diff
changeset
|
326 |
splitpath = splitpath[1:] # cut off leading '' |
617
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
327 |
|
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
328 |
if len(splitpath) < 4: |
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
329 |
# TODO: perhaps this needs a better explanation? |
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
330 |
deny(request) |
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
331 |
|
713
bcd480745f44
Thinkofix in access.checkIsInvited
Sverre Rabbelier <srabbelier@gmail.com>
parents:
709
diff
changeset
|
332 |
role = splitpath[0] |
bcd480745f44
Thinkofix in access.checkIsInvited
Sverre Rabbelier <srabbelier@gmail.com>
parents:
709
diff
changeset
|
333 |
group_id = splitpath[2] |
bcd480745f44
Thinkofix in access.checkIsInvited
Sverre Rabbelier <srabbelier@gmail.com>
parents:
709
diff
changeset
|
334 |
user_id = splitpath[3] |
617
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
335 |
|
525
1dc62d570eff
Created a checkIsInvited method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
508
diff
changeset
|
336 |
user = user_logic.logic.getForFields( |
1dc62d570eff
Created a checkIsInvited method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
508
diff
changeset
|
337 |
{'account': users.get_current_user()}, unique=True) |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
338 |
|
617
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
339 |
if user_id != user.link_id: |
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
340 |
# TODO: perhaps this needs a better explanation? |
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
341 |
deny(request) |
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
342 |
|
525
1dc62d570eff
Created a checkIsInvited method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
508
diff
changeset
|
343 |
properties = { |
617
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
344 |
'link_id': user_id, |
525
1dc62d570eff
Created a checkIsInvited method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
508
diff
changeset
|
345 |
'role': role, |
617
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
346 |
'scope_path': group_id, |
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
347 |
'group_accepted': True, |
525
1dc62d570eff
Created a checkIsInvited method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
508
diff
changeset
|
348 |
} |
1dc62d570eff
Created a checkIsInvited method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
508
diff
changeset
|
349 |
|
1dc62d570eff
Created a checkIsInvited method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
508
diff
changeset
|
350 |
request = request_logic.logic.getForFields(properties, unique=True) |
1dc62d570eff
Created a checkIsInvited method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
508
diff
changeset
|
351 |
|
1dc62d570eff
Created a checkIsInvited method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
508
diff
changeset
|
352 |
if request: |
293
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
353 |
return |
1edd01373e71
Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
354 |
|
543
280a1ac6bcc1
Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents:
525
diff
changeset
|
355 |
raise out_of_band.LoginRequest(message_fmt=login_message_fmt) |
699
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
639
diff
changeset
|
356 |
|
814
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
357 |
|
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
358 |
def checkIsClubAppAccepted(request): |
802
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
796
diff
changeset
|
359 |
"""Returns an alternate HTTP response if Google Account has no Club App |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
796
diff
changeset
|
360 |
entity for the specified Club. |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
796
diff
changeset
|
361 |
|
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
796
diff
changeset
|
362 |
Args: |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
796
diff
changeset
|
363 |
request: a Django HTTP request |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
796
diff
changeset
|
364 |
|
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
796
diff
changeset
|
365 |
Raises: |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
796
diff
changeset
|
366 |
AccessViolationResponse: if the required authorization is not met |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
796
diff
changeset
|
367 |
|
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
796
diff
changeset
|
368 |
Returns: |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
796
diff
changeset
|
369 |
None if Club App exists for the specified program, or a subclass |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
796
diff
changeset
|
370 |
of django.http.HttpResponse which contains the alternate response |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
796
diff
changeset
|
371 |
should be returned by the calling view. |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
796
diff
changeset
|
372 |
""" |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
796
diff
changeset
|
373 |
|
814
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
374 |
try: |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
375 |
# if the current user is a developer we allow access |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
376 |
checkIsDeveloper(request) |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
377 |
return |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
378 |
except out_of_band.Error: |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
379 |
pass |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
380 |
|
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
381 |
checkIsUser(request) |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
382 |
|
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
383 |
user = user_logic.logic.getForCurrentAccount() |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
384 |
|
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
385 |
properties = { |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
386 |
'applicant': user, |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
387 |
'reviewed': True, |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
388 |
'accepted': True, |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
389 |
'application_completed': False, |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
390 |
} |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
391 |
|
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
392 |
group_app = group_app_logic.logic.getForFields(properties, unique=True) |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
393 |
|
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
394 |
if group_app: |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
395 |
return |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
396 |
|
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
397 |
# TODO(srabbelier) Make this give a proper error message |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
398 |
deny(request) |
25ffebd9fa8f
Implement the checkIsClubAppAccepted function
Sverre Rabbelier <srabbelier@gmail.com>
parents:
802
diff
changeset
|
399 |
|
802
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
796
diff
changeset
|
400 |
|
726 | 401 |
def checkIsMyNotification(request): |
402 |
"""Returns an alternate HTTP response if this request is for a Notification belonging |
|
403 |
to the current user. |
|
404 |
||
405 |
Args: |
|
406 |
request: a Django HTTP request |
|
407 |
||
408 |
Raises: |
|
409 |
AccessViolationResponse: if the required authorization is not met |
|
410 |
||
411 |
Returns: |
|
412 |
None if the current User is allowed to access this Notification. |
|
413 |
""" |
|
414 |
||
415 |
try: |
|
416 |
# if the current user is a developer we allow access |
|
417 |
checkIsDeveloper(request) |
|
418 |
return |
|
419 |
except out_of_band.Error: |
|
420 |
pass |
|
421 |
||
422 |
checkIsUser(request) |
|
729
7fe218e3d359
Make checkIsMyInvitation use Django to parse the URL
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
423 |
|
7fe218e3d359
Make checkIsMyInvitation use Django to parse the URL
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
424 |
# Mine the url for params |
7fe218e3d359
Make checkIsMyInvitation use Django to parse the URL
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
425 |
try: |
7fe218e3d359
Make checkIsMyInvitation use Django to parse the URL
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
426 |
callback, args, kwargs = urlresolvers.resolve(request.path) |
7fe218e3d359
Make checkIsMyInvitation use Django to parse the URL
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
427 |
except Exception: |
7fe218e3d359
Make checkIsMyInvitation use Django to parse the URL
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
428 |
deny(request) |
7fe218e3d359
Make checkIsMyInvitation use Django to parse the URL
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
429 |
|
7fe218e3d359
Make checkIsMyInvitation use Django to parse the URL
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
430 |
properties = dicts.filter(kwargs, ['link_id', 'scope_path']) |
7fe218e3d359
Make checkIsMyInvitation use Django to parse the URL
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
431 |
|
726 | 432 |
notification = notification_logic.logic.getForFields(properties, unique=True) |
727
ddf44af087a0
Using getForCurrentAccount where possible due to comments on r1309.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
726
diff
changeset
|
433 |
user = user_logic.logic.getForCurrentAccount() |
729
7fe218e3d359
Make checkIsMyInvitation use Django to parse the URL
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
434 |
|
7fe218e3d359
Make checkIsMyInvitation use Django to parse the URL
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
435 |
# We need to check to see if the key's are equal since the User |
7fe218e3d359
Make checkIsMyInvitation use Django to parse the URL
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
436 |
# objects are different and the default __eq__ method does not check |
7fe218e3d359
Make checkIsMyInvitation use Django to parse the URL
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
437 |
# if the keys are equal (which is what we want). |
726 | 438 |
if user.key() == notification.scope.key(): |
439 |
return None |
|
729
7fe218e3d359
Make checkIsMyInvitation use Django to parse the URL
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
440 |
|
7fe218e3d359
Make checkIsMyInvitation use Django to parse the URL
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
441 |
# TODO(ljvderijk) Make this give a proper error message |
7fe218e3d359
Make checkIsMyInvitation use Django to parse the URL
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
442 |
deny(request) |
699
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
639
diff
changeset
|
443 |
|
791
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
444 |
def checkIsMyApplication(request): |
796
126a1ef235ec
Fixed a typo in the comment in helper/access.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
791
diff
changeset
|
445 |
"""Returns an alternate HTTP response if this request is for a Application belonging |
791
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
446 |
to the current user. |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
447 |
|
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
448 |
Args: |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
449 |
request: a Django HTTP request |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
450 |
|
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
451 |
Raises: |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
452 |
AccessViolationResponse: if the required authorization is not met |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
453 |
|
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
454 |
Returns: |
796
126a1ef235ec
Fixed a typo in the comment in helper/access.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
791
diff
changeset
|
455 |
None if the current User is allowed to access this Application. |
791
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
456 |
""" |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
457 |
|
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
458 |
try: |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
459 |
# if the current user is a developer we allow access |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
460 |
checkIsDeveloper(request) |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
461 |
return |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
462 |
except out_of_band.Error: |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
463 |
pass |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
464 |
|
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
465 |
checkIsUser(request) |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
466 |
|
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
467 |
# Mine the url for params |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
468 |
try: |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
469 |
callback, args, kwargs = urlresolvers.resolve(request.path) |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
470 |
except Exception: |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
471 |
deny(request) |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
472 |
|
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
473 |
properties = dicts.filter(kwargs, ['link_id']) |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
474 |
|
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
475 |
application = group_app_logic.logic.getForFields(properties, unique=True) |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
476 |
user = user_logic.logic.getForCurrentAccount() |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
477 |
|
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
478 |
# We need to check to see if the key's are equal since the User |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
479 |
# objects are different and the default __eq__ method does not check |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
480 |
# if the keys are equal (which is what we want). |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
481 |
if user.key() == application.applicant.key(): |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
482 |
return None |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
483 |
|
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
484 |
# TODO(srabbelier) Make this give a proper error message |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
485 |
deny(request) |
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
486 |
|
30da180c4bca
Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
746
diff
changeset
|
487 |
|
720
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
488 |
def checkCanInvite(request): |
746
018efb9863dc
Fix import sorting in soc.views.helper.access module and rename 'host' to 'Program Administrator'.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
729
diff
changeset
|
489 |
"""Checks to see if the current user can create an invite. |
720
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
490 |
|
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
491 |
Note that if the current url is not in the default 'request' form |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
492 |
this method either deny()s or performs the wrong access check. |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
493 |
|
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
494 |
Args: |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
495 |
request: a Django HTTP request |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
496 |
""" |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
497 |
|
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
498 |
try: |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
499 |
# if the current user is a developer we allow access |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
500 |
checkIsDeveloper(request) |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
501 |
return |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
502 |
except out_of_band.Error: |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
503 |
pass |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
504 |
|
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
505 |
# Mine the url for params |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
506 |
try: |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
507 |
callback, args, kwargs = urlresolvers.resolve(request.path) |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
508 |
except Exception: |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
509 |
deny(request) |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
510 |
|
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
511 |
# Construct a new url by reshufling the kwargs |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
512 |
order = ['role', 'access_type', 'scope_path', 'link_id'] |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
513 |
url_params = dicts.unzip(kwargs, order) |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
514 |
url = '/'.join([''] + list(url_params)) |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
515 |
|
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
516 |
# Mine the reshufled url |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
517 |
try: |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
518 |
callback, args, kwargs = urlresolvers.resolve(url) |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
519 |
except Exception: |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
520 |
deny(request) |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
521 |
|
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
522 |
# Get the everything we need for the access check |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
523 |
params = callback.im_self.getParams() |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
524 |
access_type = kwargs['access_type'] |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
525 |
|
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
526 |
# Perform the access check |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
527 |
helper.access.checkAccess(access_type, request, rights=params['rights']) |
9eb2522dfa83
Make it possible to invite another Host as Host
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
528 |
|
699
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
639
diff
changeset
|
529 |
def checkIsDocumentPublic(request): |
714
3e2ce3d8057a
Add missing dots in docstrings, proper sorting of imports and small docstring typo fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
713
diff
changeset
|
530 |
"""Checks whether a document is public. |
699
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
639
diff
changeset
|
531 |
|
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
639
diff
changeset
|
532 |
Args: |
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
639
diff
changeset
|
533 |
request: a Django HTTP request |
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
639
diff
changeset
|
534 |
""" |
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
639
diff
changeset
|
535 |
|
714
3e2ce3d8057a
Add missing dots in docstrings, proper sorting of imports and small docstring typo fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
713
diff
changeset
|
536 |
# TODO(srabbelier): A proper check needs to be done to see if the document |
699
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
639
diff
changeset
|
537 |
# is public or not, probably involving analysing it's scope or such. |
4e8eefe95748
Add and use a placeholder for checkIsDocumentPublic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
639
diff
changeset
|
538 |
allow(request) |