Skip to content

Commit 0f60531

Browse files
committed
Fix outputted groups in JS
- Legacy-Id: 3840
1 parent d16a5ea commit 0f60531

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

ietf/idtracker/templatetags/ietf_filters.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from django.template.defaultfilters import linebreaksbr, wordwrap, stringfilter, urlize, truncatewords_html
88
from django.template import resolve_variable
99
from django.utils.safestring import mark_safe, SafeData
10+
from django.utils import simplejson
1011
try:
1112
from email import utils as emailutils
1213
except ImportError:
@@ -449,6 +450,22 @@ def format_history_text(text):
449450
return mark_safe(u'<div class="snipped">%s<div class="showAll">[show all]</div><div><div style="display:none" class="full">%s</div>' % (snipped, full))
450451
return full
451452

453+
@register.filter
454+
def user_roles_json(user):
455+
roles = {}
456+
if user.is_authenticated():
457+
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
458+
from redesign.group.models import Role
459+
for r in Role.objects.filter(person__user=user).select_related(depth=1):
460+
if r.name_id == "secr" and r.group.acronym == "secretariat":
461+
roles["Secretariat"] = True
462+
elif r.name_id == "ad" and r.group.type_id == "area" and r.group.state_id == "active":
463+
roles["Area Director"] = roles["Area_Director"] = True
464+
else:
465+
for g in user.groups:
466+
roles[g.name] = True
467+
return mark_safe(simplejson.dumps(roles))
468+
452469
def _test():
453470
import doctest
454471
doctest.testmod()

ietf/templates/base.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3535

3636
{% endcomment %}
37+
{% load ietf_filters %}
3738
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3839
<head>
3940
<!-- v{{version_num}}, {{ revision_num }}, {{ revision_time }} -->
@@ -46,7 +47,7 @@
4647
{% block pagehead %}{% endblock %}
4748
<script type="text/javascript">
4849
IETF = {};
49-
IETF.user_groups = { {% for group in user.groups.all %}"{{group}}":true{% if not forloop.last %}, {%endif%}{%endfor%} };
50+
IETF.user_groups = {{ user|user_roles_json }};
5051
</script>
5152
{% ifnotequal server_mode "production" %}
5253
<link rel="icon" href="/images/ietf-dev-icon.bmp" />

0 commit comments

Comments
 (0)