From 8798ee0f5340677afd9952e9e8b9008d0c780355 Mon Sep 17 00:00:00 2001 From: Ahsan Ulhaq Date: Thu, 7 Jan 2016 16:20:28 +0500 Subject: [PATCH] Add credentials service user --- cms/envs/test.py | 1 + lms/envs/common.py | 3 ++ lms/envs/test.py | 1 + .../migrations/0003_data__add_service_user.py | 34 +++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 openedx/core/djangoapps/credentials/migrations/0003_data__add_service_user.py diff --git a/cms/envs/test.py b/cms/envs/test.py index 89c4586016..659b97227f 100644 --- a/cms/envs/test.py +++ b/cms/envs/test.py @@ -132,6 +132,7 @@ DATABASES = { # This hack disables migrations during tests. We want to create tables directly from the models for speed. # See https://groups.google.com/d/msg/django-developers/PWPj3etj3-U/kCl6pMsQYYoJ. MIGRATION_MODULES = {app: "app.migrations_not_used_in_tests" for app in INSTALLED_APPS} +MIGRATION_MODULES["credentials"] = "app.migrations_not_used_in_tests" LMS_BASE = "localhost:8000" FEATURES['PREVIEW_LMS_BASE'] = "preview" diff --git a/lms/envs/common.py b/lms/envs/common.py index fd925c39be..48e622757c 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -2553,6 +2553,9 @@ ECOMMERCE_API_SIGNING_KEY = None ECOMMERCE_API_TIMEOUT = 5 ECOMMERCE_SERVICE_WORKER_USERNAME = 'ecommerce_worker' +# Credentials configuration +CREDENTIALS_SERVICE_USERNAME = 'credentials_service_user' + # Reverification checkpoint name pattern CHECKPOINT_PATTERN = r'(?P[^/]+)' diff --git a/lms/envs/test.py b/lms/envs/test.py index 2b58e02569..0617443bb5 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -190,6 +190,7 @@ DATABASES = { # This hack disables migrations during tests. We want to create tables directly from the models for speed. # See https://groups.google.com/d/msg/django-developers/PWPj3etj3-U/kCl6pMsQYYoJ. MIGRATION_MODULES = {app: "app.migrations_not_used_in_tests" for app in INSTALLED_APPS} +MIGRATION_MODULES["credentials"] = "app.migrations_not_used_in_tests" CACHES = { # This is the cache used for most things. diff --git a/openedx/core/djangoapps/credentials/migrations/0003_data__add_service_user.py b/openedx/core/djangoapps/credentials/migrations/0003_data__add_service_user.py new file mode 100644 index 0000000000..e1da00f4cc --- /dev/null +++ b/openedx/core/djangoapps/credentials/migrations/0003_data__add_service_user.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + +from django.conf import settings +from django.contrib.auth.models import User + + +def add_service_user(apps, schema_editor): + """Add service user.""" + user, created = User.objects.get_or_create(username=settings.CREDENTIALS_SERVICE_USERNAME, is_staff=True) + if created: + user.set_unusable_password() + user.save() + + +def remove_service_user(apps, schema_editor): + """Remove service user.""" + try: + User.objects.get(username=settings.CREDENTIALS_SERVICE_USERNAME).delete() + except User.DoesNotExist: + return + + +class Migration(migrations.Migration): + + dependencies = [ + ('credentials', '0002_credentialsapiconfig_cache_ttl'), + ] + + operations = [ + migrations.RunPython(add_service_user, remove_service_user), + ]