# HG changeset patch # User Lennard de Rijk # Date 1236464044 0 # Node ID 2d877bb10306f1be6857e6646488821dd50a9fbe # Parent c5cfa7b3cdff72ba48a2ba57681b272716ae864d Important roles can now not resign if they are the last in their group. Fixes Issue 288. I've decided to do it outside of the logic because if the need arises to kick the last org admin out of a group we need the ability to do so. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed diff -r c5cfa7b3cdff -r 2d877bb10306 app/soc/templates/soc/club_admin/manage.html --- a/app/soc/templates/soc/club_admin/manage.html Sat Mar 07 20:27:52 2009 +0000 +++ b/app/soc/templates/soc/club_admin/manage.html Sat Mar 07 22:14:04 2009 +0000 @@ -18,6 +18,7 @@ {% endblock %} {% block manage %} +
{{ not_allowed_to_resign }}
Please select the appropriate action:
diff -r c5cfa7b3cdff -r 2d877bb10306 app/soc/templates/soc/club_member/manage.html --- a/app/soc/templates/soc/club_member/manage.html Sat Mar 07 20:27:52 2009 +0000 +++ b/app/soc/templates/soc/club_member/manage.html Sat Mar 07 22:14:04 2009 +0000 @@ -18,6 +18,7 @@ {% endblock %} {% block manage %} +
{{ not_allowed_to_resign }}
Please select the appropriate action:
diff -r c5cfa7b3cdff -r 2d877bb10306 app/soc/templates/soc/mentor/manage.html --- a/app/soc/templates/soc/mentor/manage.html Sat Mar 07 20:27:52 2009 +0000 +++ b/app/soc/templates/soc/mentor/manage.html Sat Mar 07 22:14:04 2009 +0000 @@ -18,6 +18,7 @@ {% endblock %} {% block manage %} +
{{ not_allowed_to_resign }}
Please select the appropriate action:
diff -r c5cfa7b3cdff -r 2d877bb10306 app/soc/templates/soc/org_admin/manage.html --- a/app/soc/templates/soc/org_admin/manage.html Sat Mar 07 20:27:52 2009 +0000 +++ b/app/soc/templates/soc/org_admin/manage.html Sat Mar 07 22:14:04 2009 +0000 @@ -18,6 +18,7 @@ {% endblock %} {% block manage %} +
{{ not_allowed_to_resign }}
Please select the appropriate action:
diff -r c5cfa7b3cdff -r 2d877bb10306 app/soc/templates/soc/student/manage.html --- a/app/soc/templates/soc/student/manage.html Sat Mar 07 20:27:52 2009 +0000 +++ b/app/soc/templates/soc/student/manage.html Sat Mar 07 22:14:04 2009 +0000 @@ -18,6 +18,7 @@ {% endblock %} {% block manage %} +
{{ not_allowed_to_resign }}
Please select the appropriate action:
diff -r c5cfa7b3cdff -r 2d877bb10306 app/soc/views/models/club_admin.py --- a/app/soc/views/models/club_admin.py Sat Mar 07 20:27:52 2009 +0000 +++ b/app/soc/views/models/club_admin.py Sat Mar 07 22:14:04 2009 +0000 @@ -76,6 +76,7 @@ new_params['extra_dynaexclude'] = ['agreed_to_tos'] + new_params['disallow_last_resign'] = False new_params['allow_invites'] = True new_params['show_in_roles_overview'] = False diff -r c5cfa7b3cdff -r 2d877bb10306 app/soc/views/models/host.py --- a/app/soc/views/models/host.py Sat Mar 07 20:27:52 2009 +0000 +++ b/app/soc/views/models/host.py Sat Mar 07 22:14:04 2009 +0000 @@ -88,6 +88,7 @@ 'clean_blog': cleaning.clean_url('blog'), 'clean_photo_url': cleaning.clean_url('photo_url')} + new_params['disallow_last_resign'] = False new_params['allow_invites'] = True new_params['show_in_roles_overview'] = True diff -r c5cfa7b3cdff -r 2d877bb10306 app/soc/views/models/org_admin.py --- a/app/soc/views/models/org_admin.py Sat Mar 07 20:27:52 2009 +0000 +++ b/app/soc/views/models/org_admin.py Sat Mar 07 22:14:04 2009 +0000 @@ -108,6 +108,7 @@ }, ] + new_params['disallow_last_resign'] = True new_params['allow_invites'] = True new_params['show_in_roles_overview'] = True diff -r c5cfa7b3cdff -r 2d877bb10306 app/soc/views/models/role.py --- a/app/soc/views/models/role.py Sat Mar 07 20:27:52 2009 +0000 +++ b/app/soc/views/models/role.py Sat Mar 07 22:14:04 2009 +0000 @@ -156,6 +156,8 @@ new_params['extra_dynaexclude'] = ['user', 'status', 'agreed_to_tos_on'] + new_params['disallow_last_resign'] = False + params = dicts.merge(params, new_params, sub_merge=True) super(View, self).__init__(params=params) @@ -434,12 +436,29 @@ resign = get_dict.get('resign') if resign == 'true': - # change the status of this role_entity to invalid - fields = {'status': 'invalid'} - logic.updateEntityProperties(role_entity, fields) + + if params.get('disallow_last_resign'): + # check if the current role is the last for this scope + fields = {'scope': role_entity.scope, + 'status': 'active'} + roles = logic.getForFields(fields, limit=2) + + # if there is more then one left we can safely resign + resign = len(roles) > 1 + else: + resign = True - # redirect to the roles listing - return http.HttpResponseRedirect(redirect) + if resign: + # change the status of this role_entity to invalid + fields = {'status': 'invalid'} + logic.updateEntityProperties(role_entity, fields) + + # redirect to the roles listing + return http.HttpResponseRedirect(redirect) + else: + # show error to the user + context['not_allowed_to_resign'] = ugettext("This user can't be " + "resigned, please make sure it's not the last %(name)s." % params) # set the appropriate context context['entity'] = role_entity