Skip to content

Commit

Permalink
Add bugtag permissions required for working on kiwitcms#1597
Browse files Browse the repository at this point in the history
Model: `bugs.Bug`
Permissions added:
* `'bugs.add_bugtag'`
* `'bugs.delete_bugtag'`
  • Loading branch information
mfonism committed May 25, 2020
1 parent 508564d commit a0833d8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tcms/bugs/migrations/0003_add_bugtag_permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.0.3 on 2020-05-25 16:29

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('bugs', '0002_add_permissions'),
]

operations = [
migrations.AlterModelOptions(
name='bug',
options={
'permissions': (
('add_bugtag', 'can add bug tag'), ('delete_bugtag', 'can delete bug tag')
)
},
),
]
7 changes: 7 additions & 0 deletions tcms/bugs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.conf import settings
from django.db import models
from django.urls import reverse
from django.utils.translation import gettext_lazy as _

from tcms.core.models.base import UrlMixin

Expand Down Expand Up @@ -32,6 +33,12 @@ class Bug(models.Model, UrlMixin):
executions = models.ManyToManyField('testruns.TestExecution', related_name='bugs')
tags = models.ManyToManyField('management.Tag', related_name='bugs')

class Meta:
permissions = (
('add_bugtag', _('can add bug tag')),
('delete_bugtag', _('can delete bug tag')),
)

def __str__(self):
return "BUG-%d: %s " % (self.pk, self.summary)

Expand Down
9 changes: 9 additions & 0 deletions tcms/bugs/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
if 'tcms.bugs.apps.AppConfig' not in settings.INSTALLED_APPS:
raise unittest.SkipTest('tcms.bugs is disabled')

from django.contrib.auth.models import Permission # noqa: E402
from django.template.loader import render_to_string # noqa: E402
from django.test import TestCase # noqa: E402
from django.utils.translation import gettext_lazy as _ # noqa: E402
Expand Down Expand Up @@ -47,3 +48,11 @@ def test_no_notification_if_assignee_not_set(self, send_mail):
BugFactory(assignee=None)

self.assertFalse(send_mail.called)


class TestBugTagPermissions(TestCase):
def test_add_bugtag(self):
self.assertTrue(Permission.objects.filter(codename='add_bugtag'))

def test_delete_bugtag(self):
self.assertTrue(Permission.objects.filter(codename='delete_bugtag'))

0 comments on commit a0833d8

Please sign in to comment.