Skip to content

Commit

Permalink
Make teams an org feature.. that nobody has for now
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Oct 28, 2024
1 parent a7dcb61 commit 9d00908
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 16 deletions.
2 changes: 2 additions & 0 deletions temba/orgs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,12 @@ class Org(SmartModel):
FEATURE_USERS = "users" # can invite users to this org
FEATURE_NEW_ORGS = "new_orgs" # can create new workspace with same login
FEATURE_CHILD_ORGS = "child_orgs" # can create child workspaces of this org
FEATURE_TEAMS = "teams" # can create teams to organize agent users
FEATURES_CHOICES = (
(FEATURE_USERS, _("Users")),
(FEATURE_NEW_ORGS, _("New Orgs")),
(FEATURE_CHILD_ORGS, _("Child Orgs")),
(FEATURE_TEAMS, _("Teams")),
)

LIMIT_CHANNELS = "channels"
Expand Down
14 changes: 10 additions & 4 deletions temba/orgs/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1657,8 +1657,8 @@ def test_workspace(self):
],
)

# enable child workspaces and users
self.org.features = [Org.FEATURE_USERS, Org.FEATURE_CHILD_ORGS]
# enable child workspaces, users and teams
self.org.features = [Org.FEATURE_USERS, Org.FEATURE_CHILD_ORGS, Org.FEATURE_TEAMS]
self.org.save(update_fields=("features",))

self.child_org = Org.objects.create(
Expand Down Expand Up @@ -2824,16 +2824,22 @@ def test_list(self):
def test_team(self):
team_url = reverse("orgs.user_team", args=[self.org.default_ticket_team.id])

# nobody can access if users feature not enabled
# nobody can access if teams feature not enabled
response = self.requestView(team_url, self.admin)
self.assertRedirect(response, reverse("orgs.org_workspace"))

self.org.features = [Org.FEATURE_USERS]
self.org.features = [Org.FEATURE_TEAMS]
self.org.save(update_fields=("features",))

self.assertRequestDisallowed(team_url, [None, self.user, self.editor, self.agent])

self.assertListFetch(team_url, [self.admin], context_objects=[self.agent])
self.assertContentMenu(team_url, self.admin, []) # because it's a system team

team = Team.create(self.org, self.admin, "My Team")
team_url = reverse("orgs.user_team", args=[team.id])

self.assertContentMenu(team_url, self.admin, ["Edit", "Delete"])

def test_update(self):
update_url = reverse("orgs.user_update", args=[self.agent.id])
Expand Down
17 changes: 9 additions & 8 deletions temba/orgs/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def get_context_data(self, **kwargs):

class Team(RequireFeatureMixin, ContextMenuMixin, BaseListView):
permission = "orgs.user_list"
require_feature = Org.FEATURE_USERS
require_feature = Org.FEATURE_TEAMS
menu_path = "/settings/teams"
search_fields = ("email__icontains", "first_name__icontains", "last_name__icontains")

Expand Down Expand Up @@ -1064,14 +1064,15 @@ def derive_menu(self):
count=org.invitations.filter(is_active=True).count(),
)
)
menu.append(
self.create_menu_item(
name=_("Teams"),
icon="agent",
href="tickets.team_list",
count=org.teams.filter(is_active=True).count(),
if Org.FEATURE_TEAMS in org.features:
menu.append(
self.create_menu_item(
name=_("Teams"),
icon="agent",
href="tickets.team_list",
count=org.teams.filter(is_active=True).count(),
)
)
)

menu.append(self.create_divider())
if self.has_org_perm("orgs.org_export"):
Expand Down
16 changes: 15 additions & 1 deletion temba/tickets/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.utils import timezone

from temba.contacts.models import Contact, ContactField, ContactURN
from temba.orgs.models import Export, OrgMembership, OrgRole
from temba.orgs.models import Export, Org, OrgMembership, OrgRole
from temba.tests import CRUDLTestMixin, MigrationTest, TembaTest, matchers, mock_mailroom
from temba.utils.dates import datetime_to_timestamp
from temba.utils.uuid import uuid4
Expand Down Expand Up @@ -436,6 +436,13 @@ class TeamCRUDLTest(TembaTest, CRUDLTestMixin):
def test_create(self):
create_url = reverse("tickets.team_create")

# nobody can access if new orgs feature not enabled
response = self.requestView(create_url, self.admin)
self.assertRedirect(response, reverse("orgs.org_workspace"))

self.org.features = [Org.FEATURE_TEAMS]
self.org.save(update_fields=("features",))

self.assertRequestDisallowed(create_url, [None, self.agent, self.user, self.editor])

self.assertCreateFetch(create_url, [self.admin], form_fields=("name", "topics"))
Expand Down Expand Up @@ -557,6 +564,13 @@ def test_list(self):

list_url = reverse("tickets.team_list")

# nobody can access if new orgs feature not enabled
response = self.requestView(list_url, self.admin)
self.assertRedirect(response, reverse("orgs.org_workspace"))

self.org.features = [Org.FEATURE_TEAMS]
self.org.save(update_fields=("features",))

self.assertRequestDisallowed(list_url, [None, self.agent, self.editor])

self.assertListFetch(list_url, [self.admin], context_objects=[self.org.default_ticket_team, team2, team1])
Expand Down
9 changes: 6 additions & 3 deletions temba/tickets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from temba.msgs.models import Msg
from temba.notifications.views import NotificationTargetMixin
from temba.orgs.models import Org
from temba.orgs.views.base import (
BaseCreateModal,
BaseDeleteModal,
Expand All @@ -21,7 +22,7 @@
BaseMenuView,
BaseUpdateModal,
)
from temba.orgs.views.mixins import OrgObjPermsMixin, OrgPermsMixin
from temba.orgs.views.mixins import OrgObjPermsMixin, OrgPermsMixin, RequireFeatureMixin
from temba.utils.dates import datetime_to_timestamp, timestamp_to_datetime
from temba.utils.export import response_from_workbook
from temba.utils.fields import InputWidget
Expand Down Expand Up @@ -112,7 +113,8 @@ class TeamCRUDL(SmartCRUDL):
model = Team
actions = ("create", "update", "delete", "list")

class Create(BaseCreateModal):
class Create(RequireFeatureMixin, BaseCreateModal):
require_feature = Org.FEATURE_TEAMS
form_class = TeamForm
success_url = "@tickets.team_list"

Expand All @@ -127,7 +129,8 @@ class Delete(BaseDeleteModal):
cancel_url = "[email protected]_team"
redirect_url = "@tickets.team_list"

class List(ContextMenuMixin, BaseListView):
class List(RequireFeatureMixin, ContextMenuMixin, BaseListView):
require_feature = Org.FEATURE_TEAMS
menu_path = "/settings/teams"

def derive_queryset(self, **kwargs):
Expand Down

0 comments on commit 9d00908

Please sign in to comment.