summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2014-11-07 09:27:56 -0600
committerDan McGee <dan@archlinux.org>2014-11-07 09:27:56 -0600
commitcd22bfd73b184888df13b194ecdf6e482b36c3fc (patch)
treeb906e8ac5f48071e9814da36cb7d0a9ff521ce55
parent9b5eb6ab383dcd090cdbf88a250ecdfd407c3beb (diff)
Master signing keys page improvements
* Don't show non-packagers * Don't hardcode group names in view code * Reduce number of database queries for all of the cross-signature developer name lookups Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--main/templatetags/pgp.py19
-rw-r--r--public/views.py37
-rw-r--r--templates/public/keys.html4
-rw-r--r--visualize/static/visualize.js5
4 files changed, 32 insertions, 33 deletions
diff --git a/main/templatetags/pgp.py b/main/templatetags/pgp.py
index 2417f688..455e8f9c 100644
--- a/main/templatetags/pgp.py
+++ b/main/templatetags/pgp.py
@@ -44,21 +44,14 @@ def pgp_key_link(key_id, link_text=None):
return '<a href="%s" title="PGP key search for %s">%s</a>' % values
-@cache_function(1741)
-def name_for_key(normalized):
- try:
- matching_key = DeveloperKey.objects.select_related(
- 'owner').get(key=normalized, owner_id__isnull=False)
- return matching_key.owner.get_full_name()
- except DeveloperKey.DoesNotExist:
- return None
-
-
@register.simple_tag
-def user_pgp_key_link(key_id):
+def user_pgp_key_link(dev_keys, key_id):
normalized = key_id[-16:]
- name = name_for_key(normalized)
- return pgp_key_link(key_id, name)
+ found = dev_keys.get(normalized, None)
+ if found:
+ return pgp_key_link(key_id, found.owner.get_full_name())
+ else:
+ return pgp_key_link(key_id, None)
@register.filter(needs_autoescape=True)
diff --git a/public/views.py b/public/views.py
index 118f067a..c0dae400 100644
--- a/public/views.py
+++ b/public/views.py
@@ -9,7 +9,7 @@ from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render
from django.views.decorators.cache import cache_control, cache_page
-from devel.models import MasterKey, PGPSignature, StaffGroup
+from devel.models import MasterKey, DeveloperKey, PGPSignature, StaffGroup, UserProfile
from main.models import Arch, Repo, Donor
from mirrors.models import MirrorUrl
from news.models import News
@@ -91,7 +91,9 @@ def feeds(request):
@cache_control(max_age=307)
def keys(request):
- users = User.objects.filter(is_active=True).select_related(
+ profile_ids = UserProfile.allowed_repos.through.objects.values('userprofile_id')
+ users = User.objects.filter(
+ is_active=True, userprofile__id__in=profile_ids).select_related(
'userprofile__pgp_key').order_by('first_name', 'last_name')
user_key_ids = frozenset(user.userprofile.pgp_key[-16:] for user in users
if user.userprofile.pgp_key)
@@ -114,34 +116,39 @@ def keys(request):
not_expired, revoked__isnull=True).values_list('signer', 'signee'))
restrict = Q(signer__in=user_key_ids) & Q(signee__in=user_key_ids)
- cross_signatures = PGPSignature.objects.filter(restrict,
+ cross_signatures = PGPSignature.objects.filter(
not_expired, revoked__isnull=True).order_by('created')
+ # filter in python so we aren't sending a crazy long query to the DB
+ cross_signatures = [s for s in cross_signatures
+ if s.signer in user_key_ids and s.signee in user_key_ids]
+
+ developer_keys = DeveloperKey.objects.select_related(
+ 'owner').filter(owner__isnull=False)
+ developer_keys = {key.key[-16:]: key for key in developer_keys}
context = {
'keys': master_keys,
'active_users': users,
'signatures': signatures,
'cross_signatures': cross_signatures,
+ 'developer_keys': developer_keys,
}
return render(request, 'public/keys.html', context)
@cache_page(1789)
def keys_json(request):
- node_list = []
+ profile_ids = UserProfile.allowed_repos.through.objects.values('userprofile_id')
+ users = User.objects.filter(
+ is_active=True, userprofile__id__in=profile_ids).select_related(
+ 'userprofile__pgp_key').order_by('first_name', 'last_name')
users = User.objects.filter(is_active=True).select_related('userprofile')
- node_list.extend({
- 'name': dev.get_full_name(),
- 'key': dev.userprofile.pgp_key,
- 'group': 'dev'
- } for dev in users.filter(groups__name='Developers'))
- node_list.extend({
- 'name': tu.get_full_name(),
- 'key': tu.userprofile.pgp_key,
- 'group': 'tu'
- } for tu in users.filter(groups__name='Trusted Users').exclude(
- groups__name='Developers'))
+ node_list = [{
+ 'name': user.get_full_name(),
+ 'key': user.userprofile.pgp_key,
+ 'group': 'packager'
+ } for user in users]
master_keys = MasterKey.objects.select_related('owner').filter(
revoked__isnull=True)
diff --git a/templates/public/keys.html b/templates/public/keys.html
index 54d52ab8..37d5b232 100644
--- a/templates/public/keys.html
+++ b/templates/public/keys.html
@@ -123,8 +123,8 @@
<tbody>
{% for sig in cross_signatures %}
<tr>
- <td>{% user_pgp_key_link sig.signer %}</td>
- <td>{% user_pgp_key_link sig.signee %}</td>
+ <td>{% user_pgp_key_link developer_keys sig.signer %}</td>
+ <td>{% user_pgp_key_link developer_keys sig.signee %}</td>
<td>{{ sig.created }}</td>
<td>{{ sig.expires|default:"" }}</td>
</tr>
diff --git a/visualize/static/visualize.js b/visualize/static/visualize.js
index 5004fe6c..5254c26b 100644
--- a/visualize/static/visualize.js
+++ b/visualize/static/visualize.js
@@ -175,7 +175,7 @@ function developer_keys(chart_id, data_url) {
}
});
jQuery.map(json.nodes, function(d, i) {
- if (d.group === "dev" || d.group === "tu") {
+ if (d.group === "packager") {
d.approved = d.master_sigs >= 3;
} else {
d.approved = null;
@@ -200,8 +200,7 @@ function developer_keys(chart_id, data_url) {
return r * 1.6 - 0.75;
case "cacert":
return r * 1.4 - 0.75;
- case "dev":
- case "tu":
+ case "packager":
default:
return r - 0.75;
}