[PATCH 2/2] New Project method to check whether the given user has edit rights on it.
Guilherme Salgado
guilherme.salgado at linaro.org
Wed Apr 13 07:35:10 EST 2011
This is to replace the couple places where we duplicate this same check.
---
apps/patchwork/models.py | 7 ++++++-
apps/patchwork/views/__init__.py | 3 +--
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py
index e4df2c5..7cfcd92 100644
--- a/apps/patchwork/models.py
+++ b/apps/patchwork/models.py
@@ -67,6 +67,11 @@ class Project(models.Model):
def __unicode__(self):
return self.name
+ def is_editable(self, user):
+ if not user.is_authenticated():
+ return False
+ return self in user.get_profile().maintainer_projects.all()
+
class UserProfile(models.Model):
user = models.ForeignKey(User, unique = True)
primary_project = models.ForeignKey(Project, null = True, blank = True)
@@ -223,7 +228,7 @@ class Patch(models.Model):
if self.submitter.user == user or self.delegate == user:
return True
- return self.project in user.get_profile().maintainer_projects.all()
+ return self.project.is_editable(user)
def filename(self):
fname_re = re.compile('[^-_A-Za-z0-9\.]+')
diff --git a/apps/patchwork/views/__init__.py b/apps/patchwork/views/__init__.py
index f66a2bf..fee2a32 100644
--- a/apps/patchwork/views/__init__.py
+++ b/apps/patchwork/views/__init__.py
@@ -44,8 +44,7 @@ def generic_list(request, project, view,
data = request.POST
user = request.user
properties_form = None
- if (user.is_authenticated()
- and project in user.get_profile().maintainer_projects.all()):
+ if user.is_authenticated() and project.is_editable(user):
properties_form = MultiplePatchForm(project, data = data)
if request.method == 'POST' and data.get('form') == 'patchlistform':
More information about the Patchwork
mailing list