Skip to content

Commit

Permalink
Merge pull request #964 from regiov/pinax-remove
Browse files Browse the repository at this point in the history
Remove hard dependency on pinax teams
  • Loading branch information
gwasser committed Aug 5, 2021
2 parents 9fd5d46 + 563b28e commit 9c6e857
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 14 deletions.
2 changes: 2 additions & 0 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ errors with trying to create User settings.
'reversion', # required by pinax-teams
)

Note: you do not need to use pinax-teams. To dissable teams see the :doc:`teams` section.

Your ``settings.py`` file should also define a ``SITE_ID`` that allows multiple projects to share
a single database, and is required by ``django.contrib.sites`` in Django 1.9+.
If you aren't running multiple sites, you can simply add a default ``SITE_ID`` to ``settings.py``::
Expand Down
2 changes: 2 additions & 0 deletions docs/teams.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ You can visit the 'Pinax Teams' page in your django admin in order to create a t
You can assign a knowledge-base item to a team on the Helpdesk admin page.

Once you have set up teams. Unassigned tickets which are associated with a knowledge-base item will only be shown on the dashboard to those users who are members of the team which is associated with that knowledge-base item.

Note: It is possible that pinax-teams will interfere with other packages that you already use in your project. If you do not wish to use team functionality, you can dissable teams by setting the following settings: ``HELPDESK_TEAMS_MODEL`` to any random model, ``HELPDESK_TEAMS_MIGRATION_DEPENDENCIES`` to ``[]``, and ``HELPDESK_KBITEM_TEAM_GETTER`` to ``lambda _: None``. You can also use a different library in place of pinax teams by setting those settings appropriately. ``HELPDESK_KBITEM_TEAM_GETTER`` should take a ``kbitem`` and return a team object with a ``name`` property and a method ``is_member(self, user)`` which returns true if user is a member of the team.
7 changes: 4 additions & 3 deletions helpdesk/migrations/0028_kbitem_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
from django.db import migrations, models
import django.db.models.deletion

from helpdesk import settings as helpdesk_settings


class Migration(migrations.Migration):

dependencies = [
('pinax_teams', '0004_auto_20170511_0856'),
('helpdesk', '0027_auto_20200107_1221'),
]
] + helpdesk_settings.HELPDESK_TEAMS_MIGRATION_DEPENDENCIES

operations = [
migrations.AddField(
model_name='kbitem',
name='team',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='pinax_teams.Team', verbose_name='Team'),
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=helpdesk_settings.HELPDESK_TEAMS_MODEL, verbose_name='Team'),
),
]
7 changes: 4 additions & 3 deletions helpdesk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
from markdown import markdown
from markdown.extensions import Extension

import pinax.teams.models


import uuid

Expand Down Expand Up @@ -1363,7 +1361,7 @@ class KBItem(models.Model):
)

team = models.ForeignKey(
pinax.teams.models.Team,
helpdesk_settings.HELPDESK_TEAMS_MODEL,
on_delete=models.CASCADE,
verbose_name=_('Team'),
blank=True,
Expand All @@ -1386,6 +1384,9 @@ def save(self, *args, **kwargs):
self.last_updated = timezone.now()
return super(KBItem, self).save(*args, **kwargs)

def get_team(self):
return helpdesk_settings.HELPDESK_KBITEM_TEAM_GETTER(self)

def _score(self):
""" Return a score out of 10 or Unrated if no votes """
if self.votes > 0:
Expand Down
5 changes: 5 additions & 0 deletions helpdesk/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@
# use https in the email links
HELPDESK_USE_HTTPS_IN_EMAIL_LINK = getattr(settings, 'HELPDESK_USE_HTTPS_IN_EMAIL_LINK', False)

HELPDESK_TEAMS_MODEL = getattr(settings, 'HELPDESK_TEAMS_MODEL', 'pinax_teams.Team')
HELPDESK_TEAMS_MIGRATION_DEPENDENCIES = getattr(settings, 'HELPDESK_TEAMS_MIGRATION_DEPENDENCIES', [('pinax_teams', '0004_auto_20170511_0856')])
HELPDESK_KBITEM_TEAM_GETTER = getattr(settings, 'HELPDESK_KBITEM_TEAM_GETTER', lambda kbitem: kbitem.team)

# Include all signatures and forwards in the first ticket message if set
# Useful if you get forwards dropped from them while they are useful part of request
HELPDESK_FULL_FIRST_MESSAGE_FROM_EMAIL = getattr(settings, 'HELPDESK_FULL_FIRST_MESSAGE_FROM_EMAIL', False)
Expand All @@ -174,3 +178,4 @@
# which is quite noisy but very helpful for complicated markup, forwards and so on
# (which gets stripped/corrupted otherwise)
HELPDESK_ALWAYS_SAVE_INCOMING_EMAIL_MESSAGE = getattr(settings, "HELPDESK_ALWAYS_SAVE_INCOMING_EMAIL_MESSAGE", False)

2 changes: 1 addition & 1 deletion helpdesk/templates/helpdesk/include/unassigned.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<div class="card mb-3">
<div class="card-header">
<i class="fas fa-table"></i>
{% trans "KBItem:" %} {{kbitem.title}} {% trans "Team:" %} {{kbitem.team.name}} {% trans "(pick up a ticket if you start to work on it)" %}
{% trans "KBItem:" %} {{kbitem.title}} {% trans "Team:" %} {{kbitem.get_team.name}} {% trans "(pick up a ticket if you start to work on it)" %}
</div>
<div class="card-body">
<div class="table-responsive">
Expand Down
2 changes: 1 addition & 1 deletion helpdesk/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_allowed_kb_categories(self):
def get_assigned_kb_items(self):
kbitems = []
for item in KBItem.objects.all():
if item.team and item.team.is_member(self.user):
if item.get_team() and item.get_team().is_member(self.user):
kbitems.append(item)
return kbitems

Expand Down
16 changes: 11 additions & 5 deletions quicktest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ class QuickDjangoTest(object):
'django.contrib.sites',
'django.contrib.staticfiles',
'bootstrap4form',
'account',
'pinax.invitations',
'pinax.teams',
## The following commented apps are optional,
## related to teams functionalities
#'account',
#'pinax.invitations',
#'pinax.teams',
'helpdesk',
'reversion',
#'reversion',
)
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
Expand Down Expand Up @@ -97,7 +99,11 @@ def _tests(self):
STATIC_URL='/static/',
LOGIN_URL='/helpdesk/login/',
TEMPLATES=self.TEMPLATES,
SITE_ID=1
SITE_ID=1,
## The following settings disable teams
HELPDESK_TEAMS_MODEL = 'auth.User',
HELPDESK_TEAMS_MIGRATION_DEPENDENCIES = [],
HELPDESK_KBITEM_TEAM_GETTER = lambda _: None
)

from django.test.runner import DiscoverRunner
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ pytz
six
djangorestframework
django-model-utils
pinax-teams>=2.0

0 comments on commit 9c6e857

Please sign in to comment.