From a59331dd632074e2958fcd6cd3838359dff37902 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Wed, 10 May 2017 13:05:51 +0000 Subject: [PATCH] Align the roles edit buttons on a group's about page with the roles that the group edit GroupForm will accept. Avoids edit forms without any fields and some server 500 errors. - Legacy-Id: 13296 --- ietf/group/utils.py | 8 ++++++++ ietf/group/views.py | 3 ++- ietf/group/views_edit.py | 10 ++-------- ietf/templates/group/group_about.html | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ietf/group/utils.py b/ietf/group/utils.py index 3a4f195ad..a5efa69d6 100644 --- a/ietf/group/utils.py +++ b/ietf/group/utils.py @@ -242,3 +242,11 @@ def construct_group_menu_context(request, group, selected, group_type, others): d.update(others) return d + + +def roles_for_group_type(group_type): + roles = ["chair", "secr", "techadv", "delegate", ] + if group_type == "dir": + roles.append("reviewer") + return roles + diff --git a/ietf/group/views.py b/ietf/group/views.py index 064b40e4f..9a2630089 100644 --- a/ietf/group/views.py +++ b/ietf/group/views.py @@ -59,7 +59,7 @@ from ietf.group.models import Group, Role, ChangeStateGroupEvent from ietf.name.models import GroupTypeName from ietf.group.utils import (get_charter_text, can_manage_group_type, milestone_reviewer_for_group_type, can_provide_status_update, - can_manage_materials, get_group_or_404, + can_manage_materials, get_group_or_404, roles_for_group_type, construct_group_menu_context, get_group_materials) from ietf.community.utils import docs_tracked_by_community_list from ietf.community.models import CommunityList, EmailSubscription @@ -443,6 +443,7 @@ def group_about(request, acronym, group_type=None): "can_provide_status_update": can_provide_update, "status_update": status_update, "charter_submit_url": charter_submit_url, + "editable_roles": roles_for_group_type(group_type), })) def all_status(request): diff --git a/ietf/group/views_edit.py b/ietf/group/views_edit.py index 18416e261..1ffa6f0f1 100644 --- a/ietf/group/views_edit.py +++ b/ietf/group/views_edit.py @@ -16,8 +16,8 @@ from ietf.doc.utils import get_tags_for_stream_id from ietf.doc.utils_charter import charter_name_for_group from ietf.group.models import ( Group, Role, GroupEvent, GroupHistory, GroupStateName, GroupStateTransitions, GroupTypeName, GroupURL, ChangeStateGroupEvent ) -from ietf.group.utils import save_group_in_history, can_manage_group, can_manage_group_type -from ietf.group.utils import get_group_or_404, setup_default_community_list_for_group +from ietf.group.utils import (save_group_in_history, can_manage_group, can_manage_group_type, + get_group_or_404, setup_default_community_list_for_group, roles_for_group_type, ) from ietf.ietfauth.utils import has_role from ietf.person.fields import SearchableEmailsField from ietf.person.models import Person, Email @@ -28,12 +28,6 @@ from ietf.utils.text import strip_suffix MAX_GROUP_DELEGATES = 3 -def roles_for_group_type(group_type): - roles = ["chair", "secr", "techadv", "delegate"] - if group_type == "dir": - roles.append("reviewer") - return roles - class GroupForm(forms.Form): name = forms.CharField(max_length=80, label="Name", required=True) acronym = forms.CharField(max_length=40, label="Acronym", required=True) diff --git a/ietf/templates/group/group_about.html b/ietf/templates/group/group_about.html index c9e91548b..ac54312e2 100644 --- a/ietf/templates/group/group_about.html +++ b/ietf/templates/group/group_about.html @@ -143,7 +143,7 @@ {% endif %} {{ label }} - {% if can_edit_group and not slug == "ad" %} + {% if can_edit_group and slug in editable_roles %} Edit {% endif %}