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 |
434 # check to see if resign is true |
432 # check to see if resign is true |
435 get_dict = request.GET |
433 get_dict = request.GET |
436 resign = get_dict.get('resign') |
434 resign = get_dict.get('resign') |
437 |
435 |
438 if resign == 'true': |
436 if resign == 'true': |
439 |
437 # change the status of this role_entity to invalid |
440 if params.get('disallow_last_resign'): |
438 fields = {'status': 'invalid'} |
441 # check if the current role is the last for this scope |
439 logic.updateEntityProperties(role_entity, fields) |
442 fields = {'scope': role_entity.scope, |
440 |
443 'status': 'active'} |
441 # redirect to the roles listing |
444 roles = logic.getForFields(fields, limit=2) |
442 return http.HttpResponseRedirect(redirect) |
445 |
|
446 # if there is more then one left we can safely resign |
|
447 resign = len(roles) > 1 |
|
448 else: |
|
449 resign = True |
|
450 |
|
451 if resign: |
|
452 # change the status of this role_entity to invalid |
|
453 fields = {'status': 'invalid'} |
|
454 logic.updateEntityProperties(role_entity, fields) |
|
455 |
|
456 # redirect to the roles listing |
|
457 return http.HttpResponseRedirect(redirect) |
|
458 else: |
|
459 # show error to the user |
|
460 context['not_allowed_to_resign'] = ugettext("This user can't be " |
|
461 "resigned, please make sure it's not the last %(name)s." % params) |
|
462 |
443 |
463 # set the appropriate context |
444 # set the appropriate context |
464 context['entity'] = role_entity |
445 context['entity'] = role_entity |
465 context['url_name'] = params['url_name'] |
446 context['url_name'] = params['url_name'] |
466 context['cancel_redirect'] = redirect |
447 context['cancel_redirect'] = redirect |