Skip to content

Commit

Permalink
Merge pull request #5774 from nyaruka/remove_viewers
Browse files Browse the repository at this point in the history
Data migration to remove viewers from workspaces
  • Loading branch information
rowanseymour authored Jan 9, 2025
2 parents dc754a9 + 9659db0 commit c9ec873
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
17 changes: 17 additions & 0 deletions temba/orgs/migrations/0164_remove_viewers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.1.4 on 2025-01-08 20:51

from django.db import migrations


def remove_viewers(apps, schema_editor):
OrgMembership = apps.get_model("orgs", "OrgMembership")
num_deleted = OrgMembership.objects.filter(role_code="V").delete()[0]
if num_deleted:
print(f"Deleted {num_deleted} viewer memberships")


class Migration(migrations.Migration):

dependencies = [("orgs", "0163_squashed")]

operations = [migrations.RunPython(remove_viewers, migrations.RunPython.noop)]
10 changes: 10 additions & 0 deletions temba/orgs/tests/test_migrations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from temba.tests import MigrationTest


class RemoveViewersTest(MigrationTest):
app = "orgs"
migrate_from = "0163_squashed"
migrate_to = "0164_remove_viewers"

def test_migration(self):
self.assertEqual({self.admin, self.editor, self.agent}, set(self.org.get_users()))
1 change: 0 additions & 1 deletion temba/orgs/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ def get_context_data(self, **kwargs):
user.role = membership.role
user.team = membership.team

context["has_viewers"] = self.request.org.get_users(roles=[OrgRole.VIEWER]).exists()
context["has_teams"] = Org.FEATURE_TEAMS in self.request.org.features

admins = self.request.org.get_users(roles=[OrgRole.ADMINISTRATOR])
Expand Down
10 changes: 0 additions & 10 deletions templates/orgs/user_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@
<temba-modax header="{{ _("Remove User") |escapejs }}" -temba-redirected="refreshUsers" id="delete-user">
</temba-modax>
{% endblock modaxes %}
{% block pre-table %}
{% if has_viewers %}
<temba-alert level="warning" class="mb-4">
{% blocktrans trimmed with cutoff="2024-12-31"|day %}
The <i>Viewer</i> role for users is being removed. Please update any users with that role or remove from your
workspace. After <b>{{ cutoff }}</b> these users will no longer be able to access the workspace.
{% endblocktrans %}
</temba-alert>
{% endif %}
{% endblock pre-table %}
{% block table %}
<table class="list lined scrolled">
<thead>
Expand Down

0 comments on commit c9ec873

Please sign in to comment.