From patchwork Tue Apr 12 21:35:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guilherme Salgado X-Patchwork-Id: 90875 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id 76897B6F59 for ; Wed, 13 Apr 2011 07:35:15 +1000 (EST) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by ozlabs.org (Postfix) with ESMTP id 69E1AB6F49 for ; Wed, 13 Apr 2011 07:35:14 +1000 (EST) Received: from youngberry.canonical.com ([91.189.89.112]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1Q9lEv-0001pD-1K; Tue, 12 Apr 2011 21:35:13 +0000 Received: from [187.126.166.24] (helo=feioso) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1Q9lEu-0003Y3-Nd; Tue, 12 Apr 2011 21:35:13 +0000 Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by feioso (Postfix) with ESMTP id 1559B427D5; Tue, 12 Apr 2011 18:35:10 -0300 (BRT) Subject: [PATCH 2/2] New Project method to check whether the given user has edit rights on it. To: patchwork@lists.ozlabs.org From: Guilherme Salgado Date: Tue, 12 Apr 2011 18:35:10 -0300 Message-ID: <20110412213502.21112.87934.stgit@localhost6.localdomain6> In-Reply-To: <20110412213136.21112.3159.stgit@localhost6.localdomain6> References: <20110412213136.21112.3159.stgit@localhost6.localdomain6> User-Agent: StGit/0.15 MIME-Version: 1.0 Cc: patches@linaro.org X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org 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':