# HG changeset patch # User Sverre Rabbelier # Date 1232038875 0 # Node ID 25ffebd9fa8f3977ab1f37af98fd65be59895382 # Parent 68c0eb8656bcfc2ce0b48a8ee223265a74223a28 Implement the checkIsClubAppAccepted function Also added a stub for checkIsClubAdminForClub. Patch by: Sverre Rabbelier diff -r 68c0eb8656bc -r 25ffebd9fa8f app/soc/views/helper/access.py --- a/app/soc/views/helper/access.py Wed Jan 14 22:37:05 2009 +0000 +++ b/app/soc/views/helper/access.py Thu Jan 15 17:01:15 2009 +0000 @@ -261,6 +261,39 @@ raise out_of_band.LoginRequest(message_fmt=login_message_fmt) +def checkIsClubAdminForClub(request): + """Returns an alternate HTTP response if Google Account has no Club Admin + entity for the specified club. + + Args: + request: a Django HTTP request + + Raises: + AccessViolationResponse: if the required authorization is not met + + Returns: + None if Club Admin exists for the specified club, or a subclass of + django.http.HttpResponse which contains the alternate response + should be returned by the calling view. + """ + + try: + # if the current user is invited to create a host profile we allow access + checkIsDeveloper(request) + return + except out_of_band.Error: + pass + + checkIsUser(request) + + # TODO(srabbelier) implement this + + login_message_fmt = DEF_DEV_LOGOUT_LOGIN_MSG_FMT % { + 'role': 'a Club Admin for this Club'} + + raise out_of_band.LoginRequest(message_fmt=login_message_fmt) + + def checkIsInvited(request): """Returns an alternate HTTP response if Google Account has no Host entity for the specified program. @@ -321,7 +354,8 @@ raise out_of_band.LoginRequest(message_fmt=login_message_fmt) -def checkIsApplied(request): + +def checkIsClubAppAccepted(request): """Returns an alternate HTTP response if Google Account has no Club App entity for the specified Club. @@ -337,8 +371,32 @@ should be returned by the calling view. """ - #TODO(srabbelier): implement this - pass + try: + # if the current user is a developer we allow access + checkIsDeveloper(request) + return + except out_of_band.Error: + pass + + checkIsUser(request) + + user = user_logic.logic.getForCurrentAccount() + + properties = { + 'applicant': user, + 'reviewed': True, + 'accepted': True, + 'application_completed': False, + } + + group_app = group_app_logic.logic.getForFields(properties, unique=True) + + if group_app: + return + + # TODO(srabbelier) Make this give a proper error message + deny(request) + def checkIsMyNotification(request): """Returns an alternate HTTP response if this request is for a Notification belonging diff -r 68c0eb8656bc -r 25ffebd9fa8f app/soc/views/models/club.py --- a/app/soc/views/models/club.py Wed Jan 14 22:37:05 2009 +0000 +++ b/app/soc/views/models/club.py Thu Jan 15 17:01:15 2009 +0000 @@ -51,7 +51,8 @@ """ rights = {} - rights['create'] = [access.checkIsApplied] + rights['create'] = [access.checkIsClubAppAccepted] + rights['edit'] = [access.checkIsClubAdminForClub] new_params = {} new_params['logic'] = soc.logic.models.club.logic @@ -65,6 +66,8 @@ required=False), } + new_params['edit_redirect'] = '/notification/list' + params = dicts.merge(params, new_params) super(View, self).__init__(params=params) @@ -117,4 +120,4 @@ delete = view.delete edit = view.edit list = view.list -public = view.public \ No newline at end of file +public = view.public