]> git.ipfire.org Git - thirdparty/patchwork.git/log
thirdparty/patchwork.git
8 years agoparser: Don't pass a message-id longer than 255 chars to the db
Stephen Finucane [Wed, 28 Jun 2017 20:33:20 +0000 (21:33 +0100)] 
parser: Don't pass a message-id longer than 255 chars to the db

The db limit is 255: we need to make sure we don't pass anything
longer in or it will throw an exception.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Stephen Finucane <stephen@that.guru>
8 years agoparser: better date parsing
Daniel Axtens [Wed, 28 Jun 2017 07:48:48 +0000 (17:48 +1000)] 
parser: better date parsing

It turns out that there is a lot that can go wrong in parsing a
date. OverflowError, ValueError and OSError have all been observed.

If these go wrong, substitute the current datetime.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Stephen Finucane <stephen@that.guru>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
8 years agoparser: deal with headers entirely failing to parse
Daniel Axtens [Wed, 28 Jun 2017 07:48:47 +0000 (17:48 +1000)] 
parser: deal with headers entirely failing to parse

It turns out that the attempts in clean_header() to convert
headers to strings are not guaranteed to work: you can end up with,
for example, a base64 decoding error which makes it impossible
to determine any header content.

In this case, sanitise_header() should return None, and thus
clean_header() should return None. We then need to plumb that
through.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Stephen Finucane <stephen@that.guru>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
8 years agoparser: catch failures in decoding headers
Daniel Axtens [Wed, 28 Jun 2017 07:48:46 +0000 (17:48 +1000)] 
parser: catch failures in decoding headers

Headers can fail to decode:
 - if a part cannot be encoded as ascii
 - if the coding hint names a codec that doesn't exist
 - if there's a null byte in the codec name

Catch these errors.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
8 years agoparser: codec lookup fails when a NUL (\x00) is in the name
Daniel Axtens [Wed, 28 Jun 2017 07:48:45 +0000 (17:48 +1000)] 
parser: codec lookup fails when a NUL (\x00) is in the name

On Python3 this presents as a ValueError
On Python2 this presents as a TypeError

In both cases, catch these exceptions.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Stephen Finucane <stephen@that.guru>
8 years agoparser: don't assume headers are strings
Daniel Axtens [Wed, 28 Jun 2017 07:48:44 +0000 (17:48 +1000)] 
parser: don't assume headers are strings

In python3, mail.get() can return either a string, or an
email.header.Header type.

clean_header() is designed to clean headers into strings,
so make sure we use that everywhere.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
8 years agoparser: fix charset 'guessing' algorithm
Daniel Axtens [Wed, 28 Jun 2017 07:48:43 +0000 (17:48 +1000)] 
parser: fix charset 'guessing' algorithm

The charset guessing algorithm doesn't work if it has to guess
multiple charsets, as it overwrites the payload with None.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
8 years agoRemove ResourceWarnings under Py3
Daniel Axtens [Wed, 28 Jun 2017 06:55:09 +0000 (16:55 +1000)] 
Remove ResourceWarnings under Py3

This is just a matter of correctly closing files we open.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
8 years agoevents-api: allow filtering by date
Aaron Conole [Wed, 14 Jun 2017 18:14:23 +0000 (14:14 -0400)] 
events-api: allow filtering by date

This commit allows users of the REST API to query for events based on
the date field.  This will allow utility writers to select a smaller
subset of events when polling.

Signed-off-by: Aaron Conole <aconole@bytheb.org>
Reviewed-by: Stephen Finucane <stephen@that.guru>
8 years agoparser: Trivial fix of test docstring
Stephen Finucane [Wed, 28 Jun 2017 19:54:03 +0000 (20:54 +0100)] 
parser: Trivial fix of test docstring

Based on the 'References' and 'In-Reply-To' headers of the used mbox,
the docstring for the 'test_reply_nocover_noversion' test is incorrect.
Fix this.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Reviewed-by: Sean Farley <sean@farley.io>
8 years agoparser: Support single-patch "series"
Stephen Finucane [Wed, 28 Jun 2017 19:53:58 +0000 (20:53 +0100)] 
parser: Support single-patch "series"

There are merits to supporting single-patch series, not least the
ability to provide two consistent interfaces that show _all_ patches in
the '/patches' endpoint and the '/series' endpoint.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Reviewed-by: Sean Farley <sean@farley.io>
8 years agoparser: Use a series even if the version differs
Stephen Finucane [Sun, 25 Jun 2017 20:55:54 +0000 (21:55 +0100)] 
parser: Use a series even if the version differs

Currently, once we've found a series for a new submission, we check to
ensure that the version of that series matches that of the submission,
and we discard the series if not. The original intention for this was
given in commit 'c21b30525', where this was added:

  There are some things you probably shouldn't do on public mailing
  lists, but which people do anyway.

  - [PATCH 1/2] test: Add some lorem ipsum
    - [PATCH 2/2] test: Convert to Markdown
      - [PATCH v2 1/2] test: Add some lorem ipsum
        - [PATCH v2 2/2] test: Convert to Markdown

  We should correctly parse these...

This is unnecessary for two reasons:

- If the series is using proper references, then the mechanism that
  we use to prevent this issue with unversioned follow ups (also added
  in that patch) will work here: namely, we don't add submissions if an
  submission with a given number already exists in that series.
- If the series is not using references, we already have a check for
  version.

Seeing as this check is actually causing issues for legitimate typos, we
should just remove this check. Do so, adding a check to ensure we don't
regress.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes-bug: #105

8 years agoparser: Validate no references, no cover behavior
Stephen Finucane [Sun, 25 Jun 2017 20:56:03 +0000 (21:56 +0100)] 
parser: Validate no references, no cover behavior

This works as expected but let's add this to prevent regressions.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Document token auth support v2.0.0-rc4
Stephen Finucane [Fri, 9 Jun 2017 17:18:38 +0000 (18:18 +0100)] 
docs: Document token auth support

Signed-off-by: Stephen Finucane <stephen@that.guru>
Acked-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
8 years agoviews: Provide a way to view, (re)generate tokens
Andrew Donnellan [Thu, 25 May 2017 05:42:16 +0000 (15:42 +1000)] 
views: Provide a way to view, (re)generate tokens

Integrate token support into the web UI.

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoREST: Enable token auth support
Stephen Finucane [Fri, 9 Jun 2017 17:18:23 +0000 (18:18 +0100)] 
REST: Enable token auth support

Token authentication is generally viewed as a more secure option for API
authentication than storing a username and password.

Django REST Framework gives us a TokenAuthentication class and an authtoken
app that we can use to generate random tokens and authenticate to API
endpoints. Enable this support and add some tests to validate correct
behavior.

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agohtdocs: Add clipboard.js
Stephen Finucane [Fri, 9 Jun 2017 17:18:04 +0000 (18:18 +0100)] 
htdocs: Add clipboard.js

We provide our own, much smaller implementation of this currently.
However, we want to be able to implement slightly different variants of
this elsewhere and using an existing library helps avoid reinventing the
wheel and lets us use already battle-tested code.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
8 years agodocs: Document the various htdocs supported
Stephen Finucane [Fri, 9 Jun 2017 17:17:55 +0000 (18:17 +0100)] 
docs: Document the various htdocs supported

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Document how to access SQL console
Stephen Finucane [Tue, 13 Jun 2017 10:06:20 +0000 (11:06 +0100)] 
docs: Document how to access SQL console

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agomigrations: Mark '0016_series_project' as non-atomic
Stephen Finucane [Tue, 13 Jun 2017 09:12:36 +0000 (10:12 +0100)] 
migrations: Mark '0016_series_project' as non-atomic

This should resolve migration issues arising from PostgreSQL's inability
to mix data and schema migrations in a single transaction.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Acked-by: Aaron Conole <aconole@bytheb.org>
Closes-bug: #104

8 years agoFix typo in 'bundles' template
Stephen Finucane [Fri, 9 Jun 2017 17:28:42 +0000 (18:28 +0100)] 
Fix typo in 'bundles' template

Fixes: d1c605f ("views: Stop using Bundle.public_url")
8 years agodocs: Fix prelude for 2.0.0
Stephen Finucane [Tue, 30 May 2017 21:59:28 +0000 (22:59 +0100)] 
docs: Fix prelude for 2.0.0

Turns out 'prelude' sections can't be lists.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: dd72ff6 ("docs: Add prelude section for v2.0.0")
8 years agoAdd missing release for pwclient unicode fixes
Stephen Finucane [Tue, 30 May 2017 21:40:00 +0000 (22:40 +0100)] 
Add missing release for pwclient unicode fixes

This was missed in '5e3b234'.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Add prelude section for v2.0.0 v2.0.0-rc3
Stephen Finucane [Tue, 30 May 2017 21:14:41 +0000 (22:14 +0100)] 
docs: Add prelude section for v2.0.0

Call out the two most important features in this release: the REST API
and series/cover letter support.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoviews: Display correct download links for covers
Stephen Finucane [Wed, 24 May 2017 10:32:49 +0000 (11:32 +0100)] 
views: Display correct download links for covers

This means using the correct link for the cover mbox and not displaying
one for the non-existent diff.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoREST: Expose cover mbox link via REST API
Stephen Finucane [Wed, 24 May 2017 10:29:31 +0000 (11:29 +0100)] 
REST: Expose cover mbox link via REST API

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoviews: Enable downloading of cover mboxes
Stephen Finucane [Wed, 24 May 2017 10:27:29 +0000 (11:27 +0100)] 
views: Enable downloading of cover mboxes

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agomodels: Centralize generation of filenames
Stephen Finucane [Tue, 30 May 2017 20:33:58 +0000 (21:33 +0100)] 
models: Centralize generation of filenames

Move filename generation to a mixin. This allows us to reuse the code
for other items like cover letters. Some unncessary 'strip' calls are
removed as their unnecessary.

This allows us to change the file extension for diffs to 'diff', which
is a little more accurate.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoparser: Validate deep threading behavior
Stephen Finucane [Tue, 23 May 2017 15:28:40 +0000 (16:28 +0100)] 
parser: Validate deep threading behavior

This is pretty simple but let's add this to prevent regressions.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoparser: Handle multiple reference headers
Stephen Finucane [Tue, 23 May 2017 14:08:13 +0000 (15:08 +0100)] 
parser: Handle multiple reference headers

It's possible to duplicate message headers multiple times. One common
case is the 'Received' header, but it appears that multiple
'In-Reply-To' and 'References' headers are also a thing.

Handle these cases through the use of the 'Message.get_all' function,
which returns all matching headers, instead of the 'Message.get'
function previously used.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoparser: Strip whitespace from references
Stephen Finucane [Wed, 24 May 2017 05:54:55 +0000 (06:54 +0100)] 
parser: Strip whitespace from references

Some mail, particularly those generated with older versions of
git-send-email or written by hand, include some extra whitespace in the
'References' and 'In-Reply-To' lines. Ensure we always strip this,
preventing mismatches between this and 'Message-ID', which is already
stripped of whitespace, when looking up SeriesReference's.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoparser: Extend series heuristics to include other metadata
Stephen Finucane [Tue, 23 May 2017 11:41:58 +0000 (12:41 +0100)] 
parser: Extend series heuristics to include other metadata

Not every series will include the reference headers necessary to do
proper series-ification, particularly those generated without the help
of 'git-send-email' or similar.

Make life a little easier for these folks by attempting to match on
other heuristics of the series: submitter, version, number of patches,
project (mailing list) and date. The last of these is particularly
important to prevent duplicate series getting munged together.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Document the various management commands available
Stephen Finucane [Tue, 30 May 2017 14:48:13 +0000 (15:48 +0100)] 
docs: Document the various management commands available

As requested.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Reported-by: Thomas Monjalon <thomas@monjalon.net>
Closes-bug: #77

8 years agodocs/api: change POST to PATCH in REST API parameters example
Andrew Donnellan [Thu, 25 May 2017 08:05:10 +0000 (18:05 +1000)] 
docs/api: change POST to PATCH in REST API parameters example

api/rest.rst gives an example of how to POST parameters to the PatchDetail
view at api/patches/<patch_id>. However, the endpoint in question doesn't
support POST - you need to use PUT or PATCH. Change it to PATCH.

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
8 years agotests: Add tests for viewing private bundles
Andrew Donnellan [Thu, 25 May 2017 07:38:05 +0000 (17:38 +1000)] 
tests: Add tests for viewing private bundles

Add some tests to check that owners can view their private bundles while
other authenticated users can't.

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agobundle: Fix use of basic auth for bundle mboxes
Andrew Donnellan [Thu, 25 May 2017 07:38:04 +0000 (17:38 +1000)] 
bundle: Fix use of basic auth for bundle mboxes

Commit 0b4f508a8438 ("views: Allow use of basic auth for bundle mboxes")
added support for using Django REST Framework's BasicAuthentication to
authenticate when accessing the bundle-mbox view.

To check the user's credentials, we call
BasicAuthentication.authenticate(), however, we don't check whether
the returned user is actually the bundle owner. This means that any user
can access any private bundle if they authenticate using basic
authentication.

Additionally, if invalid credentials are provided via a basic
authentication header, BasicAuthentication.authenticate() will throw an
AuthenticationFailed exception. We currently don't catch this, resulting in
an exception page being displayed rather than a 404.

Add a new helper, rest_auth(), that takes a request and returns a user.
Call this in bundle_mbox() and save the result into request.user before we
check whether request.user is actually the bundle owner.

Found by code inspection.

Fixes: 0b4f508a8438 ("views: Allow use of basic auth for bundle mboxes")
Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
8 years agodocker: increase database connection timeout
Andrew Donnellan [Thu, 25 May 2017 05:36:18 +0000 (15:36 +1000)] 
docker: increase database connection timeout

When starting the Docker environment, if the web container can't see the
database immediately, it waits 5 seconds, tries again, then waits 15
seconds more to account for first-time start-ups where it takes a bit
longer for the database to be initialised.

Some of us, unfortunately, have slow computers with slow mechanical hard
drives which take just a bit longer. Increase the second timeout from 15
seconds to 60 seconds, testing every 5 seconds.

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Acked-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Correct pre-release regex
Stephen Finucane [Fri, 26 May 2017 08:36:08 +0000 (09:36 +0100)] 
docs: Correct pre-release regex

There's no dot before the rc version.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: b02c43d ("docs: Add pre-release regex")
8 years agopwclient: Force xmlrpc client to return unicode strings
Robin Jarry [Tue, 23 May 2017 13:24:07 +0000 (15:24 +0200)] 
pwclient: Force xmlrpc client to return unicode strings

On python 2, the reference implementation of the XML-RPC unmarshaller
decodes strings to unicode with the selected encoding (utf-8 by default)
but it tries to re-encode the unicode strings to ascii bytes before
returning the values. If it fails, it leaves the value as unicode.

See these links for more details:

  https://hg.python.org/cpython/file/2.7/Lib/xmlrpclib.py#l878
  https://hg.python.org/cpython/file/2.7/Lib/xmlrpclib.py#l180

  https://hg.python.org/cpython/file/3.6/Lib/xmlrpc/client.py#l753

Monkey-patch the internal xmlrpclib._stringify() function only on python
2 to force it to preserve unicode strings. This allows to have similar
behaviour in both python 2 and python 3.

Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoREST: Allow filtering by both project ID and linkname v2.0.0-rc2
Stephen Finucane [Thu, 18 May 2017 22:25:26 +0000 (23:25 +0100)] 
REST: Allow filtering by both project ID and linkname

In hindsight, it's a bit odd that we would filter project by linkname by
everything else by ID. Simply support both.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: e27b68a ("REST: Filter on Project.linkname - not Project.pk")
8 years agoUpdate django-debug-toolbar from 1.7 to 1.8
pyup-bot [Fri, 5 May 2017 07:58:13 +0000 (08:58 +0100)] 
Update django-debug-toolbar from 1.7 to 1.8

Reviewed-by: Stephen Finucane <stephen@that.guru>
8 years agotox: Don't use exceptions - just warn
Stephen Finucane [Thu, 18 May 2017 20:54:57 +0000 (21:54 +0100)] 
tox: Don't use exceptions - just warn

It seems Django uses deprecated items in Python 3.x, meaning we can't
use this.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: 9db5cd0 ("tox: Turn deprecation notices into warnings")
8 years agotemplates: Use compat.cycle everywhere
Stephen Finucane [Thu, 18 May 2017 20:40:04 +0000 (21:40 +0100)] 
templates: Use compat.cycle everywhere

We missed this previously and now it's breaking Django 1.6.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: 8ae7705 ("templates: Resolve cycle issues with Django 1.10")
8 years agosettings: 'XViewMiddleware' is moved in Django 1.6 too
Stephen Finucane [Thu, 18 May 2017 20:35:58 +0000 (21:35 +0100)] 
settings: 'XViewMiddleware' is moved in Django 1.6 too

This was causing a deprecation warning. Clearly we don't need to special
case Django 1.6 here.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: 9db5cd0 ("tox: Turn deprecation notices into warnings")
8 years agomodels: Only set 'base_manager_name' for Django >= 1.10
Stephen Finucane [Thu, 18 May 2017 20:33:00 +0000 (21:33 +0100)] 
models: Only set 'base_manager_name' for Django >= 1.10

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: 8585ea5 ("models: Use 'base_manager_name'")
8 years agosettings: Enable 'XFrameOptionsMiddleware'
Stephen Finucane [Thu, 18 May 2017 20:23:59 +0000 (21:23 +0100)] 
settings: Enable 'XFrameOptionsMiddleware'

This provides basic click jacking protection. This was identified using
'manage.py check --deploy'.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoREST: Resolve issues with filters
Stephen Finucane [Mon, 15 May 2017 23:13:37 +0000 (00:13 +0100)] 
REST: Resolve issues with filters

Turns out filtering patches using a series string wasn't as easy as we
thought. We need to slugify State.name, but unfortunately that isn't
stored in the database. The tests were hiding this fact as State objects
created by 'tests.utils.create_state' don't have spaces in them.

Override custom versions of both django-filter's 'Filter' class and
the Django 'Form' required by this, and update the tests to prevent a
regression.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: 6222574 ("REST: filter patches by state name")
Tested-by: Philippe Pepiot <philippe.pepiot@logilab.fr>
8 years agoREST: Filter on Project.linkname - not Project.pk
Stephen Finucane [Mon, 15 May 2017 23:13:36 +0000 (00:13 +0100)] 
REST: Filter on Project.linkname - not Project.pk

This is what we expect based on the web UI.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoREST: Embed nested element bodies instead of URLs
Stephen Finucane [Mon, 15 May 2017 23:13:34 +0000 (00:13 +0100)] 
REST: Embed nested element bodies instead of URLs

In developing a client for the Patchwork REST API, git-pw, it was noted
that it should be possible to embed some information about nested
resources in order to prevent the need for additional requests [1]. It
was seen that this would be particularly beneficial for list operations,
where each element in the N sized list could theoretically require an
additional request for each of the M nested fields, resulting in N * (M
+ 1) total requests.

Upon experimenting with the 2.0 RC1 API, this optimization was found to
be less of a nice-to-have (and possibly something for the 2.1 release)
and more of a must-have, particularly once one took network latency for
each request into account. During testing with 'git-pw', simple list
operations were found to take an average of 31 requests per operation,
of which only one for was the resource endpoint itself ('GET
/api/series'). As each of these requests took ~2 seconds a piece,
listing was essentially broken.

While local caching could be used to offset some of this demand, this
will result in (a) significantly larger, more complex clients or (b)
instances that strain under the load of dumb clients making multiple
requests per operation. Instead, the server should be smarter about
embedding the data that would actually be required by clients.

Resolve the issue by embedding summarized versions of various nested
fields instead of merely linking to them. Nesting is only a single level
deep, to avoid large/complex database queries and with the expectation
that only these basic fields (resource names, dates, etc.) would be
required. These summary serializers are kept in their own module, to
encourage consistent results throughout the API and to prevent circular
import errors.

This will have the side effect of slightly increasing load on the server
due to the additional serialization required. However, this load is
largely mitigated through the avoidance of deeper nesting as noted
above. In addition, any increase in load seen will be a fraction of the
demand that repeat requests will incur. While it would be possible to
make nesting optional (by way of an 'embed' or 'expand' parameter), it
is expected that this would be an atypical request and would result in
far more complicated serialization code.

[1] https://github.com/stephenfin/git-pw/blob/21e0e593/git_pw/patch.py#L88-L89

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoREST: Embed 'mbox' parameter in /series
Stephen Finucane [Mon, 15 May 2017 23:13:31 +0000 (00:13 +0100)] 
REST: Embed 'mbox' parameter in /series

This wasn't added in '6deedfb7' but it should have been.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: 6deedfb7 ("views: Expose Series mbox")
8 years agoREST: Stop including 'tags' in '/patches'
Stephen Finucane [Mon, 15 May 2017 23:13:29 +0000 (00:13 +0100)] 
REST: Stop including 'tags' in '/patches'

While this is a very helpful field to include, doing so significantly
increases the number of DB queries necessary for listing patches (from
~14 to ~46). Stop including this information until the model itself is
reworked to prevent this issue.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoREST: Correct some prefetch, select_related
Stephen Finucane [Mon, 15 May 2017 23:13:27 +0000 (00:13 +0100)] 
REST: Correct some prefetch, select_related

There were two issues here:

- The 'get_queryset' function, rather than the 'queryset' attribute,
  must be overriden when using either the 'prefetch_related' or
  'select_related' functions

- A couple of endpoints contained a 'project' attribute, but this wasn't
  being prefetched. This didn't cause issues in a single-project
  deployment, as used in testing, but will for larger deployments

Resolve both issues.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agotox: Turn deprecation notices into warnings
Stephen Finucane [Thu, 18 May 2017 20:17:48 +0000 (21:17 +0100)] 
tox: Turn deprecation notices into warnings

Django does an excellent job of marking what features are going to
change in upcoming releases through extensive use of the 'warnings' module.

Pass the '-Werror' flag to 'manage.py' in tests, ensuring that any
warnings will result in exceptions instead. This should make upgrades a
mostly painless process going forward.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agocompat: Handle is_authenticated move to property
Stephen Finucane [Thu, 18 May 2017 20:17:46 +0000 (21:17 +0100)] 
compat: Handle is_authenticated move to property

This raises a warning in Django 1.10 and will cause an error in 2.0.

This resolves all issues with Django 1.9.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agosettings: Use 'MIDDLEWARE' for Django >= 1.10
Stephen Finucane [Thu, 18 May 2017 20:17:44 +0000 (21:17 +0100)] 
settings: Use 'MIDDLEWARE' for Django >= 1.10

This raises warnings in Django 1.10 and will be mandatory in Django 2.0.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agocompat: Handle moved 'reverse' function
Stephen Finucane [Thu, 18 May 2017 20:17:43 +0000 (21:17 +0100)] 
compat: Handle moved 'reverse' function

This raises a warning in Django 1.10 and will cause an error in 2.0.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agomodels: Use 'base_manager_name'
Stephen Finucane [Thu, 18 May 2017 20:17:41 +0000 (21:17 +0100)] 
models: Use 'base_manager_name'

This raises warnings in Django 1.10 and will be required in Django 1.11.

We also set 'silence_use_for_related_fields_deprecation' to allow us to
retain the current behavior on versions of Django < 1.10.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agourls: Don't "include" admin URLs
Stephen Finucane [Thu, 18 May 2017 20:17:40 +0000 (21:17 +0100)] 
urls: Don't "include" admin URLs

This raises a warning in Django 1.9 and will cause an error in Django
2.0. Per the documentation [1] it is not even necessary so it can simply
be removed.

This resolves all issues with Django 1.9.

[1] https://docs.djangoproject.com/en/1.11/ref/contrib/admin/\
      #hooking-adminsite-instances-into-your-urlconf

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agomigrations: Explicitly set 'on_delete'
Stephen Finucane [Thu, 18 May 2017 20:17:38 +0000 (21:17 +0100)] 
migrations: Explicitly set 'on_delete'

This raises warnings for Django 1.9 and will be mandatory in Django 2.0.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agomodels: Explicitly set 'on_delete'
Stephen Finucane [Thu, 18 May 2017 20:17:37 +0000 (21:17 +0100)] 
models: Explicitly set 'on_delete'

This raises warnings in Django 1.9 and will be mandatory in Django 2.0.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agosettings: Enable 'SessionAuthenticationMiddleware'
Stephen Finucane [Thu, 18 May 2017 20:17:35 +0000 (21:17 +0100)] 
settings: Enable 'SessionAuthenticationMiddleware'

This raises warnings for Django 1.8 and is mandatory in Django 1.10. It
provides a helpful feature, invalidating a user's session when their
password is changed, and can/should be enabled.

This resolves all issues with Django 1.8.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Don't mention 'default_project' in deployment guide
Stephen Finucane [Thu, 18 May 2017 13:42:19 +0000 (14:42 +0100)] 
docs: Don't mention 'default_project' in deployment guide

The deployment guide currently suggests using the 'default_project'
fixture when deploying a production installation of Patchwork. While one
_could_ use this, it's generally unnecessary given that most people care
about their own projects and not Patchwork.

Resolve this by simply removing any references. The references are
retained for the development installation guide, as they're likely
useful here.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agolib/apache2: Update location to wsgi python script
Florian Fainelli [Thu, 11 May 2017 23:25:30 +0000 (16:25 -0700)] 
lib/apache2: Update location to wsgi python script

Commit 8fe68d96f18e ("wsgi: Move wsgi file to expected location")
relocated lib/apache2/patchwork.wsgi to patchwork/wsgi.py but did not
update the Apache2 example configuration file under
lib/apache2/patchwork.wsgi.conf.

Fixes: 8fe68d96f18e ("wsgi: Move wsgi file to expected location")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Document Check.context type change
Stephen Finucane [Wed, 10 May 2017 15:19:12 +0000 (11:19 -0400)] 
docs: Document Check.context type change

Check contexts must now be slugs. Document this in the release notes.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agosettings: Enable the REST API by default v2.0.0-rc1
Stephen Finucane [Thu, 4 May 2017 18:51:12 +0000 (19:51 +0100)] 
settings: Enable the REST API by default

The release notes say this is already the case. As the API is now
functionally complete, there's no reason not to toggle this. Make it so.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agolib: Correct typo in uWSGI config file
Stephen Finucane [Thu, 4 May 2017 18:27:58 +0000 (19:27 +0100)] 
lib: Correct typo in uWSGI config file

Signed-off-by: Stephen Finucane <stephen@that.guru>
Reported-by: Philippe Pepiot <philippe.pepiot@logilab.fr>
Fixes: 150f6150 ("lib: Update uWSGI, nginx config files")
8 years agotox: Always recreate docs
Stephen Finucane [Thu, 4 May 2017 18:27:05 +0000 (19:27 +0100)] 
tox: Always recreate docs

The reno extension doesn't seem to trigger an environment rebuild. Force
this.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodoc: The REST API can now be used with Django < 1.8
Stephen Finucane [Thu, 4 May 2017 18:26:58 +0000 (19:26 +0100)] 
doc: The REST API can now be used with Django < 1.8

The release notes stated that the REST API was only compatible with
Django 1.8. However, with the merge of commit '646366cc', this is no
longer the case.

We would rather people didn't use these older versions of Django, but
let's not lie.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Add pre-release regex
Stephen Finucane [Thu, 4 May 2017 18:26:51 +0000 (19:26 +0100)] 
docs: Add pre-release regex

...in preparation for 'v2.0.0-rc1'.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Update installation guide for Ubuntu 16.04
Stephen Finucane [Mon, 1 May 2017 23:45:57 +0000 (00:45 +0100)] 
docs: Update installation guide for Ubuntu 16.04

Use the latest LTS version of Ubuntu. This is mostly a simplification of
the guide, which reverts back to single-node configuration and increases
the emphasis on installing system packages rather than using 'pip'.
There are also a series of corrections, mostly around using the Python 3
variants of packages.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agolib: Update uWSGI, nginx config files
Stephen Finucane [Mon, 1 May 2017 23:47:51 +0000 (00:47 +0100)] 
lib: Update uWSGI, nginx config files

The nginx file was a replacement for '/etc/nginx/nginx.conf' instead of
a "site" file, while the uWSGI file referenced the Python 2 plugin
despite the sample deployment guide, which uses this, being Python
3-based. Correct both issues.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoREST: Add 'category' filter to '/events'
Stephen Finucane [Wed, 3 May 2017 14:25:07 +0000 (15:25 +0100)] 
REST: Add 'category' filter to '/events'

There doesn't appear to be any reason that this _can't_ be included, and
it does make the resource a little more usable.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agomodels: Series plural name is Series
Philippe Pepiot [Thu, 4 May 2017 09:45:04 +0000 (11:45 +0200)] 
models: Series plural name is Series

By default django use verbose_name + s which lead 'Seriess'
displayed in admin interface.

Signed-off-by: Philippe Pepiot <philippe.pepiot@logilab.fr>
Reviewed-by: Stephen Finucane <stephen@that.guru>
8 years agoREST: filter patches by state name
Philippe Pepiot [Wed, 3 May 2017 11:43:04 +0000 (13:43 +0200)] 
REST: filter patches by state name

Since we display the name of the state in the serialized patch, also
filter by name instead of primary key.

Also this will be consistent with the current documentation examples
(curl 'https://patchwork.example.com/api/patches?state=under-review')

Signed-off-by: Philippe Pepiot <philippe.pepiot@logilab.fr>
Reviewed-by: Stephen Finucane <stephen@that.guru>
8 years agopwclient: Fix silent crash on python 2
Robin Jarry [Tue, 2 May 2017 14:51:51 +0000 (16:51 +0200)] 
pwclient: Fix silent crash on python 2

Replacing sys.stdout and sys.stderr can cause obscure crashes when
trying to write non unicode data. The interpreter is terminated with
SIGINT without any specific error writen on the console.

  rt_sigaction(SIGINT, {SIG_DFL, [], SA_RESTORER, 0x7f964820e8d0},
  {0x559f50, [], SA_RESTORER, 0x7f964820e8d0}, 8) = 0

This happens easily when there is an untrapped exception which should
lead to printing a traceback on stderr.

The only way to prevent UnicodeEncodeErrors is to make sure that one of
the locale-related environment variables (LC_ALL, LANG, LANGUAGE, etc.)
is set. Python will use the correct encoding accordingly.

Add a note about this on `pwclient --help`. Also, display a help message
when an encoding error occurs.

Fixes: 046419a3bf8f ("pwclient: Fix encoding problems")
Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Misc fixes
Stephen Finucane [Sat, 29 Apr 2017 00:32:23 +0000 (01:32 +0100)] 
docs: Misc fixes

Add release note requirement to contributing and fix some issues with
the development installation guide.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Emphasise the cron job
Stephen Finucane [Sat, 29 Apr 2017 00:13:06 +0000 (01:13 +0100)] 
docs: Emphasise the cron job

Having talked to a few folks deploying Patchwork, it appears not
everyone is aware of/enabling the Patchwork cron job. Emphasise this
feature by moving it to its own section. This section is marked as
optional, given that it's not truly required but is helpful.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Add a configuration guide
Stephen Finucane [Fri, 28 Apr 2017 23:46:55 +0000 (00:46 +0100)] 
docs: Add a configuration guide

This should simplify matters for folks that don't have much experience
with Django. It also serves to highlight the 'ENABLE_REST_API' option.

A release note is also added to capture the rename of
DEFAULT_PATCHES_PER_PAGE that has occurred during this cycle.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoREST: Allow users to omit version entirely
Stephen Finucane [Wed, 26 Apr 2017 23:58:04 +0000 (00:58 +0100)] 
REST: Allow users to omit version entirely

This is super handy for debugging/development of Patchwork and Patchwork
clients alike.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoREST: Fix versioning
Stephen Finucane [Wed, 26 Apr 2017 23:58:03 +0000 (00:58 +0100)] 
REST: Fix versioning

One of the few remaining warts in the API is versioning. There is some
basic versioning there, but it doesn't work properly as-is. Fix this by
correcting the index endpoint ('/') to use Django REST Framework's
'reverse' function [1], which handles versioning for us [2] and
switching from 'NamespaceVersioning' to 'URLPathVersioning', the latter
of which does the same thing but in a different way.

[1] http://www.django-rest-framework.org/api-guide/reverse/#reverse
[2] http://www.django-rest-framework.org/api-guide/versioning/#reversing-urls-for-versioned-apis
[3] http://www.django-rest-framework.org/api-guide/versioning/#urlpathversioning

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoAdd release note for Mercurial series support
Stephen Finucane [Fri, 28 Apr 2017 22:28:36 +0000 (23:28 +0100)] 
Add release note for Mercurial series support

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoparser: detect mercurial series markers
Philippe Pepiot [Fri, 28 Apr 2017 16:14:42 +0000 (18:14 +0200)] 
parser: detect mercurial series markers

Unlike git, Mercurial series marker uses the format "M of N", handle
this in the subject parser.

Test code original author is Andrew Shadura <andrew.shadura@collabora.co.uk>

Signed-off-by: Philippe Pepiot <philippe.pepiot@logilab.fr>
Reviewed-by: Stephen Finucane <stephen@that.guru>
8 years agorequirements: Test older versions of DRF (v2)
Stephen Finucane [Tue, 4 Apr 2017 21:38:19 +0000 (22:38 +0100)] 
requirements: Test older versions of DRF (v2)

In commit febad055, we attempted to start testing older versions of
Django REST Framework for use with older versions of Django. This work
was later reverted in commit 6f2ddab6 due to issues with 'django-filter'
versions.

There are additional reasons for validating older versions of DRF, such
as supporting the versions provide as part of distributions. It turns
out that those issues aren't such a big deal and can be handled with a
shim. All in all, this means we can and should support these older
versions of Django REST Framework, and that is what we'll do.

Note that the minimum version supported in requirements.txt is not
changed as it's good practice to use the latest available version.
However, that doesn't make it any less supported.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agocompat: Add non-None queryset attribute
Stephen Finucane [Tue, 4 Apr 2017 21:38:18 +0000 (22:38 +0100)] 
compat: Add non-None queryset attribute

Older versions of Django REST Framework's 'RelatedField' did not check
for the presence 'get_queryset' before checking for a 'queryset'
attribute. This was fixed in 3.4.0 [1] and backported to the 3.3 series
in 3.3.3 [2]. However, the fix was not backported to the last release of
3.2 series [3], which is the last release to support Django 1.6. As
such, we must set a 'queryset' attribute, even if it's set to a garbage
value.

[1] ../blob/3.4.0/rest_framework/relations.py#L78-L82
[2] ../blob/3.3.3/rest_framework/relations.py#L78-L82
[3] ../blob/3.2.5/rest_framework/relations.py#L64-L67

Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes-bug: #94

8 years agocompat: Handle older versions of django-filter
Stephen Finucane [Tue, 4 Apr 2017 21:38:17 +0000 (22:38 +0100)] 
compat: Handle older versions of django-filter

Recent versions of Django REST Framework (DRF) have deprecated the
'DjangoFilterBackend' filter found in-tree, in favour of an equivalent
implementation found in django-filter. However, we need to support older
versions of DRF for users who want to use system packages.

Seeing as the two implementations are, for all intents and purposes,
essentially the same thing, provide a shim that will allow us to use
both together.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Partial-bug: #94

8 years agodocs: Split API docs into their own section
Stephen Finucane [Wed, 26 Apr 2017 21:45:33 +0000 (22:45 +0100)] 
docs: Split API docs into their own section

Third time lucky. There are two changes:

- Add a new 'clients' section to the usage doc, allowing us to remove a
  lot of the API nitty gritty stuff from the users guide. This makes
  more sense as users don't really care what API method they're using -
  only what application).

- Change the API docs from the developers guide into a quick start
  section, allowing us to greatly expand the REST API docs to include
  information on pagination, authentication, etc.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agorequirements: Remove docs requirements
Stephen Finucane [Wed, 26 Apr 2017 15:06:37 +0000 (16:06 +0100)] 
requirements: Remove docs requirements

This was causing issues in the Docker build and is unnecessary with tox
around. Simply drop this.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoREADME: Additional link fixes
Stephen Finucane [Sun, 23 Apr 2017 12:32:34 +0000 (13:32 +0100)] 
README: Additional link fixes

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoREADME: Fix badges
Stephen Finucane [Sun, 23 Apr 2017 12:31:08 +0000 (13:31 +0100)] 
README: Fix badges

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoREADME: Fix broken links
Stephen Finucane [Sun, 23 Apr 2017 12:27:37 +0000 (13:27 +0100)] 
README: Fix broken links

Nested markup doesn't work that well in rST.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Add REST API usage guide
Stephen Finucane [Sun, 23 Apr 2017 12:14:30 +0000 (13:14 +0100)] 
docs: Add REST API usage guide

This details the availability of 'git-pw'. The other API usage and
development guides are updated accordingly.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Migrate release notes to rST
Stephen Finucane [Wed, 22 Mar 2017 23:03:00 +0000 (23:03 +0000)] 
docs: Migrate release notes to rST

This allows us to remove both UPGRADING and CHANGELOG.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoAdd reno for release notes management
Stephen Finucane [Wed, 22 Mar 2017 23:17:27 +0000 (23:17 +0000)] 
Add reno for release notes management

An initial patch to add reno and create a base directory for release
notes.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Remove old Markdown files
Stephen Finucane [Wed, 22 Mar 2017 23:17:25 +0000 (23:17 +0000)] 
docs: Remove old Markdown files

Everything is now ported to rST/Sphinx meaning we can remove the
Markdown versions.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Convert development guide
Stephen Finucane [Wed, 22 Mar 2017 23:17:22 +0000 (23:17 +0000)] 
docs: Convert development guide

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Convert deployment guide
Stephen Finucane [Tue, 18 Apr 2017 20:57:46 +0000 (21:57 +0100)] 
docs: Convert deployment guide

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Covert usage guide
Stephen Finucane [Wed, 22 Mar 2017 23:17:16 +0000 (23:17 +0000)] 
docs: Covert usage guide

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Convert README, index
Stephen Finucane [Wed, 22 Mar 2017 23:17:13 +0000 (23:17 +0000)] 
docs: Convert README, index

We can remove the Markdown README but must keep the index page until all
docs are migrated.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agodocs: Add skeleton for Sphinx docs
Stephen Finucane [Wed, 22 Mar 2017 23:17:08 +0000 (23:17 +0000)] 
docs: Add skeleton for Sphinx docs

This is mostly the output of 'sphinx-quickstart' with all non-HTML build
cruft removed and Sphinx minimum version set to 1.5. A tox target is
included and the output of the docs build ignored.

Signed-off-by: Stephen Finucane <stephen@that.guru>
8 years agoDisplay count of patches
Daniel Axtens [Mon, 27 Mar 2017 05:42:52 +0000 (16:42 +1100)] 
Display count of patches

Minor UI tweak - show the number of patches left in the current
view.

Suggested-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Stephen Finucane <stephen@that.guru>