Important roles can now not resign if they are the last in their group.
authorLennard de Rijk <ljvderijk@gmail.com>
Sat, 07 Mar 2009 22:14:04 +0000
changeset 1730 2d877bb10306
parent 1729 c5cfa7b3cdff
child 1731 254375a57d62
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
app/soc/templates/soc/club_admin/manage.html
app/soc/templates/soc/club_member/manage.html
app/soc/templates/soc/mentor/manage.html
app/soc/templates/soc/org_admin/manage.html
app/soc/templates/soc/student/manage.html
app/soc/views/models/club_admin.py
app/soc/views/models/host.py
app/soc/views/models/org_admin.py
app/soc/views/models/role.py
--- 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 %}
+<div class="error">{{ not_allowed_to_resign }}</div>
 <tr>
   <td>
     Please select the appropriate action:</br>
--- 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 %}
+<div class="error">{{ not_allowed_to_resign }}</div>
 <tr>
   <td>
     Please select the appropriate action:</br>
--- 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 %}
+<div class="error">{{ not_allowed_to_resign }}</div>
 <tr>
   <td>
     Please select the appropriate action:</br>
--- 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 %}
+<div class="error">{{ not_allowed_to_resign }}</div>
 <tr>
   <td>
     Please select the appropriate action:</br>
--- 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 %}
+<div class="error">{{ not_allowed_to_resign }}</div>
 <tr>
   <td>
     Please select the appropriate action:</br>
--- 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
 
--- 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
 
--- 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
 
--- 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