-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11402 from camptocamp/GSBLGEOS-35-add-user-display
Add display name in the user for better OpenID Connect support
- Loading branch information
Showing
9 changed files
with
99 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,6 +166,7 @@ def test_submit_update(self, pw_gen_mock, smtp_mock, dbsession, test_app, users_ | |
("item_type", "user"), | ||
("id", user.id), | ||
("username", "new_name_withéàô"), | ||
("display_name", "New name withéàô"), | ||
("email", "[email protected]"), | ||
("settings_role_id", roles[2].id), | ||
("__start__", "roles:sequence"), | ||
|
@@ -271,6 +272,7 @@ def test_submit_new(self, pw_gen_mock, smtp_mock, dbsession, test_app, users_tes | |
("item_type", "user"), | ||
("id", ""), | ||
("username", "new_user"), | ||
("display_name", "New user"), | ||
("email", "[email protected]"), | ||
("settings_role_id", roles[2].id), | ||
), | ||
|
@@ -284,6 +286,7 @@ def test_submit_new(self, pw_gen_mock, smtp_mock, dbsession, test_app, users_tes | |
).group(1) | ||
|
||
assert user.username == "new_user" | ||
assert user.display_name == "New user" | ||
assert user.email == "[email protected]" | ||
assert user.settings_role_id == roles[2].id | ||
assert user.password is not None and len(user.password) | ||
|
@@ -315,6 +318,7 @@ def test_invalid_email(self, test_app): | |
"item_type": "user", | ||
"id": "", | ||
"username": "invalid_email", | ||
"display_name": "Invalid email", | ||
"email": "new_mail", | ||
"role_name": "secretary_2", | ||
"is_password_changed": "false", | ||
|
61 changes: 61 additions & 0 deletions
61
...geoportal_commons/alembic/static/267b4c1bde2e_add_display_name_in_the_user_for_better_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Copyright (c) 2024, Camptocamp SA | ||
# All rights reserved. | ||
|
||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
|
||
# 1. Redistributions of source code must retain the above copyright notice, this | ||
# list of conditions and the following disclaimer. | ||
# 2. Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
|
||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
# The views and conclusions contained in the software and documentation are those | ||
# of the authors and should not be interpreted as representing official policies, | ||
# either expressed or implied, of the FreeBSD Project. | ||
|
||
""" | ||
Add display name in the user for better OpenID Connect support. | ||
Revision ID: 267b4c1bde2e | ||
Revises: aa41e9613256 | ||
Create Date: 2024-10-02 14:33:59.185133 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from c2c.template.config import config | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "267b4c1bde2e" | ||
down_revision = "aa41e9613256" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
"""Upgrade.""" | ||
staticschema = config["schema_static"] | ||
|
||
op.add_column("user", sa.Column("display_name", sa.Unicode(), nullable=True), schema=staticschema) | ||
op.execute(f'UPDATE {staticschema}."user" SET display_name = username') | ||
op.alter_column("user", "display_name", nullable=False, schema=staticschema) | ||
|
||
|
||
def downgrade() -> None: | ||
"""Downgrade.""" | ||
staticschema = config["schema_static"] | ||
|
||
op.drop_column("user", "display_name", schema=staticschema) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -320,6 +320,7 @@ def __init__(self, name, functionalities): | |
|
||
class U: | ||
username = "__test_user" | ||
display_name = "Test User" | ||
is_password_changed = True | ||
email = "[email protected]" | ||
settings_role = None | ||
|
@@ -332,7 +333,7 @@ def __init__(self, role="__test_role", functionalities=None): | |
request.user = U() | ||
login = Login(request) | ||
expected = { | ||
"username": "__test_user", | ||
"username": "Test User", | ||
"email": "[email protected]", | ||
"is_intranet": False, | ||
"login_type": "local", | ||
|
@@ -350,7 +351,7 @@ class F: | |
del request.response.headers["Vary"] | ||
login = Login(request) | ||
expected = { | ||
"username": "__test_user", | ||
"username": "Test User", | ||
"email": "[email protected]", | ||
"is_intranet": False, | ||
"login_type": "local", | ||
|
@@ -392,6 +393,7 @@ def __init__(self, name, functionalities): | |
|
||
class U: | ||
username = "__test_user" | ||
display_name = "Test User" | ||
is_password_changed = True | ||
email = "[email protected]" | ||
|
||
|
@@ -407,13 +409,13 @@ def __init__(self, role="__test_role", functionalities=None): | |
self.assertEqual( | ||
login.loginuser(), | ||
{ | ||
"username": "Test User", | ||
"email": "[email protected]", | ||
"functionalities": {}, | ||
"is_intranet": False, | ||
"login_type": "local", | ||
"roles": [{"id": 123, "name": "__test_role"}], | ||
"two_factor_enable": False, | ||
"username": "__test_user", | ||
}, | ||
) | ||
|
||
|
@@ -422,13 +424,13 @@ def __init__(self, role="__test_role", functionalities=None): | |
self.assertEqual( | ||
login.loginuser(), | ||
{ | ||
"username": "Test User", | ||
"email": "[email protected]", | ||
"functionalities": {}, | ||
"is_intranet": True, | ||
"login_type": "local", | ||
"roles": [{"id": 123, "name": "__test_role"}], | ||
"two_factor_enable": False, | ||
"username": "__test_user", | ||
}, | ||
) | ||
|
||
|