summaryrefslogtreecommitdiff
path: root/patchwork/signals.py
Commit message (Collapse)AuthorAge
* REST: Null out previous, current relation infoStephen Finucane2020-12-13
| | | | | | | | | | | | | | | | | 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
* models: Split 'CoverLetter' from 'Submission'Stephen Finucane2020-04-26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* models, templates: Add patch relationsMete Polat2020-03-16
| | | | | | | | | | | | | | | | 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>
* Include the responsible actor in applicable eventsJohan Herland2019-12-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* signals: Fix 'series-completed' eventStephen Finucane2018-12-22
| | | | | | | | I'm not sure how I ever intended this to work and there were no tests verifying things. Fix it now and add tests to prevent it regressing. Signed-off-by: Stephen Finucane <stephen@that.guru> Fixes: 76505e91 ("models: Convert Series-Patch relationship to 1:N")
* models: Convert Series-Patch relationship to 1:NStephen Finucane2018-10-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Late in the development of the series feature, it was decided that there were advantages to allowing an N:M relationship between series and patches. This would allow us to do things like create complete series where a sole vN patch was sent to a list rather than the full series. After some time using series in the wild, it's apparent that such features are very difficult to implement correctly and will likely never be implemented. As such, it's time to start cleaning up the mess, paving the way for things like an improved tagging feature. There are some significant changes to the model required: - models.py, migrations/0027, migrations/0028, migrations/0029 The migrations make the following changes: 1. - Add 'Patch.series_alt' and 'Patch.number' fields. 2. - Populate the 'Patch.series_alt' and 'Patch.number' fields from their 'SeriesPatch' equivalents. 3. - Remove the 'SeriesPatch' model. - Rename 'Patch.series_alt' to 'Patch.series'. - Change 'Series.cover_letter' to a 'OneToOneField' since a cover letter can no longer be assigned to multiple series. Note that the migrations have to be split into multiple parts as the combined migration raises an OperationalError as below. (1072, "Key column 'series_alt_id' doesn't exist in table") This is due to Django's penchant for creating indexes for newly created fields, as noted here: https://stackoverflow.com/q/35158530/ Aside from the model changes, there are numerous other changes required: - admin.py Reflect model changes for the 'PatchInline' inline used by 'SeriesAdmin' - api/cover.py, api/patch.py Update the 'series' field for the cover letter and patch resources to reflect the model changes. A 'to_representation' function is added in both cases to post-process this field and make it look like a list again. This is necessary to avoid breaking clients. - parser.py Update to reflect the replacement of 'SeriesPatch' with 'Patch'. - signals.py Update to filter on changes to 'Patch' instead of 'SeriesPatch'. This requires some reworking due to how we set these fields now, as we can no longer receive on 'post_save' signals for 'SeriesPatch' and must instead watch for 'pre_save' on 'Patch', which is what we do for delegate and state changes on same. - templates/patchwork/*.html Remove logic that handled multiple series in favour of the (simpler) single series logic. - tests/* Modify the 'create_series_patch' helper to reflect the removal of the 'SeriesPatch' model. This entire helper will be removed in a future change. Improve some tests to cover edge cases that were highlighted during development Unfortunately, all of the above changes must go in at the same time, otherwise we end up with either (a) broken views, API etc. or (b) split brain because we need to keep the new single-series fields alongside the older multi-series fields and models while we rework the views. It's unfortunate but there's not much to be done here. Signed-off-by: Stephen Finucane <stephen@that.guru> Tested-by: Daniel Axtens <dja@axtens.net>
* Update license headerStephen Finucane2018-09-19
| | | | | | | | | | | | | The FSF has a new address since 2005 that hasn't been noted in any file except the COPYING file. Rather than fix these, simply remove the headers in favour of a SPDX license header. IANAL but the combination of the header and the COPYING file in source should resolve this issue. Note that copyright notices are retained. Signed-off-by: Stephen Finucane <stephen@that.guru> Closes: #210 Reviewed-by: Veronika Kabatova <vkabatov@redhat.com>
* Avoid timezone confusionVeronika Kabatova2018-03-08
| | | | | | | | | | | | | | | | | | | | | | | Patchwork saves patches, comments etc with UTC timezone and reports this time when opening the patch details. However, internally generated processes such as events are reported with the instance's local time. There's nothing wrong with that and making PW timezone-aware would add useless complexity, but in a world-wide collaboration a lot of confusion may arise as the timezone is not reported at all. Instance's local time might be very different from the local time of CI integrating with PW, which is different from the local time of person dealing with it etc. Use UTC everywhere by default instead of UTC for sumbissions and local timezone for internally generated events (which is not reported). Signed-off-by: Veronika Kabatova <vkabatov@redhat.com> [dja: - squash 2 patches: https://patchwork.ozlabs.org/patch/876744/ https://patchwork.ozlabs.org/patch/877815/ - minor changes to both patches - rejig order of migrations and adjust wording: "happened sooner" -> "happened earlier"] Tested-by: Daniel Axtens <dja@axtens.net> Signed-off-by: Daniel Axtens <dja@axtens.net>
* trivial: Fix some nitsStephen Finucane2018-01-10
| | | | Signed-off-by: Stephen Finucane <stephen@that.guru>
* signals: Don't call event creation code for fixturesStephen Finucane2018-01-09
| | | | | | | If loading fixtures via the 'loaddata' management command, then it is unlikely that the signal handling code should execute. Disable it. Signed-off-by: Stephen Finucane <stephen@that.guru>
* signals: Add callbacks for eventsStephen Finucane2017-03-01
| | | | | | | | When models are modified, fire signal handlers to create the relevant events. Signed-off-by: Stephen Finucane <stephen@that.guru> Tested-by: Daniel Axtens <dja@axtens.net>
* models: Move signal to 'signals'Stephen Finucane2017-03-01
Additional signals are going to be added shortly and they shouldn't pollute 'models.py'. Signed-off-by: Stephen Finucane <stephen@that.guru> Tested-by: Daniel Axtens <dja@axtens.net>