]> git.ipfire.org Git - thirdparty/patchwork.git/log
thirdparty/patchwork.git
4 years agourls: Support sha256-based tokens
Stephen Finucane [Sat, 20 Feb 2021 12:22:08 +0000 (12:22 +0000)] 
urls: Support sha256-based tokens

Django 3.1 changed the default hashing algorithm used for things like
password reset tokens from SHA-1 to SHA-256. As noted in the release
notes [1], this is configurable via the 'DEFAULT_HASHING_ALGORITHM'
transitional setting, but that's only intended to allow upgrades of
multiple instances in a HA deployment and shouldn't be used post
upgrade. Instead, we need to fix our URLs to support the longer tokens
generated by SHA-256.

Long term, we want to replace these regex-based routes with the simpler
flask-style template string routes. That's not really backportable so
we'll do that separately.

[1] https://docs.djangoproject.com/en/3.1/releases/3.1/#default-hashing-algorithm-settings

Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes: #394
(cherry picked from commit 8d988f15b8a3c433aa385de7e5ba5129fdba4f40)

4 years agoRelease 3.0.0 v3.0.0
Stephen Finucane [Sun, 4 Oct 2020 11:18:11 +0000 (12:18 +0100)] 
Release 3.0.0

Major version bump because of Python 2.7 removal and the unfortunately
large DB migration.

Signed-off-by: Stephen Finucane <stephen@that.guru>
4 years agoAdd Python 3.9 support
Stephen Finucane [Sun, 13 Dec 2020 20:06:50 +0000 (20:06 +0000)] 
Add Python 3.9 support

This has been out since October. Time to support it.

Signed-off-by: Stephen Finucane <stephen@that.guru>
4 years agorequirements: Switch to openapi-core 0.13.4
Stephen Finucane [Sun, 13 Dec 2020 19:44:53 +0000 (19:44 +0000)] 
requirements: Switch to openapi-core 0.13.4

In commit b7f3c3d34 ("tests: Switch to openapi-core 0.13.x") we added
support for 'openapi-core' 0.13.x. However, we needed to use a commit
from master since an important fix [1] was not included in the latest
release at the time, 0.13.3. 0.13.4 has since been released so let's
move on and use that.

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

Signed-off-by: Stephen Finucane <stephen@that.guru>
4 years agoRe-enable django-dbbackup
Stephen Finucane [Sun, 13 Dec 2020 19:16:38 +0000 (19:16 +0000)] 
Re-enable django-dbbackup

...and bump to 3.3.0, which does support Django 3.0 [1].

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

Signed-off-by: Stephen Finucane <stephen@that.guru>
4 years agorequirements: Bump django-debug-toolbar to 3.2.x
Stephen Finucane [Sun, 13 Dec 2020 19:15:17 +0000 (19:15 +0000)] 
requirements: Bump django-debug-toolbar to 3.2.x

Signed-off-by: Stephen Finucane <stephen@that.guru>
4 years agoAdd release note for #379
Stephen Finucane [Sun, 13 Dec 2020 18:34:47 +0000 (18:34 +0000)] 
Add release note for #379

Signed-off-by: Stephen Finucane <stephen@that.guru>
4 years agoREST: Null out previous, current relation info
Stephen Finucane [Sun, 29 Nov 2020 12:50:22 +0000 (12:50 +0000)] 
REST: Null out previous, current relation info

These fields don't work like we expect them to. Because we're linking to
a non-idempotent entity, an instance of 'relation', what we're storing
in either of these fields is subject to change as patches are added and
removed. This makes the information pretty much useless after the fact.
It's best to just state the patch and request that people query the
information themselves if necessary. We don't want to remove the field
entirely from the API - that would be a truly breaking change - so
instead we null it out like we do for patch tags. In a v2 API (i.e. a
major version bump) we can remove this entirely.

A small bug with the schema generation is corrected.

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

4 years agoRemove 'PatchRelationSerializer'
Stephen Finucane [Thu, 1 Oct 2020 13:38:31 +0000 (14:38 +0100)] 
Remove 'PatchRelationSerializer'

This wasn't writeable for reasons I haven't been able to figure out.
However, it's not actually needed: the 'PatchSerializer' can do the job
just fine, given enough information. This exposes a bug in DRF, which
has been reported upstream [1]. While we wait for that fix, or some
variant of it, to be merged, we must monkey patch the library.

[1] https://github.com/encode/django-rest-framework/issues/7550
[2] https://github.com/encode/django-rest-framework/pull/7574

Signed-off-by: Stephen Finucane <stephen@that.guru>
Reported-by: Ralf Ramsauer <ralf.ramsauer@oth-regensburg.de>
Closes: #379
Cc: Daniel Axtens <dja@axtens.net>
Cc: Rohit Sarkar <rohitsarkar5398@gmail.com>
4 years agotests: Add tests for 'patch-relation-changed' events
Stephen Finucane [Sun, 4 Oct 2020 11:03:19 +0000 (12:03 +0100)] 
tests: Add tests for 'patch-relation-changed' events

This event is rather odd. If you have two patches then the way a
relation is created is by creating a 'PatchRelation' instance and then
setting the 'related' attribute on the first patch followed by the
second patch. Because the event uses the 'Patch' model's 'pre_save'
signal, we'll only see events for the patch being currently saved. This
means no event will be raised for the first patch and only one event,
the one for the second patch, will be raised when the second patch is
being added to the relationship.

In hindsight, the structure of the event is off. We should have had
something like a 'patch-added-to-relationship' and a
'patch-removed-from-relationship' event, both with the same fields:
'project', 'actor', 'patch' and 'related', the latter of which would
have listed all of the _other_ patches in the relationship. Sadly, this
is an API change which means we can't do it now. We may well wish to do
so in the future though.

Signed-off-by: Stephen Finucane <stephen@that.guru>
4 years agotests: Rework 'create_relation' helper
Stephen Finucane [Sun, 4 Oct 2020 10:42:42 +0000 (11:42 +0100)] 
tests: Rework 'create_relation' helper

This wasn't actually creating just a patch relation object - it was also
creating patches, which is something we already have an explicit helper
for. Clean this thing up.

Signed-off-by: Stephen Finucane <stephen@that.guru>
4 years agolib: Grant SELECT on auth_user
Stephen Finucane [Sat, 28 Nov 2020 17:32:32 +0000 (17:32 +0000)] 
lib: Grant SELECT on auth_user

If a mail arrives with the 'X-Patchwork-Delegate' hint header, the
'patchwork.parser' script will need to index the users table to find the
appropriate user. This should be okay from a security perspective since
passwords are hashed and salted and the rest of the information is
mostly accessible publicly via the web UI and REST API.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Suggested-by: Ali Alnubani <alialnu@mellanox.com>
Closes: #365
4 years agoviews/patch: Set correct encoding for patches
Toke Høiland-Jørgensen [Tue, 1 Dec 2020 21:15:11 +0000 (22:15 +0100)] 
views/patch: Set correct encoding for patches

The patch_mbox view returns text/plain data without specifying a character
set, which means clients will assume the default of iso-8559-1 as defined
in the HTTP/1.1 standard. Since the data being returned is in fact utf-8
encoded, set the encoding accordingly in the HTTP Content-Type header.

Reported-by: Jakub Kicinski <kuba@kernel.org>
Suggested-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
4 years agorequirements: Bump sqlparse to 0.4.0
Stephen Finucane [Mon, 30 Nov 2020 09:31:48 +0000 (09:31 +0000)] 
requirements: Bump sqlparse to 0.4.0

Signed-off-by: Stephen Finucane <stephen@that.guru>
4 years agorequirements: Add tblib
Stephen Finucane [Sun, 29 Nov 2020 13:01:42 +0000 (13:01 +0000)] 
requirements: Add tblib

This is needed by the parallel test runner to handle pickling of
tracebacks.

Signed-off-by: Stephen Finucane <stephen@that.guru>
4 years agoAdd parallel testing
Stephen Finucane [Thu, 1 Oct 2020 15:28:58 +0000 (16:28 +0100)] 
Add parallel testing

This saves us a good deal of time, even allowing for process startup and
general overhead. Before:

  real    6m39.103s
  user    1m9.561s
  sys     0m2.705s

After:

  real    4m5.267s
  user    1m24.527s
  sys     0m3.828s

This requires N databases, where N is the N of processors on the host.
We need to update the docker configuration for this.

Signed-off-by: Stephen Finucane <stephen@that.guru>
4 years agoRemove landscape.yaml
Stephen Finucane [Sun, 29 Nov 2020 12:11:26 +0000 (12:11 +0000)] 
Remove landscape.yaml

landscape.io is dead [1]. No point keeping this artefact around.

[1] https://landscape.io/landscapes-story-in-2016.html

Signed-off-by: Stephen Finucane <stephen@that.guru>
4 years agolib: Update DB permissions to reflect model changes
Stephen Finucane [Sat, 28 Nov 2020 17:25:25 +0000 (17:25 +0000)] 
lib: Update DB permissions to reflect model changes

These should have been done when we made changes to the model.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: ac0e4de9 ("models: Merge 'Patch' and 'Submission'")
4 years agoparser: Update reference to PatchComment
Stephen Finucane [Sat, 28 Nov 2020 16:34:01 +0000 (16:34 +0000)] 
parser: Update reference to PatchComment

Commit 0686a736fbf6d869bd31bd135ba38080ac96de22 split out 'CoverLetter'
from the old 'Submission' model, removing the common 'Comment' model in
favour of distinct 'CoverComment' and 'PatchComment' models in the
process. Unfortunately we misssed some references to the old model in
the 'patchwork.parser' module. Correct these now, adding unit tests to
prevent regressions.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: 0686a736 ("models: Split 'CoverLetter' from 'Submission'")
Closes: #384
5 years agorequirements: Update doc requirements
Stephen Finucane [Thu, 1 Oct 2020 15:51:26 +0000 (16:51 +0100)] 
requirements: Update doc requirements

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agorequirements: Bump mysqlclient to 2.0.0
Stephen Finucane [Thu, 1 Oct 2020 14:17:49 +0000 (15:17 +0100)] 
requirements: Bump mysqlclient to 2.0.0

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agorequirements: Bump django-debug-toolbar to 3.1.x
Stephen Finucane [Thu, 1 Oct 2020 14:16:42 +0000 (15:16 +0100)] 
requirements: Bump django-debug-toolbar to 3.1.x

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agorequirements: Bump django-filter to 2.4.0
Stephen Finucane [Thu, 1 Oct 2020 14:15:37 +0000 (15:15 +0100)] 
requirements: Bump django-filter to 2.4.0

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoAdd support for djangorestframework 3.12
Stephen Finucane [Thu, 1 Oct 2020 14:14:41 +0000 (15:14 +0100)] 
Add support for djangorestframework 3.12

No changes necessary.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agomodels: Validate Project.linkname does not contain forward slash
Thomas Bracht Laumann Jespersen [Mon, 28 Sep 2020 16:37:07 +0000 (18:37 +0200)] 
models: Validate Project.linkname does not contain forward slash

I started by creating a project that contained a forward slash
(importing patches from https://lists.sr.ht/~sircmpwn/sr.ht-dev/) and
it fails to render the "projects" main page.

The specific error reads:

    NoReverseMatch at /

    Reverse for 'patch-list' with keyword arguments
    '{'project_id': 'foo/bar'}' not found. 1 pattern(s) tried:
    ['project/(?P<project_id>[^/]+)/list/$']

which appears to explicitly disallow forward slashes.

So I think it makes sense to validate that project linkname doesn't
contain forward slahes.

This implementation uses the validate_unicode_slug validator instead of just
rejecting inputs that contain forward slashes.

Signed-off-by: Thomas Bracht Laumann Jespersen <t@laumann.xyz>
Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes: #380
5 years agoAdd support for Django 3.1
Andrew Donnellan [Thu, 27 Aug 2020 14:14:06 +0000 (00:14 +1000)] 
Add support for Django 3.1

Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
5 years agorequirements: Update django-filter
Andrew Donnellan [Thu, 27 Aug 2020 14:14:05 +0000 (00:14 +1000)] 
requirements: Update django-filter

Update django-filter dependency to a version that's compatible with Django
3.1.

Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
5 years agosettings: Add context processor django.template.context_processors.request
Andrew Donnellan [Thu, 27 Aug 2020 14:14:04 +0000 (00:14 +1000)] 
settings: Add context processor django.template.context_processors.request

Django 3.1 adds a new admin sidebar feature that requires the
django.template.context_processors.request context processor to be enabled
in the settings.

Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
5 years agourls: Update url pattern functions
Andrew Donnellan [Thu, 27 Aug 2020 14:14:03 +0000 (00:14 +1000)] 
urls: Update url pattern functions

Django 3.1 deprecates django.conf.urls.url() as an alias for
django.urls.re_path(). Also switch to using django.urls.include() rather
than django.conf.urls.include().

Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agotemplates: Replace ifequal and ifnotequal with if
Andrew Donnellan [Thu, 27 Aug 2020 14:14:02 +0000 (00:14 +1000)] 
templates: Replace ifequal and ifnotequal with if

Django 3.1 deprecates the ifequal and ifnotequal tags, for removal in 4.0.
Replace all occurrences of ifequal and ifnotequal with if.

Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
5 years agomanagement: introduce replacerelations command
Rohit Sarkar [Sat, 1 Aug 2020 06:24:15 +0000 (11:54 +0530)] 
management: introduce replacerelations command

The replacerelations script is used to ingest relations into Patchwork's
patch database. A patch groups file is taken as input, which on each
line contains a space separated list of patchwork ids denoting a
relation. All the existing relations in Patchwork's database are removed
and the relations read from the patch groups file are ingested.

Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com>
[dja: pep8, drop relations directory as empty dirs don't get stored by git,
      comment about how lines are generated.]
Signed-off-by: Daniel Axtens <dja@axtens.net>
5 years agodocker: Switch to MariaDB for wider platform support
Stewart Smith [Sat, 13 Jun 2020 23:19:12 +0000 (16:19 -0700)] 
docker: Switch to MariaDB for wider platform support

MySQL docker images only have amd64 arch support
MariaDB images have amd64, arm64v8, and ppc64le

Signed-off-by: Stewart Smith <stewart@flamingspork.com>
Signed-off-by: Daniel Axtens <dja@axtens.net>
5 years agoadmin: fix series query
Jan Remmet [Mon, 25 May 2020 07:03:10 +0000 (09:03 +0200)] 
admin: fix series query

remove typo from search_fields.

Signed-off-by: Jan Remmet <j.remmet@phytec.de>
Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocs: Bump sphinxcontrib-openapi to 0.7.0
Stephen Finucane [Fri, 8 May 2020 08:49:50 +0000 (09:49 +0100)] 
docs: Bump sphinxcontrib-openapi to 0.7.0

This picks up an important fix [1] we want for our docs build.

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

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoRevert "tox: Add default Django version"
Stephen Finucane [Fri, 1 May 2020 09:02:11 +0000 (10:02 +0100)] 
Revert "tox: Add default Django version"

This reverts commit 029aff107ea9950418f9ad3cf44c3ba1ca3ea3ee. It appears
this isn't supported by tox either :(

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agotox: Add default Django version
Stephen Finucane [Thu, 30 Apr 2020 21:22:10 +0000 (22:22 +0100)] 
tox: Add default Django version

I occasionally forget myself and run e.g. 'tox -e pyNN' when I want to
sanity check something instead of 'tox -e pyNN-djangoMM'. Add fallback
Django versions so that this doesn't crash and burn. It's less succict
than it could be since tox doesn't seem to support '!django{22,30}'
(yet!).

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agomigrations: Moved squashed migration
Stephen Finucane [Sun, 26 Apr 2020 20:20:46 +0000 (21:20 +0100)] 
migrations: Moved squashed migration

This should have been in the 'patchwork/migrations' directory, not
'migrations.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: 9bb5caec ("migrations: Squash 0001 to 0040")
5 years agomigrations: Resolve issues with other DB backends for 0042, 0043
Stephen Finucane [Sun, 26 Apr 2020 13:17:57 +0000 (14:17 +0100)] 
migrations: Resolve issues with other DB backends for 0042, 0043

0042 was using MySQL-specific SQL to delete entries in the
'patchwork_comment' table that were associated with entries in the
'patchwork_coverletter' table, while 0043 only considered MySQL and
PostgrSQL when attempting to copy fields from 'patchwork_patch' to
'patchwork_submission'. Both issues are resolved.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agodocker: Ignore postgres data file
Stephen Finucane [Sun, 26 Apr 2020 14:28:20 +0000 (15:28 +0100)] 
docker: Ignore postgres data file

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agomigrations: Squash 0001 to 0040
Stephen Finucane [Fri, 10 Apr 2020 11:08:32 +0000 (12:08 +0100)] 
migrations: Squash 0001 to 0040

Now that we're moving a new major version, we can squash the migrations
we have to date. This coexists alongside the old migrations, which we
can remove and replace entirely when we release 4.0, per the advice of
the 'squashmigrations' tool.

  You should commit this migration but leave the old ones in place; the
  new migration will be used for new installs. Once you are sure all
  instances of the codebase have applied the migrations you squashed,
  you can delete them.

The 'squashmigrations' tool can't parse the output of 'RunPython' blocks
so the output of the tool was less optimized than it could be. As a
result, we've manually modified this change to remove the 'RunPython'
block and unnecessary 'AlterField' entries. This was done by removing
all migrations and generating a new "initial" migration, which was then
modified to mark all strings as byte strings (as they were when we were
using Python 2 to generate these migrations) so that 0041 would apply
cleanly.

The main benefit of this change is that it significantly reduces the
startup time for unit tests. Executed on my host, the run time for a
single test goes from ~ 22 seconds to ~ 14 seconds. This is obviously
reduced for additional tests.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agomodels: Trivial post-merge cleanup
Stephen Finucane [Thu, 9 Apr 2020 16:56:44 +0000 (17:56 +0100)] 
models: Trivial post-merge cleanup

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agomodels: Merge 'Patch' and 'Submission'
Stephen Finucane [Tue, 3 Mar 2020 10:46:37 +0000 (10:46 +0000)] 
models: Merge 'Patch' and 'Submission'

Oh, the follies of youth. Time to undo the damage of 2.0.0, specifically
commit 86172ccc16, which split Patch into two separate models using
concrete inheritance. As noted previously, this introduced a large
number of unavoidable JOINs across large tables and the performance
impacts these introduce are blocking other features we want, such as
improved tagging functionality. To combine these two models, we must do
the following:

- Update any references to the 'Patch' model to point to the
  'Submission' model instead
- Move everything from 'Patch' to 'Submission', including both fields
  and options
- Delete the 'Patch' model
- Rename the 'Submission' model to 'Patch'

With this change, our model "hierarchy" goes from:

  Submission
    Patch
    PatchComment
  Cover
    CoverComment

To a nice, flat:

  Patch
    PatchComment
  Cover
    CoverComment

I expect this migration to be intensive, particularly for MySQL users
who will see their entire tables rewritten. Unfortunately I don't see
any way to resolve this in an easier manner.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agomodels: Split 'CoverLetter' from 'Submission'
Stephen Finucane [Sat, 29 Feb 2020 17:20:50 +0000 (17:20 +0000)] 
models: Split 'CoverLetter' from 'Submission'

We want to get rid of the split between 'Patch' and 'Submission' because
of the cost of using JOINs basically everywhere we use 'Patch'. Before
we do that, we need to move the other users of 'Submission' to other
models and other models that rely on these users sharing the common
'Submission' base. For the former, there is only one user,
'CoverLetter', while for the latter there is only the 'Comment' model.
As a result, we must do the following:

- Create a new 'Cover' model
- Create a new 'CoverComment' model
- Move everything from 'CoverLetter' to 'Cover' and all entries
  associated with a 'CoverLetter' from 'Comment' to 'CoverComment'
- Delete the 'CoverLetter' model
- Rename the 'Comment' model to 'PatchComment'

This means our model "hierarchy" goes from:

  Submission
    Patch
    CoverLetter
    Comment

To:

  Submission
    Patch
    PatchComment
  Cover
    CoverComment

A future change will flatten the 'Submission' and 'Patch' model.

Note that this actually highlighted a bug in Django, which has since
been reported upstream [1]. As noted there, the issue stems from MySQL's
refusal to remove an index from a foreign key when DB constraints are
used and the workaround is to remove the foreign key constraint before
altering the indexes and then re-add the constraint after.

[1] https://code.djangoproject.com/ticket/31335

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoRevert "Be sensible computing project patch counts"
Stephen Finucane [Wed, 4 Mar 2020 10:50:17 +0000 (10:50 +0000)] 
Revert "Be sensible computing project patch counts"

This reverts commit cfcf2f2a80ac0709f1a5fd9aa212c8403daa5a18.

This will no longer be necessary once we remove the Patch-Submission
split. Revert it now to avoid needing to rejig this later.

Conflicts:
patchwork/views/project.py

NOTE(stephenfin): Conflicts are due to commit 880ec8c5 ("Fetch
maintainer information in one query") which changed nearby lines.

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

We want to drop this in future changes. Start by removing any
unnecessary references.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agotrivial: Rename 'CoverLetter' references to 'Cover'
Stephen Finucane [Sun, 1 Mar 2020 15:13:23 +0000 (15:13 +0000)] 
trivial: Rename 'CoverLetter' references to 'Cover'

We're going to be doing some model surgery shortly. Do the necessary
renaming of variables ahead of this.

Signed-off-by: Stephen Finucane <stephen@that.guru>
5 years agoforms: Remove LoginForm
Stephen Finucane [Thu, 23 Apr 2020 09:46:46 +0000 (10:46 +0100)] 
forms: Remove LoginForm

This should have been removed in commit f1e089f773.

Signed-off-by: Stephen Finucane <stephen@that.guru>
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>