154 required=True), |
154 required=True), |
155 } |
155 } |
156 |
156 |
157 new_params['extra_dynaexclude'] = ['user', 'status', 'agreed_to_tos_on'] |
157 new_params['extra_dynaexclude'] = ['user', 'status', 'agreed_to_tos_on'] |
158 |
158 |
159 new_params['disallow_last_resign'] = False |
|
160 |
|
161 params = dicts.merge(params, new_params, sub_merge=True) |
159 params = dicts.merge(params, new_params, sub_merge=True) |
162 |
160 |
163 super(View, self).__init__(params=params) |
161 super(View, self).__init__(params=params) |
164 |
162 |
165 # add manage template |
163 # add manage template |
432 get_dict = request.GET |
430 get_dict = request.GET |
433 resign = get_dict.get('resign') |
431 resign = get_dict.get('resign') |
434 |
432 |
435 if resign == 'true': |
433 if resign == 'true': |
436 |
434 |
437 if params.get('disallow_last_resign'): |
435 resign_error = params['logic'].canResign(role_entity) |
438 # check if the current role is the last for this scope |
436 |
439 fields = {'scope': role_entity.scope, |
437 if not resign_error: |
440 'status': 'active'} |
|
441 roles = logic.getForFields(fields, limit=2) |
|
442 |
|
443 # if there is more then one left we can safely resign |
|
444 resign = len(roles) > 1 |
|
445 else: |
|
446 resign = True |
|
447 |
|
448 if resign: |
|
449 # change the status of this role_entity to invalid |
438 # change the status of this role_entity to invalid |
450 fields = {'status': 'invalid'} |
439 fields = {'status': 'invalid'} |
451 logic.updateEntityProperties(role_entity, fields) |
440 logic.updateEntityProperties(role_entity, fields) |
452 |
441 |
453 # redirect to the roles listing |
442 # redirect to the roles listing |
454 return http.HttpResponseRedirect(redirect) |
443 return http.HttpResponseRedirect(redirect) |
455 else: |
444 else: |
456 # show error to the user |
445 # show error to the user |
457 context['not_allowed_to_resign'] = ugettext("This user can't be " |
446 context['resign_error'] = ugettext(resign_error %params) |
458 "resigned, please make sure it's not the last %(name)s." % params) |
|
459 |
447 |
460 # set the appropriate context |
448 # set the appropriate context |
461 context['entity'] = role_entity |
449 context['entity'] = role_entity |
462 context['url_name'] = params['url_name'] |
450 context['url_name'] = params['url_name'] |
463 context['cancel_redirect'] = redirect |
451 context['cancel_redirect'] = redirect |
465 # get the manage template |
453 # get the manage template |
466 template = params['manage_template'] |
454 template = params['manage_template'] |
467 |
455 |
468 # return a proper response |
456 # return a proper response |
469 return responses.respond(request, template, context=context) |
457 return responses.respond(request, template, context=context) |
470 |
|
471 |
458 |
472 @decorators.merge_params |
459 @decorators.merge_params |
473 @decorators.check_access |
460 @decorators.check_access |
474 def request(self, request, access_type, |
461 def request(self, request, access_type, |
475 page_name=None, params=None, **kwargs): |
462 page_name=None, params=None, **kwargs): |