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

Commit 8c64de9

Browse files
committed
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
1 parent 87f2158 commit 8c64de9

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

openstack_auth/models.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
10+
# implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
# import the User model in here so Django can find it
15+
from openstack_auth.user import User # noqa

openstack_auth/user.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from django.conf import settings
1818
from django.contrib.auth import models
19+
from django.db import models as db_models
1920
from keystoneclient.common import cms as keystone_cms
2021
from keystoneclient import exceptions as keystone_exceptions
2122
import six
@@ -189,6 +190,10 @@ class User(models.AbstractBaseUser, models.AnonymousUser):
189190
Unscoped Keystone token.
190191
191192
"""
193+
194+
keystone_user_id = db_models.CharField(primary_key=True, max_length=256)
195+
USERNAME_FIELD = 'keystone_user_id'
196+
192197
def __init__(self, id=None, token=None, user=None, tenant_id=None,
193198
service_catalog=None, tenant_name=None, roles=None,
194199
authorized_tenants=None, endpoint=None, enabled=False,
@@ -199,6 +204,7 @@ def __init__(self, id=None, token=None, user=None, tenant_id=None,
199204
self.id = id
200205
self.pk = id
201206
self.token = token
207+
self.keystone_user_id = id
202208
self.username = user
203209
self.user_domain_id = user_domain_id
204210
self.user_domain_name = user_domain_name

0 commit comments

Comments
 (0)