Commit ff91eb8a authored by Arkadiusz Hiler's avatar Arkadiusz Hiler

series: Allow submitter to retest

Previously only the project maintainers were allowed to request a rerun.

This patch gives the same power to the author (aka submitter) of the
series.
Signed-off-by: Arkadiusz Hiler's avatarArkadiusz Hiler <arkadiusz.hiler@intel.com>
parent e876b068
......@@ -17,7 +17,7 @@
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from patchwork.models import Project, Patch
from patchwork.models import Project, Patch, Series
class Can:
......@@ -38,3 +38,12 @@ class Can:
can.edit(patch.project)))
return False
def retest(self, obj):
can = self
if isinstance(obj, Series):
series = obj
return (can.edit(series.project) or
series.submitter.user == self.user)
return False
......@@ -10,12 +10,7 @@ $(function () {
});
$(document).ready(function() {
if (!pw.project.is_editable) {
var retest_container = $("#retest-latest-container");
retest_container.fadeTo(0, 0.2); // immediate "transition"
pw.fade_disable(retest_container);
}
{% if is_retestable %}
$("#retest-latest").click(function(e) {
e.preventDefault();
var button = $(this);
......@@ -44,6 +39,11 @@ $(document).ready(function() {
pw.post_data(url, undefined, on_post_success, on_post_failure);
});
{% else %}
var retest_container = $("#retest-latest-container");
retest_container.fadeTo(0, 0.2); // immediate "transition"
pw.fade_disable(retest_container);
{% endif %}
});
</script>
{% endblock %}
......@@ -96,7 +96,7 @@ $(document).ready(function() {
<div>
<div id="retest-latest-container" class="btn-group" style="float: right;"
data-disabled-title="You have to be logged in and be the project maintainer.">
data-disabled-title="You have to be logged in and be the submitter or the project maintainer.">
<button class="btn btn-info" id="retest-latest"
data-series="{{ series.id }}" data-revision="{{ series.last_revision.version }}">
test latest revision again
......
......@@ -359,6 +359,18 @@ class EventTest(APITestBase):
params={'since': after})
self.assertEqual(events['count'], 0)
def testRetestApiEndpointAsSubmitter(self):
submitter = self.series.submitter
submitter.user = self.user.user
submitter.save()
events_before = self.get_json(GET_EVENTS_URL)
ret = self.post(NEW_REV_URL, user=self.user)
events_after = self.get_json(GET_EVENTS_URL)
self.assertEqual(200, ret.status_code)
self.assertEqual(events_before['count'] + 1, events_after['count'])
def testRetestApiEndpointAsMaintainer(self):
events_before = self.get_json(GET_EVENTS_URL)
ret = self.post(NEW_REV_URL, user=self.maintainer)
......
......@@ -19,7 +19,7 @@
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from django.core.exceptions import FieldDoesNotExist
from django.core.exceptions import FieldDoesNotExist, PermissionDenied
from django.conf import settings
from django.core import mail
from django.db.models import Q
......@@ -307,8 +307,12 @@ class RevisionViewSet(mixins.ListModelMixin, ListMixin,
def newrevision(self, request, series_pk=None, pk=None):
rev = get_object_or_404(SeriesRevision, series=series_pk, version=pk)
# make sure the user is a maintainer
self.check_object_permissions(request, rev.series)
# we are not using the permissions from django-rest-framework
#
# they would make us to define a class, call check_object_permissions
# here and introduce a level of indirectness just for this single use
if not Can(request.user).retest(rev.series):
raise PermissionDenied
# log event
new_revision = Event.objects.get(name='series-new-revision')
......
......@@ -53,6 +53,7 @@ class SeriesView(View):
'series': series,
'project': project,
'is_editable': Can(request.user).edit(project),
'is_retestable': Can(request.user).retest(series),
'cover_letter': revision.cover_letter,
'revisions': revisions,
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment