Skip to content

Commit

Permalink
Merge pull request #416 from lhhyung/master
Browse files Browse the repository at this point in the history
Add domain_display_name to reset password email for user added
  • Loading branch information
lhhyung authored Dec 17, 2024
2 parents 4ca342a + e052b73 commit 7aad2e1
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 40 deletions.
8 changes: 6 additions & 2 deletions src/spaceone/identity/manager/email_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def send_temporary_password_email(
self.smtp_connector.send_email(email, subject, email_contents)

def send_reset_password_email_when_user_added(
self, user_id, email, reset_password_link, language
self, domain_display_name, user_id, email, reset_password_link, language
):
service_name = self._get_service_name()
language_map_info = LANGUAGE_MAPPER.get(language, "default")
Expand All @@ -90,6 +90,7 @@ def send_reset_password_email_when_user_added(
f"reset_pwd_link_when_user_added_{language}.html"
)
email_contents = template.render(
domain_display_name=domain_display_name,
user_name=user_id,
reset_password_link=reset_password_link,
service_name=service_name,
Expand All @@ -99,13 +100,14 @@ def send_reset_password_email_when_user_added(
self.smtp_connector.send_email(email, subject, email_contents)

def send_temporary_password_email_when_user_added(
self, user_id, email, console_link, temp_password, language
self, domain_display_name, user_id, email, console_link, temp_password, language
):
service_name = self._get_service_name()
language_map_info = LANGUAGE_MAPPER.get(language, "default")

template = JINJA_ENV.get_template(f"temp_pwd_when_user_added_{language}.html")
email_contents = template.render(
domain_display_name=domain_display_name,
user_name=user_id,
temp_password=temp_password,
service_name=service_name,
Expand All @@ -117,6 +119,7 @@ def send_temporary_password_email_when_user_added(

def send_invite_email_when_external_user_added(
self,
domain_display_name: str,
user_id: str,
email: str,
console_link: str,
Expand All @@ -129,6 +132,7 @@ def send_invite_email_when_external_user_added(
template = JINJA_ENV.get_template(f"sso_invite_user_link_{language}.html")

email_contents = template.render(
domain_display_name=domain_display_name,
user_name=user_id,
auth_type=external_auth_provider,
service_name=service_name,
Expand Down
4 changes: 2 additions & 2 deletions src/spaceone/identity/service/job_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import random
import secrets
from datetime import datetime, timedelta
from typing import Union, List

Expand Down Expand Up @@ -958,7 +958,7 @@ def _get_location(result: dict, resource_group: str, sync_options: dict) -> list

@staticmethod
def _set_workspace_theme(tags: dict = None) -> dict:
theme = random.choice(WORKSPACE_COLORS_NAME)
theme = secrets.choice(WORKSPACE_COLORS_NAME)
if tags:
tags.update({"theme": theme})
else:
Expand Down
4 changes: 2 additions & 2 deletions src/spaceone/identity/service/user_profile_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import random
import secrets
import re
import string
from typing import Dict, List, Union
Expand Down Expand Up @@ -506,7 +506,7 @@ def _check_reset_password_eligibility(user_id, auth_type, email):
def _generate_temporary_password():
while True:
random_password = "".join(
random.choice(
secrets.choice(
string.ascii_uppercase + string.ascii_lowercase + string.digits
)
for _ in range(12)
Expand Down
49 changes: 33 additions & 16 deletions src/spaceone/identity/service/user_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import copy
import logging
import random
import secrets
import re
import string
from typing import Union
Expand Down Expand Up @@ -87,31 +87,34 @@ def create_user(self, params: dict) -> User:
"RESET_PASSWORD_TYPE", "ACCESS_TOKEN"
)

domain_name = self._get_domain_name(domain_id)
domain_display_name = self._get_domain_display_name(domain_id, domain_name)

if reset_password_type == "ACCESS_TOKEN":
identity_conf = config.get_global("IDENTITY", {}) or {}
token_conf = identity_conf.get("token", {})
timeout = token_conf.get("invite_token_timeout", 604800)

token = self._issue_temporary_token(user_id, domain_id, timeout)
reset_password_link = self._get_console_sso_url(
domain_id, token["access_token"]
domain_name, token["access_token"]
)

params["required_actions"] = ["UPDATE_PASSWORD"]

user_vo = self.user_mgr.create_user(params)
user_id = user_vo.user_id
email_manager.send_reset_password_email_when_user_added(
user_id, email, reset_password_link, language
domain_display_name, user_id, email, reset_password_link, language
)
else:
console_link = self._get_console_url(domain_id)
console_link = self._get_console_url(domain_name)

user_vo = self.user_mgr.create_user(params)
user_id = user_vo.user_id

email_manager.send_temporary_password_email_when_user_added(
user_id, email, console_link, temp_password, language
domain_display_name, user_id, email, console_link, temp_password, language
)
else:
user_vo = self.user_mgr.create_user(params)
Expand All @@ -123,11 +126,14 @@ def create_user(self, params: dict) -> User:
):
email_mgr = EmailManager()

console_link = self._get_console_url(domain_id)
domain_name = self._get_domain_name(domain_id)
domain_display_name = self._get_domain_display_name(domain_id, domain_name)

console_link = self._get_console_url(domain_name)
external_auth_provider = self._get_external_auth_provider(domain_id)

email_mgr.send_invite_email_when_external_user_added(
user_id, user_id, console_link, language, external_auth_provider
domain_display_name, user_id, user_id, console_link, language, external_auth_provider
)

return user_vo
Expand Down Expand Up @@ -157,6 +163,7 @@ def update(self, params: UserUpdateRequest) -> Union[UserResponse, dict]:

if params.reset_password:
domain_id = params.domain_id
domain_name = self._get_domain_name(domain_id)
user_id = user_vo.user_id
auth_type = user_vo.auth_type
email = params.email or user_vo.email
Expand Down Expand Up @@ -184,14 +191,14 @@ def update(self, params: UserUpdateRequest) -> Union[UserResponse, dict]:
if reset_password_type == "ACCESS_TOKEN":
token = self._issue_temporary_token(user_id, domain_id)
reset_password_link = self._get_console_sso_url(
domain_id, token["access_token"]
domain_name, token["access_token"]
)

email_manager.send_reset_password_email(
user_id, email, reset_password_link, language
)
elif reset_password_type == "PASSWORD":
console_link = self._get_console_url(domain_id)
console_link = self._get_console_url(domain_name)

email_manager.send_temporary_password_email(
user_id, email, console_link, temp_password, language
Expand Down Expand Up @@ -475,9 +482,8 @@ def _issue_temporary_token(
user_id, domain_id, private_jwk, timeout=timeout
)

def _get_console_sso_url(self, domain_id: str, token: str) -> str:
domain_name = self._get_domain_name(domain_id)

@staticmethod
def _get_console_sso_url(domain_name: str, token: str) -> str:
console_domain = config.get_global("EMAIL_CONSOLE_DOMAIN")
console_domain = console_domain.format(domain_name=domain_name)

Expand All @@ -491,9 +497,8 @@ def _check_last_admin_user(self, domain_id: str, user_vo: User) -> None:
if user_vos.count() == 1:
raise ERROR_LAST_ADMIN_CANNOT_DISABLED_DELETED(user_id=user_vo.user_id)

def _get_console_url(self, domain_id):
domain_name = self._get_domain_name(domain_id)

@staticmethod
def _get_console_url(domain_name: str) -> str:
console_domain = config.get_global("EMAIL_CONSOLE_DOMAIN")
return console_domain.format(domain_name=domain_name)

Expand All @@ -508,7 +513,7 @@ def _check_reset_password_eligibility(user_id: str, auth_type: str, email: str):
def _generate_temporary_password():
while True:
random_password = "".join(
random.choice(
secrets.choice(
string.ascii_uppercase + string.ascii_lowercase + string.digits
)
for _ in range(12)
Expand Down Expand Up @@ -558,6 +563,18 @@ def _get_domain_default_language(domain_id: str, language: str = None) -> str:
language = "en"
return language

@staticmethod
def _get_domain_display_name(domain_id: str, domain_name: str) -> str:
config_mgr = ConfigManager()
domain_config_data_info = config_mgr.get_auth_config(domain_id)
settings = domain_config_data_info.get("settings", {})
domain_display_name = settings.get("display_name", "")

if not domain_display_name:
domain_display_name = domain_name

return domain_display_name

@staticmethod
def _get_refresh_timeout_from_config(refresh_timeout: int) -> int:
identity_conf = config.get_global("IDENTITY") or {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<div
style="height:0px;max-height:0px;border-width:0px;border: 0px;border-color:initial;border-image:initial;visibility:hidden;line-height:0px;font-size:0px;overflow:hidden;display:none;"
>
Reset your password to continue using SpaceONE
Reset your password to continue using {{service_name}}
</div>
<table id="$beacon$">
<tbody>
Expand Down Expand Up @@ -173,7 +173,7 @@
<div><br/></div>
<div>
<span style="font-size: 18px;"
>We noticed your account was newly added or updated by your domain administrator. <br><br> To continue using SpaceONE, Please reset your password first. </span
>We noticed your account was newly added or updated in {{domain_display_name}} by your domain administrator. <br><br> To continue using {{service_name}}, Please reset your password first. </span
><span data-metadata=""></span>
</div>
</td>
Expand Down Expand Up @@ -321,7 +321,7 @@
<span
style="font-size: 12px; color: #858895;"
class="stb-fore-colored"
>Copyright 2023 © MEGAZONE CLOUD Corp. All Right
>Copyright 2024 © MEGAZONE CLOUD Corp. All Right
Reserved.</span
>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<div
style="height:0px;max-height:0px;border-width:0px;border: 0px;border-color:initial;border-image:initial;visibility:hidden;line-height:0px;font-size:0px;overflow:hidden;display:none;"
>
お客様のアカウントが、ドメイン管理者によってSpaceONEに新しく追加または更新されたことを検知しました
お客様のアカウントが、ドメイン管理者によって{{service_name}}に新しく追加または更新されたことを検知しました
</div>
<table id="$beacon$">
<tbody>
Expand Down Expand Up @@ -130,7 +130,7 @@
<div><br /></div>
<div>
<span style="font-size: 18px;"
>お客様のアカウントが、ドメイン管理者によってSpaceONEに新しく追加または更新されたことを検知しました<br><br> SpaceONEを引き続きご利用いただくには、まずパスワードをリセットしてください。 </span
>お客様のアカウントが、ドメイン管理者によって{{domain_display_name}}に新しく追加または更新されたことを検知しました<br><br> {{service_name}}を引き続きご利用いただくには、まずパスワードをリセットしてください。 </span
><span data-metadata=""></span>
</div>
</td>
Expand Down Expand Up @@ -204,7 +204,7 @@
style="word-break:break-all;text-align:left;margin:0px;;line-height:1.7;word-break:break-word;font-size:16px;font-family:noto sans kr, noto sans cjk kr, noto sans cjk, Malgun Gothic, apple sd gothic neo, nanum gothic, malgun gothic, dotum, arial, helvetica, Meiryo, MS Gothic, sans-serif!important;;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;color:#000000;padding:15px 25px 15px 25px;"
>
<div>
<span style="font-size: 18px;">今後ともSpaceONEをよろしくお願い致します</span>
<span style="font-size: 18px;">今後とも{{service_name}}をよろしくお願い致します</span>
</div>
<div><br /></div>
<div><br /></div>
Expand Down Expand Up @@ -278,7 +278,7 @@
<span
style="font-size: 12px; color: #858895;"
class="stb-fore-colored"
>Copyright 2023 © MEGAZONE CLOUD Corp. All Right
>Copyright 2024 © MEGAZONE CLOUD Corp. All Right
Reserved.</span
>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
<div><br/></div>
<div>
<span style="font-size: 18px;"
>고객님의 계정이 도메인 관리자에 의해 {{service_name}}에 신규 추가 또는 업데이트 되었음이 확인되었습니다. <br><br> 계속해서 SpaceONE을 사용하시려면, 비밀번호를 재설정 후 이용해주세요. </span
>고객님의 계정이 도메인 관리자에 의해 {{domain_display_name}}에 신규 추가 또는 업데이트 되었음이 확인되었습니다. <br><br> 계속해서 {{service_name}}을 사용하시려면, 비밀번호를 재설정 후 이용해주세요. </span
><span data-metadata=""></span>
</div>
</td>
Expand Down Expand Up @@ -286,7 +286,7 @@
<span
style="font-size: 12px; color: #858895;"
class="stb-fore-colored"
>Copyright 2023 © MEGAZONE CLOUD Corp. All Right
>Copyright 2024 © MEGAZONE CLOUD Corp. All Right
Reserved.</span
>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
<div><br/></div>
<div>
<span style="font-size: 18px;"
>We noticed your account was newly added by your domain administrator. <br> To continue using {{service_name}}, Please access via the link below. <br><br> - Login Account : {{auth_type}} </span
>We noticed your account was newly added or updated in {{domain_display_name}} by your domain administrator. <br> To continue using {{service_name}}, Please access via the link below. <br><br> - Login Account : {{auth_type}} </span
><span data-metadata=""></span>
</div>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
<div><br/></div>
<div>
<span style="font-size: 18px;"
>お客様のアカウントが、ドメイン管理者によって{{service_name}}に新しく追加されたことを検知しました。<br> {{service_name}}を引き続きご利用いただくには、以下のリンクからアクセスしてください。 <br><br> -ログインアカウント : {{auth_type}} </span
>お客様のアカウントが、ドメイン管理者によって{{domain_display_name}}に新しく追加されたことを検知しました。<br> {{service_name}}を引き続きご利用いただくには、以下のリンクからアクセスしてください。 <br><br> -ログインアカウント : {{auth_type}} </span
><span data-metadata=""></span>
</div>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
<div><br/></div>
<div>
<span style="font-size: 18px;"
>고객님의 계정이 도메인 관리자에 의해 {{service_name}}에 신규 추가 되었습니다. <br> 계속해서 {{service_name}}을 사용하시려면, 아래 링크를 통해 접속해주세요. <br><br> -로그인 계정 : {{auth_type}} </span
>고객님의 계정이 도메인 관리자에 의해 {{domain_display_name}}에 신규 추가 되었습니다. <br> 계속해서 {{service_name}}을 사용하시려면, 아래 링크를 통해 접속해주세요. <br><br> -로그인 계정 : {{auth_type}} </span
><span data-metadata=""></span>
</div>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
<div><br /></div>
<div>
<span style="font-size: 18px;">
We noticed your account was newly added or updated by your domain administrator. </span>
We noticed your account was newly added or updated in {{domain_display_name}} by your domain administrator. </span>
<span data-metadata=""></span>
<br>
<span style="font-size: 18px;">Please use the temporary password below to sign in to console and reset it.
Expand Down Expand Up @@ -287,7 +287,7 @@
<span
style="font-size: 12px; color: #858895;"
class="stb-fore-colored"
>Copyright 2023 © MEGAZONE CLOUD Corp. All Right
>Copyright 2024 © MEGAZONE CLOUD Corp. All Right
Reserved.</span
>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
</div>
<div><br /></div>
<div>
<span style="font-size: 18px;">お客様のアカウントが、ドメイン管理者によって{{service_name}}に新しく追加または更新されたことを検知しました。
<span style="font-size: 18px;">お客様のアカウントが、ドメイン管理者によって{{domain_display_name}}に新しく追加または更新されたことを検知しました。
</span>
</div>
<div></div>
Expand Down Expand Up @@ -289,7 +289,7 @@
<span
style="font-size: 12px; color: #858895;"
class="stb-fore-colored"
>Copyright 2023 © MEGAZONE CLOUD Corp. All Right
>Copyright 2024 © MEGAZONE CLOUD Corp. All Right
Reserved.</span
>
</div>
Expand Down
Loading

0 comments on commit 7aad2e1

Please sign in to comment.