Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
Replace default User model PK
Browse files Browse the repository at this point in the history
The default Django User model PK is an int() AutoField
and django-openstack-auth sets this to a hash string. Django
then breaks trying to coerce that string to an int().

This patch adds a new explicit PK to the d-o-a User
model. It also adds the standard Django "models.py" so
that the consumer application (Horizon) may use it.

The consumer application must set:

   AUTH_USER_MODEL = 'openstack_auth.User'

to use the new model in place of the default 'auth.User'.

The approach in this patch was inspired by Lin Hua
Cheng <os.lcheng@gmail.com>.

Partial-Bug: 1491117
Change-Id: I549209eb0bb0ddf36d92ee9dc1a9bac799ce67e5
  • Loading branch information
r1chardj0n3s committed Sep 14, 2015
1 parent 87f2158 commit 8c64de9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions openstack_auth/models.py
@@ -0,0 +1,15 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# import the User model in here so Django can find it
from openstack_auth.user import User # noqa
6 changes: 6 additions & 0 deletions openstack_auth/user.py
Expand Up @@ -16,6 +16,7 @@

from django.conf import settings
from django.contrib.auth import models
from django.db import models as db_models
from keystoneclient.common import cms as keystone_cms
from keystoneclient import exceptions as keystone_exceptions
import six
Expand Down Expand Up @@ -189,6 +190,10 @@ class User(models.AbstractBaseUser, models.AnonymousUser):
Unscoped Keystone token.
"""

keystone_user_id = db_models.CharField(primary_key=True, max_length=256)
USERNAME_FIELD = 'keystone_user_id'

def __init__(self, id=None, token=None, user=None, tenant_id=None,
service_catalog=None, tenant_name=None, roles=None,
authorized_tenants=None, endpoint=None, enabled=False,
Expand All @@ -199,6 +204,7 @@ def __init__(self, id=None, token=None, user=None, tenant_id=None,
self.id = id
self.pk = id
self.token = token
self.keystone_user_id = id
self.username = user
self.user_domain_id = user_domain_id
self.user_domain_name = user_domain_name
Expand Down

0 comments on commit 8c64de9

Please sign in to comment.