app/soc/views/models/club_member.py
author Lennard de Rijk <ljvderijk@gmail.com>
Thu, 29 Jan 2009 15:55:40 +0000
changeset 1063 f529113e1bc5
parent 1030 a0081c626acb
child 1067 ecf3df87b81c
permissions -rw-r--r--
Redone access checks in club and sponsor model to deal with state property in their model. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
#
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
#
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
#
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
#
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    16
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    17
"""Views for Club Members.
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
"""
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    19
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    20
__authors__ = [
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    21
    '"Lennard de Rijk" <ljvderijk@gmail.com>'
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
  ]
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    25
from django import forms
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    26
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    27
from soc.logic import cleaning
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
from soc.logic import dicts
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    29
from soc.logic.models import club as club_logic
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    30
from soc.views.helper import access
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    31
from soc.views.helper import dynaform
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
from soc.views.helper import widgets
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    33
from soc.views.models import club as club_view
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
from soc.views.models import role
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    35
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
import soc.logic.models.club_member
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    37
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    38
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
class View(role.View):
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
  """View methods for the Club Member model.
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
  """
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    43
  def __init__(self, params=None):
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
    """Defines the fields and methods required for the base View class
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
    to provide the user with list, public, create, edit and delete views.
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
    Params:
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
      params: a dict with params for this View
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
    """
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 998
diff changeset
    51
    rights = access.Checker(params)
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 998
diff changeset
    52
    rights['create'] = ['checkIsDeveloper']
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 998
diff changeset
    53
    rights['edit'] = [('checkIsMyActiveRole',soc.logic.models.club_member)]
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 998
diff changeset
    54
    rights['delete'] = ['checkIsDeveloper']
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 998
diff changeset
    55
    rights['invite'] = ['checkIsClubAdminForClub']
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 998
diff changeset
    56
    rights['accept_invite'] = [('checkCanCreateFromRequest','club_member')]
1012
73f0b61f2d9d Fold checkAgreesToSiteToS into checkIsUser
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    57
    rights['request'] = ['checkIsUser',
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 998
diff changeset
    58
        ('checkCanMakeRequestToGroup', club_logic)]
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 998
diff changeset
    59
    rights['process_request'] = ['checkIsClubAdminForClub',
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 998
diff changeset
    60
        ('checkCanProcessRequest','club_member')]
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    61
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    62
    new_params = {}
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    63
    new_params['logic'] = soc.logic.models.club_member.logic
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    64
    new_params['group_logic'] = club_logic.logic
990
fd1e6afb2d62 Added two needed redirects in role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 980
diff changeset
    65
    new_params['group_view'] = club_view.view
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
    new_params['rights'] = rights
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    67
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
    new_params['scope_view'] = club_view
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    69
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    70
    new_params['name'] = "Club Member"
1025
1f83f05f522b Add grouping to the existing views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1012
diff changeset
    71
    new_params['sidebar_grouping'] = 'Clubs'
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    72
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    73
    new_params['extra_dynaexclude'] = ['user', 'state']
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    74
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    75
    new_params['create_extra_dynafields'] = {
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    76
       'scope_path': forms.CharField(widget=forms.HiddenInput,
1030
a0081c626acb Style fixes in soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1025
diff changeset
    77
          required=True),
a0081c626acb Style fixes in soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1025
diff changeset
    78
       'clean_link_id': cleaning.clean_existing_user('link_id'),
a0081c626acb Style fixes in soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1025
diff changeset
    79
       'clean_home_page': cleaning.clean_url('home_page'),
a0081c626acb Style fixes in soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1025
diff changeset
    80
       'clean_blog': cleaning.clean_url('blog'),
a0081c626acb Style fixes in soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1025
diff changeset
    81
       'clean_photo_url': cleaning.clean_url('photo_url')}
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    82
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    83
    new_params['allow_requests_and_invites'] = True
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    84
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    85
    params = dicts.merge(params, new_params)
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    86
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    87
    super(View, self).__init__(params=params)
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    88
998
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
    89
    # register the role with the group_view
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
    90
    params['group_view'].registerRole(params['module_name'], self)
125257161908 Implemented the listing of all the roles in for a specific group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 990
diff changeset
    91
980
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    92
    # create and store the special form for invited users
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    93
    updated_fields = {
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    94
        'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    95
            required=False)}
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    96
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    97
    invited_create_form = dynaform.extendDynaForm(
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    98
        dynaform = self._params['create_form'],
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    99
        dynafields = updated_fields)
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   100
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   101
    params['invited_create_form'] = invited_create_form
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   102
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   103
  def _editPost(self, request, entity, fields):
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   104
    """See base.View._editPost().
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   105
    """
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   106
    
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   107
    if not entity:
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   108
      fields['user'] = fields['link_id']
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   109
      fields['link_id'] = fields['user'].link_id
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   110
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   111
    super(View, self)._editPost(request, entity, fields)
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   112
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   113
  def _acceptInvitePost(self, fields, request, context, params, **kwargs):
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   114
    """Fills in the fields that were missing in the invited_created_form.
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   115
    
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   116
    For params see base.View._acceptInvitePost()
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   117
    """
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   118
    # fill in the appropriate fields that were missing in the form
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   119
    fields['user'] = fields['link_id']
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   120
    fields['link_id'] = fields['user'].link_id
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   121
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   122
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   123
view = View()
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   124
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   125
accept_invite = view.acceptInvite
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   126
create = view.create
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   127
delete = view.delete
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   128
edit = view.edit
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   129
invite = view.invite
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   130
list = view.list
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   131
process_request = view.processRequest
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   132
request = view.request
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   133
public = view.public
3f3f7ec251bf Added Club Members to SoC.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   134
export = view.export