Skip to content

Commit

Permalink
Add his issue edit permission with his comment edit permission
Browse files Browse the repository at this point in the history
  • Loading branch information
nsurbay committed Nov 15, 2017
1 parent 8c8e890 commit ae75f4d
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 19 deletions.
21 changes: 21 additions & 0 deletions accounts/migrations/0007_auto_20171115_0901.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-11-15 09:01
from __future__ import unicode_literals

import django.contrib.auth.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0006_auto_20171026_0747'),
]

operations = [
migrations.AlterField(
model_name='user',
name='username',
field=models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username'),
),
]
36 changes: 36 additions & 0 deletions permissions/migrations/0010_auto_20171115_0903.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-11-15 09:03
from __future__ import unicode_literals

from django.db import migrations
import permissions.models


class Migration(migrations.Migration):

dependencies = [
('permissions', '0009_globalpermission_modify_his_comment'),
]

operations = [
migrations.RenameField(
model_name='globalpermission',
old_name='modify_his_comment',
new_name='modify_his_issue_comment',
),
migrations.RenameField(
model_name='projectpermission',
old_name='modify_his_comment',
new_name='modify_his_issue_comment',
),
migrations.AlterField(
model_name='globalpermission',
name='modify_his_issue_comment',
field=permissions.models.ProjectPermissionField(default=False, verbose_name='Modify his issue and comment'),
),
migrations.AlterField(
model_name='projectpermission',
name='modify_his_issue_comment',
field=permissions.models.PermissionField(default=False, verbose_name='Modify his issue and comment'),
),
]
8 changes: 4 additions & 4 deletions permissions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def project_perms_fields_values(self):
verbose_name='Create comment')
modify_comment = ProjectPermissionField(default=False,
verbose_name='Modify comment')
modify_his_comment = ProjectPermissionField(default=False,
verbose_name='Modify his comment')
modify_his_issue_comment = ProjectPermissionField(default=False,
verbose_name='Modify his issue and comment')
delete_comment = ProjectPermissionField(default=False,
verbose_name='Delete comment')

Expand Down Expand Up @@ -192,8 +192,8 @@ class Meta:
verbose_name='Create comment')
modify_comment = PermissionField(default=False,
verbose_name='Modify comment')
modify_his_comment = PermissionField(default=False,
verbose_name='Modify his comment')
modify_his_issue_comment = PermissionField(default=False,
verbose_name='Modify his issue and comment')
delete_comment = PermissionField(default=False,
verbose_name='Delete comment')

Expand Down
26 changes: 26 additions & 0 deletions tracker/migrations/0012_auto_20171115_0933.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-11-15 09:33
from __future__ import unicode_literals

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tracker', '0011_auto_20171031_1530'),
]

operations = [
migrations.AlterField(
model_name='settings',
name='edit_policy',
field=models.IntegerField(choices=[(0, 'No timeout'), (1, 'Timeout'), (2, 'As long no next comment')], default=0, verbose_name='Policy for "Modify his issue and comment" permission'),
),
migrations.AlterField(
model_name='settings',
name='edit_policy_timeout',
field=models.IntegerField(default=30, validators=[django.core.validators.MinValueValidator(1)], verbose_name='Timeout for "Modify his issue and comment" permission (in min)'),
),
]
33 changes: 21 additions & 12 deletions tracker/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class Settings(models.Model):
])
edit_policy = models.IntegerField(choices=EDIT_TYPE,
default=EDIT_NOTIMEOUT,
verbose_name="Policy for \"Modify his comment\" permission")
verbose_name="Policy for \"Modify his issue and comment\" permission")
edit_policy_timeout = models.IntegerField(default=30,
verbose_name="Timeout for \"Modify his comment\" permission (in min)",
verbose_name="Timeout for \"Modify his issue and comment\" permission (in min)",
validators=[
MinValueValidator(1),
])
Expand Down Expand Up @@ -261,17 +261,23 @@ def overdue(self):
else:
return False

def getdesc(self):
def getdescevent(self):
desc = self.events.filter(code=Event.DESCRIBE)
if desc.exists():
return desc.first().additionnal_section
return desc.first()
else:
return None

def getdesc(self):
desc = self.getdescevent()
if desc:
return desc.additionnal_section
else:
return None

def setdesc(self, value):
desc = self.events.filter(code=Event.DESCRIBE)
if desc.exists():
desc = desc.first()
desc = self.getdescevent()
if desc:
desc.additionnal_section = value
desc.save()
else:
Expand All @@ -280,9 +286,10 @@ def setdesc(self, value):
desc.save()

def deldesc(self):
desc = self.events.filter(code=Event.DESCRIBE)
if desc.exists():
desc.first().delete()
desc = self.getdescevent()
if desc:
desc.delete()

description = property(getdesc, setdesc, deldesc)

def add_label(self, author, label, commit=True):
Expand Down Expand Up @@ -432,9 +439,11 @@ def editable_by(self, request):
if not self.editable():
return False

if request.user.has_perm('modify_comment', self.issue.project):
if request.user.has_perm('modify_comment', self.issue.project) and self.code == Event.COMMENT:
return True
elif request.user.has_perm('modify_issue', self.issue.project) and self.code == Event.DESCRIBE:
return True
elif not request.user.has_perm('modify_his_comment', self.issue.project) or \
elif not request.user.has_perm('modify_his_issue_comment', self.issue.project) or \
not self.author == request.user:
return False

Expand Down
3 changes: 2 additions & 1 deletion tracker/templates/tracker/issue_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ <h1>{{ issue }} <small>#{{ issue.id }}</small></h1>
{% if perm.delete_issue %}
<a href="#" data-item="issue" data-action="{% url 'delete-issue' project.name issue.id %}" data-toggle="modal" data-target="#confirm-delete" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-trash"></span></a>
{% endif %}
{% if perm.modify_issue %}
{% can_edit event as perm_edit %}
{% if perm_edit %}
<a href="{% url 'edit-issue' project.name issue.id %}" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-edit"></span></a>
{% endif %}
</div>
Expand Down
6 changes: 4 additions & 2 deletions tracker/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,11 @@ def issue_list(request, project):
def issue_edit(request, project, issue=None):

if issue:
if not request.user.has_perm('modify_issue', project):
raise PermissionDenied()
issue = get_object_or_404(Issue, project=project, id=issue)
if issue.getdescevent() and not issue.getdescevent().editable_by(request):
raise PermissionDenied()
elif (not issue.getdescevent()) and (not request.user.has_perm('modify_issue', project)):
raise PermissionDenied()
init_data = {'title': issue.title,
'due_date': issue.due_date,
'description': issue.description}
Expand Down

0 comments on commit ae75f4d

Please sign in to comment.