app/soc/views/helper/decorators.py
author Sverre Rabbelier <srabbelier@gmail.com>
Wed, 21 Jan 2009 16:12:01 +0000
changeset 873 cbb1d15ffe91
parent 499 d22e4fe8e64b
child 906 275d2f457c50
permissions -rw-r--r--
Added a merge_params and check_access decorator The merge_params decorator is very simple and takes self._params and merges it with params. It's main purpose is to explicitly mark the views in which it is intended that self._params is merged raw. The check_access decorator factors out the access checking process and passes args and kwargs to the access checking methods. Patch by: Sverre Rabbelier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
365
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     2
#
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     4
#
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     8
#
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    10
#
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    16
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    17
"""Views decorators.
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    18
"""
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    19
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    20
__authors__ = [
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    21
  '"Pawel Solyga" <pawel.solyga@gmail.com>',
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    22
  ]
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    23
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    24
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    25
import logging
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    26
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    27
from functools import wraps
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    28
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    29
from google.appengine.runtime import DeadlineExceededError
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    30
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    31
from django import http
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    32
873
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    33
from soc.logic import dicts
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    34
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    35
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    36
class Error(Exception):
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    37
  pass
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    38
365
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    39
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    40
def view(func):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 367
diff changeset
    41
  """Decorator that insists that exceptions are handled by view.
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 367
diff changeset
    42
  """
365
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    43
  @wraps(func)
367
5d5730f65fc8 Remove not needed request argument in view decorator.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 365
diff changeset
    44
  def view_wrapper(*args, **kwds):
365
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    45
    try:
367
5d5730f65fc8 Remove not needed request argument in view decorator.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 365
diff changeset
    46
      return func(*args, **kwds)
365
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    47
    except DeadlineExceededError:
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    48
      logging.exception('DeadlineExceededError')
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    49
      return http.HttpResponse('DeadlineExceededError')
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    50
    except MemoryError:
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    51
      logging.exception('MemoryError')
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    52
      return http.HttpResponse('MemoryError')
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    53
    except AssertionError:
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    54
      logging.exception('AssertionError')
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    55
      return http.HttpResponse('AssertionError')
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    56
873
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    57
  return view_wrapper
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    58
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    59
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    60
def merge_params(func):
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    61
  """Decorator that merges 'params' with self._params
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    62
  """
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    63
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    64
  @wraps(func)
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    65
  def wrapper(self, *args, **kwargs):
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    66
    params = kwargs.get('params', {})
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    67
    kwargs['params'] = dicts.merge(params, self._params)
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    68
    return func(self, *args, **kwargs)
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    69
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    70
  return wrapper
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    71
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    72
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    73
def check_access(func):
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    74
  """This decorator does access checks for the specified view method
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    75
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    76
  The rights dictionary is extracted from 'params', or, if either 'params' or
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    77
  'rights' do not exist, from self._params['rights'].
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    78
  """
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    79
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    80
  # Do not pollute helper.decorators with access specific imports
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    81
  from soc.views import out_of_band
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    82
  from soc.views import helper
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    83
  from soc.views.helper import access
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    84
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    85
  @wraps(func)
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    86
  def wrapper(self, request, access_type, *args, **kwargs):
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    87
    params = kwargs.get('params', {})
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    88
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    89
    # Try to extract rights
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    90
    if 'rights' in params:
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    91
      rights = params['rights']
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    92
    else:
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    93
      rights = self._params['rights']
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    94
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    95
    # Do the access check dance
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    96
    try:
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    97
      access.checkAccess(access_type, request, rights, args, kwargs)
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    98
    except out_of_band.Error, error:
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
    99
      return helper.responses.errorResponse(error, request)
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
   100
    return func(self, request, access_type, *args, **kwargs)
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
   101
cbb1d15ffe91 Added a merge_params and check_access decorator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 499
diff changeset
   102
  return wrapper