diff options
author | Richard Jones <r1chardj0n3s@gmail.com> | 2015-09-11 16:10:06 +1000 |
---|---|---|
committer | Richard Jones <r1chardj0n3s@gmail.com> | 2015-09-14 13:07:49 +1000 |
commit | 8c64de92f4148d85704b10ea1f7bc441db2ddfee (patch) | |
tree | f9aa8595a2ea08c7b39325de056719ed7fae69af | |
parent | 87f2158899ddea28fb6e8387889a29ee4d026fd9 (diff) | |
download | django_openstack_auth-8c64de92f4148d85704b10ea1f7bc441db2ddfee.tar.gz |
Replace default User model PK
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
-rw-r--r-- | openstack_auth/models.py | 15 | ||||
-rw-r--r-- | openstack_auth/user.py | 6 |
2 files changed, 21 insertions, 0 deletions
diff --git a/openstack_auth/models.py b/openstack_auth/models.py new file mode 100644 index 0000000..76cfc2a --- /dev/null +++ b/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 diff --git a/openstack_auth/user.py b/openstack_auth/user.py index 72c8638..dd68b0f 100644 --- a/openstack_auth/user.py +++ b/openstack_auth/user.py @@ -16,6 +16,7 @@ import logging 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 @@ -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, @@ -199,6 +204,7 @@ class User(models.AbstractBaseUser, models.AnonymousUser): 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 |