forked from rapidpro/rapidpro
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement filtering of tickets by accessible topics #5593
Merged
+75
−20
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -581,19 +581,36 @@ def setUp(self): | |
super().setUp() | ||
|
||
self.contact = self.create_contact("Bob", urns=["twitter:bobby"]) | ||
self.sales = Topic.create(self.org, self.admin, "Sales") | ||
self.support = Topic.create(self.org, self.admin, "Support") | ||
|
||
# create other agent users in teams with limited topic access | ||
self.agent2 = self.create_user("[email protected]") | ||
sales_only = Team.create(self.org, self.admin, "Sales", topics=[self.sales]) | ||
self.org.add_user(self.agent2, OrgRole.AGENT, team=sales_only) | ||
|
||
self.agent3 = self.create_user("[email protected]") | ||
support_only = Team.create(self.org, self.admin, "Support", topics=[self.support]) | ||
self.org.add_user(self.agent3, OrgRole.AGENT, team=support_only) | ||
|
||
def test_list(self): | ||
list_url = reverse("tickets.ticket_list") | ||
ticket = self.create_ticket(self.contact, assignee=self.admin) | ||
|
||
ticket = self.create_ticket(self.contact, assignee=self.admin, topic=self.support) | ||
|
||
# just a placeholder view for frontend components | ||
self.assertRequestDisallowed(list_url, [None]) | ||
self.assertListFetch(list_url, [self.user, self.editor, self.admin, self.agent], context_objects=[]) | ||
self.assertListFetch( | ||
list_url, [self.user, self.editor, self.admin, self.agent, self.agent2, self.agent3], context_objects=[] | ||
) | ||
|
||
# link to our ticket within the All folder | ||
deep_link = f"{list_url}all/open/{str(ticket.uuid)}/" | ||
deep_link = f"{list_url}all/open/{ticket.uuid}/" | ||
|
||
response = self.assertListFetch(deep_link, [self.user, self.editor, self.admin, self.agent], context_objects=[]) | ||
response = self.assertListFetch( | ||
deep_link, [self.user, self.editor, self.admin, self.agent, self.agent3], context_objects=[] | ||
) | ||
self.assertEqual("All", response.context["title"]) | ||
self.assertEqual("all", response.context["folder"]) | ||
self.assertEqual("open", response.context["status"]) | ||
|
||
|
@@ -606,12 +623,39 @@ def test_list(self): | |
with self.assertNumQueries(11): | ||
self.client.get(deep_link) | ||
|
||
# try to link to our ticket but with mismatched status | ||
deep_link = f"{list_url}all/closed/{str(ticket.uuid)}/" | ||
# try same request but for agent that can't see this ticket | ||
response = self.assertListFetch(deep_link, [self.agent2], context_objects=[]) | ||
self.assertEqual("All", response.context["title"]) | ||
self.assertEqual("all", response.context["folder"]) | ||
self.assertEqual("open", response.context["status"]) | ||
self.assertNotIn("nextUUID", response.context) | ||
|
||
# can also link to our ticket within the Support topic | ||
deep_link = f"{list_url}{self.support.uuid}/open/{ticket.uuid}/" | ||
|
||
self.assertRequestDisallowed(deep_link, [self.agent2]) # doesn't have access to that topic | ||
|
||
response = self.assertListFetch( | ||
deep_link, [self.user, self.editor, self.admin, self.agent, self.agent3], context_objects=[] | ||
) | ||
self.assertEqual("Support", response.context["title"]) | ||
self.assertEqual(str(self.support.uuid), response.context["folder"]) | ||
self.assertEqual("open", response.context["status"]) | ||
|
||
# try to link to our ticket but with mismatched topic | ||
deep_link = f"{list_url}{self.sales.uuid}/closed/{str(ticket.uuid)}/" | ||
|
||
# redirected to All | ||
response = self.assertListFetch(deep_link, [self.agent], context_objects=[]) | ||
self.assertEqual("all", response.context["folder"]) | ||
self.assertEqual("open", response.context["status"]) | ||
self.assertEqual(str(ticket.uuid), response.context["uuid"]) | ||
|
||
# try to link to our ticket but with mismatched status | ||
deep_link = f"{list_url}all/closed/{ticket.uuid}/" | ||
|
||
# now our ticket is listed as the uuid and we were redirected to All folder with Open status | ||
response = self.assertListFetch(deep_link, [self.agent], context_objects=[]) | ||
self.assertEqual("all", response.context["folder"]) | ||
self.assertEqual("open", response.context["status"]) | ||
self.assertEqual(str(ticket.uuid), response.context["uuid"]) | ||
|
@@ -620,7 +664,7 @@ def test_list(self): | |
self.assertContentMenu(deep_link, self.admin, ["Edit", "Add Note", "Start Flow"]) | ||
|
||
# non-existent topic should give a 404 | ||
bad_topic_link = f"{list_url}{uuid4()}/open/{str(ticket.uuid)}/" | ||
bad_topic_link = f"{list_url}{uuid4()}/open/{ticket.uuid}/" | ||
response = self.requestView(bad_topic_link, self.agent) | ||
self.assertEqual(404, response.status_code) | ||
|
||
|
@@ -629,7 +673,6 @@ def test_list(self): | |
content_type="application/json", | ||
HTTP_TEMBA_REFERER_PATH=f"/tickets/mine/open/{ticket.uuid}", | ||
) | ||
|
||
self.assertEqual(("tickets", "mine", "open", str(ticket.uuid)), response.context["temba_referer"]) | ||
|
||
# contacts in a flow get interrupt menu option instead | ||
|
@@ -665,7 +708,7 @@ def test_menu(self): | |
menu_url = reverse("tickets.ticket_menu") | ||
|
||
self.create_ticket(self.contact, assignee=self.admin) | ||
self.create_ticket(self.contact, assignee=self.admin) | ||
self.create_ticket(self.contact, assignee=self.admin, topic=self.sales) | ||
self.create_ticket(self.contact, assignee=None) | ||
self.create_ticket(self.contact, closed_on=timezone.now()) | ||
|
||
|
@@ -680,10 +723,18 @@ def test_menu(self): | |
"Shortcuts (0)", | ||
"Export", | ||
"New Topic", | ||
"General (3)", | ||
"General (2)", | ||
"Sales (1)", | ||
"Support (0)", | ||
], | ||
) | ||
self.assertPageMenu(menu_url, self.agent, ["My Tickets (0)", "Unassigned (1)", "All (3)", "General (3)"]) | ||
self.assertPageMenu( | ||
menu_url, | ||
self.agent, | ||
["My Tickets (0)", "Unassigned (1)", "All (3)", "General (2)", "Sales (1)", "Support (0)"], | ||
) | ||
self.assertPageMenu(menu_url, self.agent2, ["My Tickets (0)", "Unassigned (1)", "All (3)", "Sales (1)"]) | ||
self.assertPageMenu(menu_url, self.agent3, ["My Tickets (0)", "Unassigned (1)", "All (3)", "Support (0)"]) | ||
|
||
@mock_mailroom | ||
def test_folder(self, mr_mocks): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ericnewcomer @norkans7
All (3)
here has wrong count for this user.. need to rework how we do ticket counts so they can be calculated over the set of topics that a user can access.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that counts is accurate as the agent can access all those tickets (even those assigned to others)
I guess we add a folder for
My topics
/My teams
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@norkans7 they can't.. as of this PR. This PR filters all tickets by the topics a user has access to.