app/soc/views/models/org_admin.py
author Lennard de Rijk <ljvderijk@gmail.com>
Tue, 03 Feb 2009 15:18:40 +0000
changeset 1203 38225f2ad3a6
parent 1184 bd9c6101d41d
child 1248 f318538394d9
permissions -rw-r--r--
Renamed checkHasRole to checkHasActiveRole. We need this distinction to later allow another check to grant access upon a role that also might be inactive. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1128
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
#
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
#
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
#
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
#
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    16
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    17
"""Views for Organization Admins.
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
"""
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    19
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    20
__authors__ = [
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    21
    '"Lennard de Rijk" <ljvderijk@gmail.com>'
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
  ]
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    25
from django import forms
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    26
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    27
from soc.logic import dicts
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
from soc.logic.models import organization as org_logic
1163
d8c50be19232 Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1128
diff changeset
    29
from soc.logic.models import org_admin as org_admin_logic
1128
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    30
from soc.views.helper import access
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    31
from soc.views.helper import dynaform
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
from soc.views.helper import widgets
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    33
from soc.views.models import organization as org_view
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
from soc.views.models import role
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    35
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
import soc.logic.models.org_admin
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    37
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    38
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
class View(role.View):
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
  """View methods for the Organization Admin model.
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
  """
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    43
  def __init__(self, params=None):
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
    """Defines the fields and methods required for the base View class
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
    to provide the user with list, public, create, edit and delete views.
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
    Params:
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
      params: a dict with params for this View
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
    """
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
    rights = access.Checker(params)
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
    rights['create'] = ['checkIsDeveloper']
1203
38225f2ad3a6 Renamed checkHasRole to checkHasActiveRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1184
diff changeset
    53
    rights['edit'] = [('checkHasActiveRole', org_admin_logic.logic)]
1128
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    54
    rights['delete'] = ['checkIsDeveloper']
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    55
    # TODO accessCheck checkIsAdministratorForOrg
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    56
    rights['invite'] = ['checkIsDeveloper']
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    57
    rights['accept_invite'] = [('checkCanCreateFromRequest', 'org_admin')]
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    58
    # TODO accessCheck checkIsAdministratorForOrg
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    59
    rights['process_request'] = ['checkIsDeveloper',
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    60
        ('checkCanProcessRequest', 'org_admin')]
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    61
    rights['manage'] = [
1184
bd9c6101d41d Use .logic in checkIsAllowedToManageRole at the caller
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1163
diff changeset
    62
        ('checkIsAllowedToManageRole', [soc.logic.models.org_admin.logic,
bd9c6101d41d Use .logic in checkIsAllowedToManageRole at the caller
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1163
diff changeset
    63
             soc.logic.models.org_admin.logic])]
1128
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    64
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    65
    new_params = {}
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
    new_params['logic'] = soc.logic.models.org_admin.logic
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    67
    new_params['group_logic'] = org_logic.logic
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
    new_params['group_view'] = org_view.view
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    69
    new_params['rights'] = rights
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    70
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    71
    new_params['scope_view'] = org_view
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    72
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    73
    new_params['name'] = "Organization Admin"
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    74
    new_params['module_name'] = "org_admin"
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    75
    new_params['sidebar_grouping'] = 'Organizations'
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    76
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    77
    new_params['extra_dynaexclude'] = ['agreed_to_tos']
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    78
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    79
    new_params['allow_invites'] = True
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    80
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    81
    params = dicts.merge(params, new_params)
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    82
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    83
    super(View, self).__init__(params=params)
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    84
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    85
    # register the role with the group_view
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    86
    params['group_view'].registerRole(params['module_name'], self)
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    87
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    88
    # create and store the special form for invited users
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    89
    updated_fields = {
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    90
        'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    91
            required=False)}
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    92
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    93
    invited_create_form = dynaform.extendDynaForm(
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    94
        dynaform = self._params['create_form'],
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    95
        dynafields = updated_fields)
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    96
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    97
    params['invited_create_form'] = invited_create_form
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    98
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    99
  def _editPost(self, request, entity, fields):
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   100
    """See base.View._editPost().
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   101
    """
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   102
    if not entity:
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   103
      fields['user'] = fields['link_id']
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   104
      fields['link_id'] = fields['user'].link_id
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   105
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   106
    super(View, self)._editPost(request, entity, fields)
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   107
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   108
  def _acceptInvitePost(self, fields, request, context, params, **kwargs):
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   109
    """Fills in the fields that were missing in the invited_created_form.
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   110
    
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   111
    For params see base.View._acceptInvitePost()
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   112
    """
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   113
    # fill in the appropriate fields that were missing in the form
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   114
    fields['user'] = fields['link_id']
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   115
    fields['link_id'] = fields['user'].link_id
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   116
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   117
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   118
view = View()
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   119
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   120
accept_invite = view.acceptInvite
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   121
create = view.create
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   122
delete = view.delete
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   123
edit = view.edit
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   124
invite = view.invite
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   125
list = view.list
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   126
manage = view.manage
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   127
process_request = view.processRequest
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   128
public = view.public
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   129
export = view.export