diff mbox series

[1/3] models.Event: Add the user responsible for the event

Message ID 20191006225725.5388-2-johan@herland.net
State Superseded
Headers show
Series Store the user responsible for patch-related events | expand

Commit Message

Johan Herland Oct. 6, 2019, 10:57 p.m. UTC
This allows using the events as a kind of audit log, to see how a
patch came to its current state/delegate.

Cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Signed-off-by: Johan Herland <johan@herland.net>
---
 patchwork/migrations/0037_event_user.py | 23 +++++++++++++++++++++++
 patchwork/models.py                     |  4 ++++
 2 files changed, 27 insertions(+)
 create mode 100644 patchwork/migrations/0037_event_user.py

Comments

Stephen Finucane Oct. 7, 2019, 3:57 p.m. UTC | #1
On Mon, 2019-10-07 at 00:57 +0200, Johan Herland wrote:
> This allows using the events as a kind of audit log, to see how a
> patch came to its current state/delegate.
> 
> Cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Signed-off-by: Johan Herland <johan@herland.net>

This looks good, though the second patch in the series needs work so
I'm going to hold off applying this quite yet.

Reviewed-by: Stephen Finucane <stephen@that.guru>

Stephen

> ---
>  patchwork/migrations/0037_event_user.py | 23 +++++++++++++++++++++++
>  patchwork/models.py                     |  4 ++++
>  2 files changed, 27 insertions(+)
>  create mode 100644 patchwork/migrations/0037_event_user.py
> 
> diff --git a/patchwork/migrations/0037_event_user.py b/patchwork/migrations/0037_event_user.py
> new file mode 100644
> index 0000000..3a6e228
> --- /dev/null
> +++ b/patchwork/migrations/0037_event_user.py
> @@ -0,0 +1,23 @@
> +# -*- coding: utf-8 -*-
> +# Generated by Django 1.11.20 on 2019-09-28 21:35
> +from __future__ import unicode_literals
> +
> +from django.conf import settings
> +from django.db import migrations, models
> +import django.db.models.deletion
> +
> +
> +class Migration(migrations.Migration):
> +
> +    dependencies = [
> +        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
> +        ('patchwork', '0036_project_commit_url_format'),
> +    ]
> +
> +    operations = [
> +        migrations.AddField(
> +            model_name='event',
> +            name='user',
> +            field=models.ForeignKey(blank=True, help_text=b'The user that created this event.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL),

Yeah, setting it to NULL is probably the correct action in this
situation.

> +        ),
> +    ]
> diff --git a/patchwork/models.py b/patchwork/models.py
> index c198bc2..3d4e222 100644
> --- a/patchwork/models.py
> +++ b/patchwork/models.py
> @@ -944,6 +944,10 @@ class Event(models.Model):
>      date = models.DateTimeField(
>          default=datetime.datetime.utcnow,
>          help_text='The time this event was created.')
> +    user = models.ForeignKey(
> +        User, related_name='+', null=True, blank=True,
> +        on_delete=models.SET_NULL,
> +        help_text='The user that created this event.')
>  
>      # event object
>
Johan Herland Oct. 7, 2019, 5:14 p.m. UTC | #2
On Mon, Oct 7, 2019 at 5:57 PM Stephen Finucane <stephen@that.guru> wrote:
> On Mon, 2019-10-07 at 00:57 +0200, Johan Herland wrote:
> > This allows using the events as a kind of audit log, to see how a
> > patch came to its current state/delegate.
> >
> > Cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > Signed-off-by: Johan Herland <johan@herland.net>
>
> This looks good, though the second patch in the series needs work so
> I'm going to hold off applying this quite yet.
>
> Reviewed-by: Stephen Finucane <stephen@that.guru>

Thanks. I like your name 'actor' better, though, so I'll re-roll this
with that change.

> > +    operations = [
> > +        migrations.AddField(
> > +            model_name='event',
> > +            name='user',
> > +            field=models.ForeignKey(blank=True, help_text=b'The user that created this event.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL),
>
> Yeah, setting it to NULL is probably the correct action in this
> situation.

Yes, I think so. From looking around models.py, I got the impression
that .deletion.CASCADE was much more common (maybe even overused?), so
I was not sure, but I do think it's more appropriate in this case, at
least.

Thanks for the review!

...Johan
diff mbox series

Patch

diff --git a/patchwork/migrations/0037_event_user.py b/patchwork/migrations/0037_event_user.py
new file mode 100644
index 0000000..3a6e228
--- /dev/null
+++ b/patchwork/migrations/0037_event_user.py
@@ -0,0 +1,23 @@ 
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.20 on 2019-09-28 21:35
+from __future__ import unicode_literals
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+        ('patchwork', '0036_project_commit_url_format'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='event',
+            name='user',
+            field=models.ForeignKey(blank=True, help_text=b'The user that created this event.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL),
+        ),
+    ]
diff --git a/patchwork/models.py b/patchwork/models.py
index c198bc2..3d4e222 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -944,6 +944,10 @@  class Event(models.Model):
     date = models.DateTimeField(
         default=datetime.datetime.utcnow,
         help_text='The time this event was created.')
+    user = models.ForeignKey(
+        User, related_name='+', null=True, blank=True,
+        on_delete=models.SET_NULL,
+        help_text='The user that created this event.')
 
     # event object