Commit b18d5e2d authored by Guilherme Salgado's avatar Guilherme Salgado Committed by Jeremy Kerr
Browse files

models: Project.is_editable to check whether a user has edit rights

This is to replace the couple of places where we duplicate this same
Signed-off-by: default avatarJeremy Kerr <>
parent e3f9cdfd
......@@ -67,6 +67,11 @@ class Project(models.Model):
def __unicode__(self):
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\.]+')
......@@ -43,8 +43,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 project.is_editable(user):
properties_form = MultiplePatchForm(project, data = data)
if request.method == 'POST' and data.get('form') == 'patchlistform':
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