misc: add a nameid property to users (#85345)
gitea/combo/pipeline/head This commit looks good
Details
gitea/combo/pipeline/head This commit looks good
Details
This commit is contained in:
parent
1d22ba93b0
commit
a2ae3a5860
|
@ -41,6 +41,7 @@ class AppConfig(django.apps.AppConfig):
|
|||
from django.contrib.auth import get_user_model
|
||||
|
||||
get_user_model().add_to_class('get_name_id', user_get_name_id)
|
||||
get_user_model().add_to_class('nameid', property(user_get_name_id))
|
||||
|
||||
def get_search_engines(self):
|
||||
from django.conf import settings
|
||||
|
|
|
@ -30,7 +30,7 @@ class ProxiedUser:
|
|||
is_anonymous = False
|
||||
|
||||
def __init__(self, name_id):
|
||||
self.name_id = name_id
|
||||
self.name_id = self.nameid = name_id
|
||||
self.email = ''
|
||||
|
||||
def get_name_id(self):
|
||||
|
|
|
@ -3,6 +3,7 @@ import json
|
|||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import override_settings
|
||||
|
||||
from combo.data.models import Page
|
||||
|
@ -46,3 +47,11 @@ def test_profile_cell(requests_get, app, admin_user):
|
|||
requests_get.return_value = mock.Mock(content=json.dumps(data), json=lambda: data, status_code=200)
|
||||
context = cell.get_cell_extra_context({'synchronous': True, 'selected_user': admin_user})
|
||||
assert context['profile_fields']['phone']['value'] == '+336a23c5678'
|
||||
|
||||
|
||||
def test_user_nameid_property():
|
||||
user = get_user_model().objects.create(
|
||||
username='john.doe', first_name='John', last_name='Doe', email='john.doe@example.net'
|
||||
)
|
||||
user._name_id = 'abcd' # fake cached nameid
|
||||
assert user.nameid == 'abcd'
|
||||
|
|
Loading…
Reference in New Issue