Commit e57ed4b2 authored by Enrico Zini's avatar Enrico Zini
Browse files

Added is_active field to Fingerprint

parent e95e7534
......@@ -329,3 +329,16 @@ class DDUsernames(hk.Task):
self.IDENTIFIER, self.hk.link(p), p.status, new_username)
p.username = new_username
p.save(audit_author=self.hk.housekeeper.user, audit_notes="updated SSO username to @debian.org version")
class CheckOneActiveKeyPerPerson(hk.Task):
"""
Check that one does not have more than one open process at the current time
"""
DEPENDS = [MakeLink]
def run_main(self, stage):
from django.db.models import Count
for p in bmodels.Person.objects.filter(fprs__is_active=True) \
.annotate(num_fprs=Count("fprs")) \
.filter(num_fprs__gt=1):
log.warn("%s: %s has %d active keys", self.IDENTIFIER, self.hk.link(p), p.num_fprs)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('backend', '0004_remove_person_fpr'),
]
operations = [
migrations.AddField(
model_name='fingerprint',
name='is_active',
field=models.BooleanField(default=False, help_text='whether this key is curently in use'),
preserve_default=True,
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
def set_existing_fingerprints_as_active(apps, schema_editor):
Fingerprint = apps.get_model("backend", "Fingerprint")
Fingerprint.objects.update(is_active=True)
class Migration(migrations.Migration):
dependencies = [
('backend', '0005_fingerprint_is_active'),
]
operations = [
migrations.RunPython(set_existing_fingerprints_as_active),
]
......@@ -533,9 +533,10 @@ class Person(PermissionsMixin, models.Model):
"""
Return the current fingerprint for this Person
"""
# TODO: add a way to tell the current valid fingerprints from
# old/revoked ones
for f in self.fprs.all():
# If there is more than one active fields, return a random one. This
# should not happen, and a nightly maintenance task will warn if it
# happens.
for f in self.fprs.filter(is_active=True):
return f.fpr
return None
......@@ -777,8 +778,8 @@ class Fingerprint(models.Model):
db_table = "fingerprints"
user = models.ForeignKey(Person, related_name="fprs")
# OpenPGP fingerprint, NULL until one has been provided
fpr = FingerprintField("OpenPGP key fingerprint", max_length=40, unique=True)
fpr = FingerprintField(verbose_name="OpenPGP key fingerprint", max_length=40, unique=True)
is_active = models.BooleanField(default=False, help_text="whether this key is curently in use")
class PersonAuditLog(models.Model):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment