]> git.ipfire.org Git - thirdparty/patchwork.git/log
thirdparty/patchwork.git
5 years agorenovate: Configure requirement file locations renovate/configure 355/head
Stephen Finucane [Wed, 15 Apr 2020 10:46:56 +0000 (11:46 +0100)] 
renovate: Configure requirement file locations

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agochore(deps): add renovate.json
Renovate Bot [Tue, 14 Apr 2020 22:35:19 +0000 (22:35 +0000)] 
chore(deps): add renovate.json

5 years agotravis: Resolve warnings, info messages from Travis
Stephen Finucane [Sat, 18 Apr 2020 12:21:13 +0000 (13:21 +0100)] 
travis: Resolve warnings, info messages from Travis

The following were reported by Travis' build config validation:

- root: deprecated key 'sudo' (The key `sudo` has no effect anymore.)
- env: key 'matrix' is an alias for 'jobs', using 'jobs'
- root: key 'matrix' is an alias for 'jobs', using 'jobs'
- root: missing 'os', using the default 'linux'

Resolve all of the above.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoparser: don't trigger database IntegrityErrors on duplicate coverletters
Jeremy Kerr [Thu, 16 Apr 2020 01:29:28 +0000 (09:29 +0800)] 
parser: don't trigger database IntegrityErrors on duplicate coverletters

As we've done for the Patch and Comment models, this change prevents
database errors from duplicate CoverLetters.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Stephen Finucane <stephen@that.guru>
[stephenfin: Add release note]

5 years agoparser: don't trigger database IntegrityErrors on duplicate comments
Jeremy Kerr [Thu, 16 Apr 2020 01:29:27 +0000 (09:29 +0800)] 
parser: don't trigger database IntegrityErrors on duplicate comments

As we've done for the Patch model, this change prevents database errors
from duplicate Comments.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Reviewed-by: Stephen Finucane <stephen@that.guru>
5 years agoparser: prevent IntegrityErrors
Jeremy Kerr [Thu, 16 Apr 2020 01:29:26 +0000 (09:29 +0800)] 
parser: prevent IntegrityErrors

Currently, the parser relies on causing (and catching) IntegrityErrors
on patch insert to catch duplicate (msgid,project) mails.

This change performs an atomic select -> insert instead.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Stephen Finucane <stephen@that.guru>
[stephenfin: Remove 'expectedFailure' marker again]

5 years agotests: ensure we don't see database errors during duplicate insert
Jeremy Kerr [Thu, 16 Apr 2020 01:29:25 +0000 (09:29 +0800)] 
tests: ensure we don't see database errors during duplicate insert

Currently, the parser causes IntegrityErrors while inserting duplicate
patches; these tend to pollute database logs.

This change adds a check, which currently fails, to ensure we do not
cause errors during a duplicate patch parse.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Stephen Finucane <stephen@that.guru>
[stephenfin: Add 'expectedFailure' marker to keep all tests green]

5 years agotests: Add duplicate mail test
Jeremy Kerr [Thu, 16 Apr 2020 01:29:24 +0000 (09:29 +0800)] 
tests: Add duplicate mail test

Test that we get the correct DuplicateMailError from parsing the same
mail twice.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Reviewed-by: Stephen Finucane <stephen@that.guru>
5 years agoparser: Don't crash when From: is list email but has weird mangle format
Andrew Donnellan [Wed, 15 Apr 2020 09:06:56 +0000 (19:06 +1000)] 
parser: Don't crash when From: is list email but has weird mangle format

get_original_sender() tries to demangle DMARC-mangled From headers, in
the case where the email's From address is the list address. It knows how
to handle Google Groups and Mailman style mangling, where the original
submitter's name will be turned into e.g. "Andrew Donnellan via
linuxppc-dev".

If an email has the From header set to the list address but has a name that
doesn't include " via ", we'll throw an exception because stripped_name
hasn't been set. Sometimes this is because the list name is seemingly
empty, resulting in a mangled name like "Andrew Donnellan via"
without the space after "via" that we detect. Handle this as well as we can
instead, and add a test.

Fixes: 8279a84238c10 ("parser: Unmangle From: headers that have been mangled for DMARC purposes")
Reported-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Update sphinxcontrib-openapi
Stephen Finucane [Wed, 15 Apr 2020 15:52:25 +0000 (16:52 +0100)] 
docs: Update sphinxcontrib-openapi

No changes necessary, thankfully, though there is a feature gap here
that we will need 0.7.0 to close [1] :(

[1] https://github.com/sphinx-contrib/openapi/pull/87

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agotests: Switch to openapi-core 0.13.x
Stephen Finucane [Wed, 15 Apr 2020 15:52:08 +0000 (16:52 +0100)] 
tests: Switch to openapi-core 0.13.x

We've done the necessary work here already so this is a relatively easy
switchover. However, we do have to work around an issue whereby the
first possible matching route is used rather than the best one [1]. In
addition, we have to install from master since there are fixes missing
from the latest release, 0.13.3. Hopefully both issues will be resolved
in a future release.

[1] https://github.com/p1c2u/openapi-core/issues/226

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agotests: Drop Django 1.x support
Stephen Finucane [Wed, 15 Apr 2020 15:44:32 +0000 (16:44 +0100)] 
tests: Drop Django 1.x support

openapi-core 0.13.x has added support for Django validation. Before we
migrate to that version and presumably remove most of this code, remove
the stuff that is *definitely* dead.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Resolve issues with 'relations'
Stephen Finucane [Thu, 16 Apr 2020 13:03:54 +0000 (14:03 +0100)] 
docs: Resolve issues with 'relations'

Two issues here:

- 'PATCH /patches/{id}' and 'PUT /patches/{id}' expect a list of
  integers on the 'related' field - not strings
- 'GET /patches' and 'GET /patches/{id}' return a list of embedded patch
  objects on the 'related' field - not strings

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Resolve issues with 'events'
Stephen Finucane [Thu, 16 Apr 2020 12:45:28 +0000 (13:45 +0100)] 
docs: Resolve issues with 'events'

Four things to change here:

- The response is any array that can contain any type of event, not one
  of them.
- The 'actor' field is nullable.
- The 'cover' field of the 'cover-created' event is an embedded cover
  letter, not a string.
- The specifications for the 'current_delegate' and 'previous_delegate'
  fields of the 'patch-delegated' field were apparently invalid.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Resolve issues with 'comments'
Stephen Finucane [Thu, 16 Apr 2020 10:48:29 +0000 (11:48 +0100)] 
docs: Resolve issues with 'comments'

Each header in the 'headers' field can be either a string or a list
value.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Resolve issues with 'patches'
Stephen Finucane [Thu, 16 Apr 2020 09:02:36 +0000 (10:02 +0100)] 
docs: Resolve issues with 'patches'

Two issues:

- Errors are reported as a mapping of the field name to an array of
  errors, not a string.
- We were attempting to validate an invalid request.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Resolve issues with 'covers'
Stephen Finucane [Wed, 15 Apr 2020 23:51:17 +0000 (00:51 +0100)] 
docs: Resolve issues with 'covers'

Two issues to correct:

- Each header in the 'headers' field can be either a string or a list
  value.
- We state that the 'content' field will always have content but our
  tests were configuring otherwise.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Resolve issues with 'bundles'
Stephen Finucane [Wed, 15 Apr 2020 23:47:26 +0000 (00:47 +0100)] 
docs: Resolve issues with 'bundles'

Errors are reported as a mapping of the field name to an array of
errors, not a string.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Resolve issues with 'projects'
Stephen Finucane [Wed, 15 Apr 2020 23:43:40 +0000 (00:43 +0100)] 
docs: Resolve issues with 'projects'

Two issues here:

- The ID in '/projects/{id}' can be either an integer or a string.
- We were attempting to validate an invalid request.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Resolve issues with 'patches'
Stephen Finucane [Wed, 15 Apr 2020 22:36:59 +0000 (23:36 +0100)] 
docs: Resolve issues with 'patches'

Four issues to resolve:

- The 'tags' field is a key-value mapping, not an array.
- Each header in the 'headers' field can be either a string or a list
  value.
- Errors are reported as a mapping of the field name to an array of
  errors, not a string.
- The security type information isn't complete and doesn't account for
  security types. Skip it for now.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Move common path parameters to parent
Stephen Finucane [Thu, 16 Apr 2020 10:43:04 +0000 (11:43 +0100)] 
docs: Move common path parameters to parent

Turns out you don't have to nest common elements under individual routes
[1]. Less duplication and more sensible docs = winning.

[1] https://swagger.io/specification/#pathItemObject

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Make embedded fields nullable by default
Stephen Finucane [Wed, 15 Apr 2020 22:37:17 +0000 (23:37 +0100)] 
docs: Make embedded fields nullable by default

As discussed at [1], "subtypes can add restrictions, but they cannot
relax restrictions that are already in place." These fields need to be
marked nullable and then "subclassed" to set non-nullability if
required.

[1] https://github.com/OAI/OpenAPI-Specification/issues/1368

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Add schema validation to 'generate-schemas' tool
Stephen Finucane [Sat, 18 Apr 2020 10:49:38 +0000 (11:49 +0100)] 
docs: Add schema validation to 'generate-schemas' tool

Just to make sure we're not generating garbage.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agorequirements: Remove final pyup markers
Stephen Finucane [Wed, 15 Apr 2020 10:59:11 +0000 (11:59 +0100)] 
requirements: Remove final pyup markers

Now that pyup properly supports compatible ranges [1], it's time to
remove these markers.

[1] https://github.com/pyupio/pyup/pull/367

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoREST: Allow update of bundle without patches
Stephen Finucane [Fri, 17 Apr 2020 22:07:27 +0000 (23:07 +0100)] 
REST: Allow update of bundle without patches

Presently, when updating a patch we assume that patches are provided.
This isn't necessary - you might just want to make it public - and isn't
enforced by the API itself. However, because we make this assumption, we
see a HTTP 500. Resolve the issue and add tests to prevent a regression.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Resolves: #357

5 years agoapi: allow filtering patches and covers by msgid
Daniel Axtens [Tue, 14 Apr 2020 05:34:40 +0000 (15:34 +1000)] 
api: allow filtering patches and covers by msgid

In the process of fixing the previous bug, I realised that:

 a) /api/patches/msgid is a perfectly reasonable thing to attempt
 b) We have no way of finding a patch by message id in the API

We can't actualy make /api/patches/msgid work because it may not
be unique, but we can add a filter.

I'm shoehorning this into stable/2.2, even though it's technically
an API change: it's minor, not incompatible and in hindsight a
glaring hole.

Cc: Michael Ellerman <mpe@ellerman.id.au>
Tested-by: Jeremy Kerr <jk@ozlabs.org>
Reviewed-by: Andrew Donnellan <ajd@linux.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
Signed-off-by: Daniel Axtens <dja@axtens.net>
5 years agoapi: do not fetch every patch in a patch detail view 404
Daniel Axtens [Tue, 14 Apr 2020 04:26:58 +0000 (14:26 +1000)] 
api: do not fetch every patch in a patch detail view 404

mpe and jk and sfr found that the OzLabs server was melting due
to some queries downloading every patch.

Turns out if you 404 the patch detail view in the API, d-r-f attempts
to render a listbox with every single patch to fill in the 'related'
field. The bundle API also has a similar field.

Replace the multiple selection box with a text field. You can still
(AIUI) populate the relevant patch IDs manually.

This is the recommended approach per
https://www.django-rest-framework.org/topics/browsable-api/#handling-choicefield-with-large-numbers-of-items

Reported-by: Jeremy Kerr <jk@ozlabs.org>
Reported-by: Michael Ellerman <mpe@ellerman.id.au>
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Tested-by: Jeremy Kerr <jk@ozlabs.org>
Server-no-longer-on-fire-by: Jeremy Kerr <jk@ozlabs.org>
Reviewed-by: Stephen Finucane <stephen@that.guru>
Signed-off-by: Daniel Axtens <dja@axtens.net>
5 years agopre-commit: Use Python 3 for everything
Stephen Finucane [Fri, 10 Apr 2020 16:33:26 +0000 (17:33 +0100)] 
pre-commit: Use Python 3 for everything

This lets us use e.g. f-strings. We also bump the version of the default
pre-commit lib and migrate to the upstream flake8 plugin, since the old
one is now deprecated.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agolib/sql: Update grant script for recent schema changes
Jeremy Kerr [Tue, 14 Apr 2020 05:57:53 +0000 (13:57 +0800)] 
lib/sql: Update grant script for recent schema changes

This change fixes a few omissions in the grant scripts:

- patchrelation is missing from both mysql and postgres scripts; it's
  only needed for web user access.

- event is missing from the web grants on postgres, and the mail grants
  on mysql.

Tested on postgres only.

Fixes: 27c2acf56c ("models, templates: Add patch relations")
Fixes: 34e3c9c493 ("sql: Update 'grant-all.mysql' script with missing tables")
Fixes: 234bc7c316 ("lib/sql: fix permissions for v2.0.0 on postgres")
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Daniel Axtens <dja@axtens.net>
5 years agoAdditional Python 2.7 cleanups
Stephen Finucane [Thu, 9 Apr 2020 17:00:57 +0000 (18:00 +0100)] 
Additional Python 2.7 cleanups

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agotox: Remove quotes around posargs
Stephen Finucane [Thu, 9 Apr 2020 16:35:56 +0000 (17:35 +0100)] 
tox: Remove quotes around posargs

This was preventing us from doing e.g.:

  tox -e py36-django30 -- patchwork -v 2

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agotests: Close XML-RPC client when done
Stephen Finucane [Thu, 9 Apr 2020 09:46:13 +0000 (10:46 +0100)] 
tests: Close XML-RPC client when done

This resolves the following irritating warnings that were popping up on
Python 3.7 and 3.8 and were silenced on 3.6:

  /usr/lib/python3.7/unittest/suite.py:107: ResourceWarning: unclosed <socket.socket ...>

Note that we need to use a subclass because the 'ServerProxy' class,
rather annoyingly, does not expose a 'close()' method. Instead, you're
expected to use a context manager, which isn't useful from the context
of a 'setUp' call. We could call '__enter__' and '__exit__' manually but
this seems cleaner. Also note that 'Server' was an alias of
'ServerProxy' [1], and we're taking the opportunity to switch here.

[1] https://docs.python.org/3/library/xmlrpc.client.html#xmlrpc.client.ServerProxy

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoRemove __future__ imports
Stephen Finucane [Wed, 8 Apr 2020 23:10:27 +0000 (00:10 +0100)] 
Remove __future__ imports

All of these are defaults in Python 3 [1].

[1] https://docs.python.org/3.6/library/__future__.html

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoTemporarily disable django-dbbackup
Stephen Finucane [Thu, 9 Apr 2020 09:06:29 +0000 (10:06 +0100)] 
Temporarily disable django-dbbackup

This does not support Django 3.0 yet [1].

[1] https://github.com/django-dbbackup/django-dbbackup/issues/314

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agomigrations: Add the Python 3 patch
Stephen Finucane [Wed, 8 Apr 2020 22:57:31 +0000 (23:57 +0100)] 
migrations: Add the Python 3 patch

Django has wanted this for a long time. It doesn't seem to do anything
but it keeps Django happy so...

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agorequirements: Bump django-debug-toolbar to 2.2
Stephen Finucane [Wed, 8 Apr 2020 22:46:48 +0000 (23:46 +0100)] 
requirements: Bump django-debug-toolbar to 2.2

This version formally includes support for Django 3.0 [1].

The default installed version of Django is bumped to 3.0.

[1] https://django-debug-toolbar.readthedocs.io/en/latest/changes.html

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoREST: Resolve warnings with DRF >= 3.11
Stephen Finucane [Wed, 8 Apr 2020 22:13:20 +0000 (23:13 +0100)] 
REST: Resolve warnings with DRF >= 3.11

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoAdd Django 3.0 support
Andrew Donnellan [Wed, 8 Apr 2020 21:47:54 +0000 (22:47 +0100)] 
Add Django 3.0 support

Add the latest version of Django.

Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes: #311
5 years agotests: Fix escaping in bundle tests on Django 3.0
Andrew Donnellan [Wed, 8 Apr 2020 21:52:26 +0000 (22:52 +0100)] 
tests: Fix escaping in bundle tests on Django 3.0

Django 3.0 switches to using Python 3's built-in HTML escaper, which
prefers to escape entities using hex rather than decimal.

Some of our tests check rendered HTML output against pre-escaped
strings, and fail because '&#39;' is now '&#x27;'.

Fix this by using the escape function so we get consistent escaping no
matter which Django version.

Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
5 years agodocker: Remove Python 2.7, 3.5
Stephen Finucane [Wed, 8 Apr 2020 22:02:33 +0000 (23:02 +0100)] 
docker: Remove Python 2.7, 3.5

We no longer need these dependencies.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Remove references to Python 2.7
Stephen Finucane [Wed, 8 Apr 2020 21:41:30 +0000 (22:41 +0100)] 
docs: Remove references to Python 2.7

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoClean up references to Python 2.7, Python 3.5
Daniel Axtens [Fri, 30 Aug 2019 07:36:43 +0000 (17:36 +1000)] 
Clean up references to Python 2.7, Python 3.5

Both this and the version of Django we were running with it are EOL
upstream. It's time to drop them.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoRemove unnecessary compat wrappers
Stephen Finucane [Wed, 8 Apr 2020 21:28:29 +0000 (22:28 +0100)] 
Remove unnecessary compat wrappers

This will probably need to be reintroduced with future Django versions,
but for now it's gone.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoReplace references to Django 1.11 docs
Stephen Finucane [Wed, 8 Apr 2020 21:21:59 +0000 (22:21 +0100)] 
Replace references to Django 1.11 docs

This is a straight forward swap, thankfully. Django 2.2 is chosen as
it's the latest LTS.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agotox: Drop support for Django < 2.2, Python < 3.6
Stephen Finucane [Wed, 8 Apr 2020 20:57:59 +0000 (21:57 +0100)] 
tox: Drop support for Django < 2.2, Python < 3.6

Each of these versions of Django is now EOL, and Python 3.5 will be EOL
by time we release the next version. Drop it.

The Python 2.7 cleanup will be done separately.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoRevert "pyenv: also install requirements for python2"
Stephen Finucane [Wed, 8 Apr 2020 21:58:11 +0000 (22:58 +0100)] 
Revert "pyenv: also install requirements for python2"

This reverts commit 5b904f91c4cab1ff3f8460c9d4ed920a990c8db3. It is no
longer necessary now that we're dropping Python 2.7 support.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Reference Patchwork 2.2 tarballs
Stephen Finucane [Wed, 8 Apr 2020 22:27:52 +0000 (23:27 +0100)] 
docs: Reference Patchwork 2.2 tarballs

This is what users will want right now.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Remove 'earliest_version' config
Stephen Finucane [Sun, 5 Apr 2020 20:22:28 +0000 (21:22 +0100)] 
docs: Remove 'earliest_version' config

This is unnecessary and was disabling reno's built-in ability to detect
a base branch.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agotox: Pass positional arguments to 'docs' job
Stephen Finucane [Sun, 5 Apr 2020 19:43:18 +0000 (20:43 +0100)] 
tox: Pass positional arguments to 'docs' job

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Update reno for stable/2.2
Stephen Finucane [Sun, 5 Apr 2020 18:49:42 +0000 (19:49 +0100)] 
docs: Update reno for stable/2.2

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoPost-release version bump
Stephen Finucane [Sun, 5 Apr 2020 18:46:58 +0000 (19:46 +0100)] 
Post-release version bump

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoRelease 2.2.0 v2.2.0
Stephen Finucane [Sun, 5 Apr 2020 18:43:32 +0000 (19:43 +0100)] 
Release 2.2.0

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agotrivial: Feed 'patchwork.migrations' through black
Stephen Finucane [Thu, 19 Mar 2020 12:34:03 +0000 (12:34 +0000)] 
trivial: Feed 'patchwork.migrations' through black

Include migrations in the flake8 checks, which should catch some simple
undefined variables errors.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoREST: Add release note for faster queries
Daniel Axtens [Tue, 17 Mar 2020 13:59:16 +0000 (00:59 +1100)] 
REST: Add release note for faster queries

Didn't quite seem like it fit anywhere else in the series. I want
the release note mostly because I hope to backport this to stable.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Stephen Finucane <stephen@that.guru>
5 years agoREST: extend performance improvements to other parts of the API
Daniel Axtens [Tue, 17 Mar 2020 13:59:15 +0000 (00:59 +1100)] 
REST: extend performance improvements to other parts of the API

We can trivially extend what we've just done to other parts of the API.

I haven't done much by way of benchmark but we're seeing multiple 'x's
pretty much across the board when filtering.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Stephen Finucane <stephen@that.guru>
5 years agoREST: fix patch listing query
Daniel Axtens [Tue, 17 Mar 2020 13:59:14 +0000 (00:59 +1100)] 
REST: fix patch listing query

The patch listing query is punishingly slow under even very simple
filters.

The new data model in 3.0 will help _a lot_, so this is a simple fix: I
did try indexes but haven't got really deeply into the weeds of what we can do
with them.

Move a number of things from select_related to prefetch_related: we trade off
one big, inefficient query for a slightly larger number of significantly more
efficient queries.

On my laptop with 2 copies of the canonical kernel team list loaded into the
database, and considering only the API view (the JSON view is always faster)
with warm caches and considering the entire set of SQL queries:

 - /api/patches/?project=1
    ~1.4-1.5s -> <100ms, something like 14x better

 - /api/patches/?project=1&since=2010-11-01T00:00:00
    ~1.7-1.8s -> <560ms, something like 3x better (now dominated by the
                         counting query only invoked on the HTML API view,
                         not the pure JSON API view.)

The things I moved:

 * project: this was generating SQL that looked like:

   INNER JOIN `patchwork_project` T5
    ON (`patchwork_submission`.`project_id` = T5.`id`)

   This is correct but we've already had to join the patchwork_submission
   table and perhaps as a result it seems to be inefficient.

 * series__project: Likewise we've already had to join the series table,
   doing another join is possibly why it is inefficient.

 * delegate: I do not know why this was tanking performance. I think it
   might relate to the strategy mysql was using.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Stephen Finucane <stephen@that.guru>
5 years agoREST: massively improve the patch counting query under filters
Daniel Axtens [Tue, 17 Mar 2020 13:59:13 +0000 (00:59 +1100)] 
REST: massively improve the patch counting query under filters

The DRF web view counts the patches as part of pagination.

The query it uses is a disaster zone:

  SELECT Count(*) FROM (
    SELECT DISTINCT
      `patchwork_submission`.`id`           AS Col1,
      `patchwork_submission`.`msgid`        AS Col2,
      `patchwork_submission`.`date`         AS Col3,
      `patchwork_submission`.`submitter_id` AS Col4,
      `patchwork_submission`.`project_id`   AS Col5,
      `patchwork_submission`.`name`         AS Col6,
      `patchwork_patch`.`submission_ptr_id` AS Col7,
      `patchwork_patch`.`commit_ref`        AS Col8,
      `patchwork_patch`.`pull_url`          AS Col9,
      `patchwork_patch`.`delegate_id`       AS Col10,
      `patchwork_patch`.`state_id`          AS Col11,
      `patchwork_patch`.`archived`          AS Col12,
      `patchwork_patch`.`hash`              AS Col13,
      `patchwork_patch`.`patch_project_id`  AS Col14,
      `patchwork_patch`.`series_id`         AS Col15,
      `patchwork_patch`.`number`            AS Col16,
      `patchwork_patch`.`related_id`        AS Col17
    FROM `patchwork_patch`
    INNER JOIN `patchwork_submission`
      ON (`patchwork_patch`.`submission_ptr_id`=`patchwork_submission`.`id`)
    WHERE `patchwork_submission`.`project_id`=1
  )

This is because django-filters adds a DISTINCT qualifier on a
ModelMultiChoiceFilter by default. I guess it makes sense and they do a
decent job of justifying it, but it causes the count to be made with
this awful subquery. (The justification is that they don't know if you're
filtering on a to-many relationship, in which case there could be
duplicate values that need to be removed.)

While fixing that, we can also tell the filter to filter on patch_project
rather than submission's project, which allows us in some cases to avoid
the join entirely.

The resultant SQL is beautiful when filtering by project only:

  SELECT COUNT(*) AS `__count`
  FROM `patchwork_patch`
  WHERE `patchwork_patch`.`patch_project_id` = 1

On my test setup (2x canonical kernel mailing list in the db, warm cache,
my laptop) this query goes from >1s to ~10ms, a ~100x improvement.

If we filter by project and date the query is still nice, but still also
very slow:

  SELECT COUNT(*) AS `__count`
  FROM `patchwork_patch`
  INNER JOIN `patchwork_submission`
    ON (`patchwork_patch`.`submission_ptr_id`=`patchwork_submission`.`id`)
  WHERE (`patchwork_patch`.`patch_project_id`=1 AND `patchwork_submission`.`date`>='2010-11-01 00:00:00')

This us from ~1.3s to a bit under 400ms - still not ideal, but I'll take
the 3x improvement!

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Stephen Finucane <stephen@that.guru>
5 years agoPatchwork v2.2.0-rc2 v2.2.0-rc2
Stephen Finucane [Thu, 27 Feb 2020 23:36:55 +0000 (23:36 +0000)] 
Patchwork v2.2.0-rc2

Signed-off-by: Stephen Finucane <stephen@that.guru>
Signed-off-by: Daniel Axtens <dja@axtens.net>
5 years agoREST: Add patch relations
Mete Polat [Thu, 27 Feb 2020 23:29:32 +0000 (23:29 +0000)] 
REST: Add patch relations

View relations and add/update/delete them as a maintainer. Maintainers
can only create relations of patches which are part of a project they
maintain. Because this is a writable many-many nested relationship, it
behaves a little unusually. In short:

- All operations use PATCH to the 'related' field of a patch

- To relate a patch to another patch, say 7 to 19, either:

    PATCH /api/patch/7  related := [19]
    PATCH /api/patch/19 related := [7]

- To delete a patch from a relation, say 1, 21 and 42 are related but we
  only want it to be 1 and 42:

    PATCH /api/patch/21 related := []

  * You _cannot_ remove a patch from a relation by patching another
    patch in the relation: I'm trying to avoid read-modify-write loops.

  * Relations that would be left with just 1 patch are deleted. This is
    only ensured in the API - the admin interface will let you do this.

- Break-before-make: if you have [1, 12, 24] and [7, 15, 42] and you want
  to end up with [1, 12, 15, 42], you have to remove 15 from the second
  relation first:

    PATCH /api/patch/1 related := [15] will fail with 409 Conflict.

  Instead do:

    PATCH /api/patch/15 related := []
    PATCH /api/patch/1  related := [15]
       -> 200 OK, [1, 12, 15, 42] and [7, 42] are the resulting relations

Signed-off-by: Mete Polat <metepolat2000@gmail.com>
Signed-off-by: Stephen Finucane <stephen@that.guru>
Signed-off-by: Daniel Axtens <dja@axtens.net>
5 years agomodels, templates: Add patch relations
Mete Polat [Thu, 27 Feb 2020 23:29:31 +0000 (23:29 +0000)] 
models, templates: Add patch relations

Introduces the ability to add relations between patches. Relations are
displayed in the details page of a patch under 'Related'. Related
patches located in another projects can be viewed as well.

Changes to relations are tracked in events. Currently the display of
this is very bare in the API but that will be fixed in a subsequent patch:
this is the minimum required to avoid throwing errors when you view the
events feed.

Signed-off-by: Mete Polat <metepolat2000@gmail.com>
[dja: address some review comments from Stephen, add an admin view,
      move to using Events, misc tidy-ups.]
Signed-off-by: Daniel Axtens <dja@axtens.net>
5 years agotests: Add tests for invalid cover/patch IDs
Stephen Finucane [Thu, 12 Mar 2020 15:11:09 +0000 (15:11 +0000)] 
tests: Add tests for invalid cover/patch IDs

Signed-off-by: Stephen Finucane <stephen@that.guru>
Related: #343

5 years agoviews: Return Http404 if patch not found
Andriy Gelman [Wed, 11 Mar 2020 03:20:04 +0000 (23:20 -0400)] 
views: Return Http404 if patch not found

Otherwise exception DoesNotExist shows error 500 on Apache

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes: #343
5 years agomigrations: Don't attempt to rehome patches
Stephen Finucane [Wed, 4 Mar 2020 16:52:19 +0000 (16:52 +0000)] 
migrations: Don't attempt to rehome patches

Migration 0039 attempts to move patches that have ended up in an
arbitrary series due to race conditions into the correct series.
However, there are a number of race conditions that can occur here that
make this particularly tricky to do. Given that series are really just
arbitary metadata, it's not really necessary to do this...so don't.
Instead, just delete the series references that identical message IDs
and below to the same project, allowing us to add the uniqueness
constraint and prevent the issue bubbling up in the future. This means
we're still left with orphaned series but these could be fixed manually,
if necessary.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Tested-by: Ali Alnubani <alialnu@mellanox.com>
Closes: #340
5 years agoparser: Don't group patches with different versions in a series
Stephen Finucane [Wed, 4 Mar 2020 15:48:56 +0000 (15:48 +0000)] 
parser: Don't group patches with different versions in a series

As noted in #340 [1], if a patch from a series is dropped or
miscategorised, patches from a later revision of that series can end up
included in the earlier series rather than in their own series. This was
actually intentional as part of the fix for #105 [2]. However,
completely ignoring this information can be problematic. Refine things
by checking for versions and, if they don't match, using timeboxing to
try guess if they should be kept together. This would resolve the issue
seen in #340 while preventing a regression for #105.

[1] https://github.com/getpatchwork/patchwork/issues/340
[1] https://github.com/getpatchwork/patchwork/issues/105

Signed-off-by: Stephen Finucane <stephen@that.guru>
Tested-by: Ali Alnubani <alialnu@mellanox.com>
Related: #340
Related: #105

5 years agomodels: Handle unset 'Submission.content'
Stephen Finucane [Sun, 7 Jul 2019 16:10:42 +0000 (17:10 +0100)] 
models: Handle unset 'Submission.content'

It's unlikely but 'Submission.content' is nullable and we weren't
handling this here. Fix that.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: 7f6685a2a ("Fix CRLF newlines upon submission changes")
5 years agodocs: Reference current list-id
Stephen Finucane [Fri, 28 Feb 2020 17:42:22 +0000 (17:42 +0000)] 
docs: Reference current list-id

We've updated our fixtures to use this newer version, meaning we no
longer need to pass an explicit '--list-id' argument. Lovely.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: 9a0b5992 ("fixtures: Update Patchwork list ID")
5 years agoAdd support for djangorestframework 3.11
Stephen Finucane [Thu, 27 Feb 2020 23:46:55 +0000 (23:46 +0000)] 
Add support for djangorestframework 3.11

There are no breaking changes apparent.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoUpdate jinja2 from 2.10.1 to 2.11.1
pyup-bot [Thu, 30 Jan 2020 21:13:55 +0000 (21:13 +0000)] 
Update jinja2 from 2.10.1 to 2.11.1

5 years agotox: Switch non-pyNN targets to Python 3
Stephen Finucane [Thu, 27 Feb 2020 23:13:54 +0000 (23:13 +0000)] 
tox: Switch non-pyNN targets to Python 3

This is long overdue and highlights a small issue, which is easily fixed
by use of Sphinx.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agopyenv: also install requirements for python2
Daniel Axtens [Tue, 28 Jan 2020 13:55:20 +0000 (00:55 +1100)] 
pyenv: also install requirements for python2

The first time you do a migration with python3, you get a whole
lot of seemingly null changes. This is a bit annoying so I use
py2 to generate the changes. To do that, first fix the pyenv
transition so requirements are still installed for python2.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Update schemas to reflect latest changes in template
Stephen Finucane [Thu, 27 Feb 2020 22:24:45 +0000 (22:24 +0000)] 
docs: Update schemas to reflect latest changes in template

Looks like I forgot to run the 'generate-schema' script beforehand. Fix
that now.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: cd3a2ce8 ("REST: Allow configuration of user settings via API")
5 years agodocker: update dependency for current build
Pranav Annam [Wed, 12 Feb 2020 03:35:47 +0000 (04:35 +0100)] 
docker: update dependency for current build

The dependency libssl1.0-dev in the Dockerfile makes docker build fail:

  The following packages have unmet dependencies:
   libmysqlclient-dev : Depends: libssl-dev (>= 1.1.1-1ubuntu2.1~18.04.5~)
  but it is not going to be installed
  E: Unable to correct problems, you have held broken packages.

There seems to be a conflict with different versions of libssl and
libmysqlclient that did not exist previously with Ubuntu 18.04.

Just use the current libssl-dev from Ubuntu 18.04 to fix the build.

Signed-off-by: Pranav Annam <pranavannam@gmail.com>
[rephrased commit message]
Signed-off-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Signed-off-by: Daniel Axtens <dja@axtens.net>
5 years agodocs: set the GID in the .env file
Pranav Annam [Wed, 12 Feb 2020 03:36:14 +0000 (04:36 +0100)] 
docs: set the GID in the .env file

The .env file needs the UID and GID for a working docker-compose build.

If you follow the current instructions, the docker build fails with a
clear error message: 'You must define GID in .env'

It is still good to update documentation to reduce the burden on new
contributors to run into this build failure first.

Signed-off-by: Pranav Annam <pranavannam@gmail.com>
[simply provide bash command in docs, reworked commit message]
Signed-off-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Signed-off-by: Daniel Axtens <dja@axtens.net>
5 years agoREST: Fix duplicate project queries
Mete Polat [Wed, 29 Jan 2020 19:01:22 +0000 (20:01 +0100)] 
REST: Fix duplicate project queries

Eliminates duplicate project queries caused by calling
get_absolute_url() in the embedded serializers. Following foreign keys
with 'series__project' will cache the project of the series as well as
the series itself.

Signed-off-by: Mete Polat <metepolat2000@gmail.com>
Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes: #335
5 years agoAdd regression tests for bug #335
Stephen Finucane [Sat, 1 Feb 2020 13:12:09 +0000 (13:12 +0000)] 
Add regression tests for bug #335

Signed-off-by: Stephen Finucane <stephen@that.guru>
Cc: Mete Polat <metepolat2000@gmail.com>
Related: #335

5 years agoHandle pull requests with random trailing space
Konstantin Ryabitsev [Mon, 27 Jan 2020 17:56:19 +0000 (12:56 -0500)] 
Handle pull requests with random trailing space

Another fix for copy-pasted pull requests, this time for cases
when something is copy-pasted from a terminal and retains all
the bogus trailing whitespace.

Example:
https://lore.kernel.org/r/043eb5b2-a302-4de6-a3e8-8238e49483b1@ti.com

Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Reviewed-by: Stephen Finucane <stephen@that.guru>
5 years agoPatchwork v2.2.0-rc1 v2.2.0-rc1
Stephen Finucane [Fri, 27 Dec 2019 18:11:13 +0000 (18:11 +0000)] 
Patchwork v2.2.0-rc1

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Bump API version in docs to 1.2
Stephen Finucane [Fri, 27 Dec 2019 18:10:04 +0000 (18:10 +0000)] 
docs: Bump API version in docs to 1.2

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agotemplates: Combine series and related row
Mete Polat [Sat, 7 Dec 2019 16:46:18 +0000 (17:46 +0100)] 
templates: Combine series and related row

Move the series patch list from row 'Related' to 'Series'. This allows
us to use the 'Related' row for actually showing submission relations
instead.

Signed-off-by: Mete Polat <metepolat2000@gmail.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
5 years agofixtures: Fix typo in default_states
Stephen Finucane [Fri, 27 Dec 2019 16:26:40 +0000 (16:26 +0000)] 
fixtures: Fix typo in default_states

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: 42b1dfa2 ("models: Add State.slug field")
5 years agotests: Add test for broken parser
Stephen Finucane [Sun, 1 Dec 2019 17:10:45 +0000 (17:10 +0000)] 
tests: Add test for broken parser

Add tests for the recent changes we made to how we parse multiple series
received at once. These tests actually highlighted what appeared to be
the test failure that's been intermittently breaking our CI for years
now, so the 'expectedFailure' marker has been removed in the hope that
this is actually the case.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoparser: Use a second query to weed out duplicate series
Stephen Finucane [Sun, 1 Dec 2019 17:10:44 +0000 (17:10 +0000)] 
parser: Use a second query to weed out duplicate series

Annoyingly, not all email clients properly thread emails using the
message ID fields originally specified in RFC 822 [1]. Worse, some MTAs
(cough, outlook.com, cough) actually override what the client
configures, breaking the world in the process. Realising this is an
issue, Patchwork supports threading using arbitrary metadata in addition
to the RFC 822 metadata. Specifically, it uses a combination of
submitter and list-id extracted from the headers along with the series
version and total count metadata extracted from the subject. In addition
to this, we timebox things so that two or more series that match on all
of this metadata but which are sent some time apart from each other
aren't combined by accident. This does leave one edge case - duplicate
series received within the timebox will be combined. We've resigned
ourselves to this fact on the basis that it's extremely unlikely for all
of these things to go wrong at once.

Given all the above, there should be no reason that attempting to find
series by series markers should return more than one series. The
timeboxing will prevent us grouping similar looking series by accident
and the only other reason for this to happen is because we lost a race
and we should try again.

[1] https://tools.ietf.org/html/rfc822

Signed-off-by: Stephen Finucane <stephen@that.guru>
Cc: Daniel Axtens <dja@axtens.net>
5 years agomodels: Use database constraints to prevent split Series
Stephen Finucane [Sun, 1 Dec 2019 17:10:43 +0000 (17:10 +0000)] 
models: Use database constraints to prevent split Series

Currently, the 'SeriesReference' object has a unique constraint on the
two fields it has, 'series', which is a foreign key to 'Series', and
'msgid'. This is the wrong constraint. What we actually want to enforce
is that a patch, cover letter or comment is referenced by a single
series, or rather a single series per project the submission appears on.
As such, we should be enforcing uniqueness on the msgid and the project
that the patch, cover letter or comment belongs to.

This requires adding a new field to the object, 'project', since it's
not possible to do something like the following:

  unique_together = [('msgid', 'series__project')]

This is detailed here [1]. In addition, the migration needs a precursor
migration step to merge any broken series.

[1] https://stackoverflow.com/a/4440189/613428

Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes: #241
Cc: Daniel Axtens <dja@axtens.net>
Cc: Petr Vorel <petr.vorel@gmail.com>
5 years agotests: Skip tests that fail on SQLite DB backend
Stephen Finucane [Sun, 1 Dec 2019 15:05:06 +0000 (15:05 +0000)] 
tests: Skip tests that fail on SQLite DB backend

These are failing due to differences in behavior of the backend. Since
this will never be used for production, we can simply skip these unit
tests and rely on the CI to catch potential issues.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agosettings: Add configuration for sqlite DB backend
Stephen Finucane [Sun, 1 Dec 2019 15:05:05 +0000 (15:05 +0000)] 
settings: Add configuration for sqlite DB backend

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agomodels: Add State.slug field
Stephen Finucane [Fri, 20 Dec 2019 10:49:21 +0000 (10:49 +0000)] 
models: Add State.slug field

This reduces a lot of the tech debt we had built up around this. This
field is populated from a slugified representation of State.name and has
a uniqueness constraint. As a result, we also need to a uniqueness
constraint to the State.name field. This shouldn't be an issue and
probably should have been used from day one.

Note that there is no REST API impact for this since we've been using
state slugs all along.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoREST: Allow configuration of user settings via API
Stephen Finucane [Sat, 30 Nov 2019 18:48:36 +0000 (18:48 +0000)] 
REST: Allow configuration of user settings via API

Expose the embedded UserProfile field via the REST API.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agotests: Provide a way to disable API schema
Stephen Finucane [Sat, 30 Nov 2019 18:48:35 +0000 (18:48 +0000)] 
tests: Provide a way to disable API schema

The API schema validation is strict, in that it will error out with
invalid keys in either the request or response. Unfortunately the API
itself is not. We're hopefully going to fix this in a distant v2.0, but
for now we need a way to ensure that the API does what it's supposed to,
namely not set fields that don't exist or that the user isn't allowed to
set, even if proper error codes aren't raised.

This isn't actually used yet. That will come later.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Add missing series index schema
Mete Polat [Sat, 7 Dec 2019 16:46:20 +0000 (17:46 +0100)] 
docs: Add missing series index schema

Fixes: 7d8e24bc84bd ("docs: Start documenting API using OpenAPI")
Signed-off-by: Mete Polat <metepolat2000@gmail.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
5 years agorequirements: Add pyup markers to prevent dumb PRs
Stephen Finucane [Sun, 1 Dec 2019 15:01:35 +0000 (15:01 +0000)] 
requirements: Add pyup markers to prevent dumb PRs

Until [1] is merged, we're going to have to override what these markers
are doing. Perhaps it would be easier to just specify the markers in the
comments as the actual marker, but I like using pip's features and the
comments *should* be temporary.

[1] https://github.com/pyupio/pyup/pull/367

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Change category of API release note
Stephen Finucane [Sun, 1 Dec 2019 12:08:42 +0000 (12:08 +0000)] 
docs: Change category of API release note

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Correct location of release note
Stephen Finucane [Sun, 1 Dec 2019 12:05:46 +0000 (12:05 +0000)] 
docs: Correct location of release note

Not sure how this ended up here but we both missed this. Correct the
location.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: d380219e ("api: support filtering patches by hash")
5 years agodocs: Add release notes for recently added features
Stephen Finucane [Sun, 1 Dec 2019 12:05:01 +0000 (12:05 +0000)] 
docs: Add release notes for recently added features

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoREST: Add 'actor' field to '/events' model
Johan Herland [Sun, 1 Dec 2019 01:49:54 +0000 (02:49 +0100)] 
REST: Add 'actor' field to '/events' model

Signed-off-by: Johan Herland <johan@herland.net>
Reviewed-by: Stephen Finucane <stephen@that.guru>
Acked-by: Daniel Axtens <dja@axtens.net>
Cc: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Closes: #73
5 years agoInclude the responsible actor in applicable events
Johan Herland [Sun, 1 Dec 2019 01:49:53 +0000 (02:49 +0100)] 
Include the responsible actor in applicable events

We want to use the events as an audit log. An important part of this is
recording _who_ made the changes that the events represent.

To accomplish this, we need to know the current user (aka. request.user)
at the point where we create the Event instance. Event creation is
currently triggered by signals, but neither the signal handlers, nor the
model classes themselves have easy access to request.user.

For some Patch-based events (patch-state-changed, patch-delegated), we
can do the following hack: The relevant events are created in signal
handlers that are all hooked up to either the pre_save or post_save
signals sent by Patch.save(). But before calling Patch.save(),
Patchwork must naturally query Patch.is_editable() to ascertain whether
the patch can in fact be changed by the current user. Thus, we only
need a way to communicate the current user from Patch.is_editable()
to the signal handlers that create the resulting Events. The Patch
object itself is available in both places, so we simply add an
'_edited_by' attribute to the instance (which fortunately is not
detected as a persistent db field by Django).

For the check-created event the current user always happens to be the
same as the 'user' field recorded in the Check object itself.

For the other Patch-based events (patch-created, patch-completed, and
series-completed), although they are also triggered by Patch.save(),
they are triggered as a result of incoming emails, hence have no real
actor as such, so we simply leave the actor as None/NULL. The same
argument also applies to the cover-created and series-created events.

Signed-off-by: Johan Herland <johan@herland.net>
Reviewed-by: Stephen Finucane <stephen@that.guru>
Cc: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
5 years agomodels.Event: Add the user responsible for the event
Johan Herland [Sun, 1 Dec 2019 01:49:52 +0000 (02:49 +0100)] 
models.Event: Add the user responsible for the event

This allows using the events as a kind of audit log, to see how a
patch came to its current state/delegate.

Signed-off-by: Johan Herland <johan@herland.net>
Reviewed-by: Stephen Finucane <stephen@that.guru>
Cc: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
5 years agotemplates: Use 'en' locale
Stephen Finucane [Sat, 30 Nov 2019 17:11:13 +0000 (17:11 +0000)] 
templates: Use 'en' locale

As discussed at [1], the UI was originally written in Australian English
but as it's been through a couple of pairs of hands since the chances
are things are more than a little messed up. Just use 'en' as our locale
rather than 'en-US', 'en-AU' or anything else.

[1] https://lists.ozlabs.org/pipermail/patchwork/2019-November/006342.html

Signed-off-by: Stephen Finucane <stephen@that.guru>
Suggested-by: Daniel Axtens <dja@axtens.net>
5 years agodocs: Only include 'order' filter in '/events/' for v1.2+
Stephen Finucane [Sat, 30 Nov 2019 16:54:48 +0000 (16:54 +0000)] 
docs: Only include 'order' filter in '/events/' for v1.2+

Even though we don't actually version this thing, don't document for
older versions of the API lest people using older deployments get
confused.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoAllow ordering events by date
Jeremy Cline [Tue, 15 Oct 2019 21:30:11 +0000 (17:30 -0400)] 
Allow ordering events by date

By default, the events API orders events by date in descending order
(newest first). However, it's useful to be able to order the events by
oldest events first. For example, when a client is polling the events
API for new events since a given date and wishes to process them in
chronological order.

Signed-off-by: Jeremy Cline <jcline@redhat.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
5 years agoREST: Exclude filters added in later version
Stephen Finucane [Sat, 30 Nov 2019 16:24:36 +0000 (16:24 +0000)] 
REST: Exclude filters added in later version

If a person requests API version 1.1, they should get the exact same
behavior regardless of the base Patchwork version. We already do this
for fields in the output, so now extend this to filters in the
querystring.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Cc: Daniel Axtens <dja@axtens.net>