Skip to content
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

Adds a management command to disable all users on apart from hard coded ones #1417

Open
wants to merge 1 commit into
base: v0.107.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions elcid/management/commands/disable_non_test_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User

test_users = [
"ohc", "emmanuel.wey"
]


class Command(BaseCommand):
def handle(self, *args, **options):
User.objects.exclude(username__in=test_users).update(
is_active=False
)
22 changes: 22 additions & 0 deletions elcid/test/test_disable_non_test_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from opal.core.test import OpalTestCase
from django.contrib.auth.models import User
from elcid.management.commands.disable_non_test_users import Command


class DisableNonTestUsersTestCase(OpalTestCase):
def setUp(self):
self.cmd = Command()

def test_disables_users(self):
User.objects.create(username='someone')
self.cmd.handle()
self.assertFalse(
User.objects.get(username='someone').is_active
)

def test_except_certain_users(self):
User.objects.create(username='ohc')
self.cmd.handle()
self.assertTrue(
User.objects.get(username='ohc').is_active
)