Merge pull request #216 feature-NEWDWH2021-1072-fix-webapp into develop

This commit is contained in:
下田雅人 2023-06-07 11:49:22 +09:00
commit 89df6350ee
15 changed files with 65 additions and 49 deletions

View File

@ -57,7 +57,7 @@ async def download_bio_data(
if search_result_df.size < 1:
# 検索結果が0件の場合、download_urlを返さない
print('Bio data not found')
logger.info('検索結果が0件です')
return {'status': 'ok', 'download_url': None}
# ファイルに打ち出すカラムを抽出
@ -73,7 +73,7 @@ async def download_bio_data(
download_file_url = bio_service.generate_download_file_url(
local_file_path, download_param.user_id, download_param.ext)
except Exception as e:
print('S3 access error', e.args)
logger.exception(f'S3 アクセスエラー{e}')
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail={'error': 'aws_error', 'message': e.args}
@ -107,9 +107,7 @@ def _search_bio_data(bio_service: BioViewService, search_param: BioModel, user_i
try:
# 生物由来データを検索
search_result_df, query = bio_service.search_download_bio_data(search_param)
# TODO: ファイルにも出力する
except DBException as e:
logger.exception(f'DB Error: {e}')
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail={'error': 'db_error', 'message': e.args}

View File

@ -9,6 +9,7 @@ from starlette import status
from src.depends.auth import code_security
from src.depends.services import get_service
from src.error.exceptions import JWTTokenVerifyException, NotAuthorizeException
from src.logging.get_logger import get_logger
from src.model.internal.session import UserSession
from src.model.request.login import LoginModel
from src.model.view.mainte_login_view_model import MainteLoginViewModel
@ -21,6 +22,8 @@ from src.templates import templates
router = APIRouter()
router.route_class = AfterSetCookieSessionRoute
logger = get_logger('ログイン')
#########################
# Views #
#########################
@ -66,9 +69,10 @@ def login(
try:
jwt_token = login_service.login(request.username, request.password)
except NotAuthorizeException as e:
print(e)
logger.exception(e)
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=constants.LOGOUT_REASON_LOGIN_ERROR)
except JWTTokenVerifyException:
except JWTTokenVerifyException as e:
logger.exception(e)
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=constants.LOGOUT_REASON_SESSION_EXPIRED)
verified_token = jwt_token.verify_token()
@ -77,10 +81,13 @@ def login(
user_record = login_service.logged_in_user(user_id)
# ユーザーが有効ではない場合、ログアウトにリダイレクトする
if not user_record.is_enable_user():
logger.info(f'無効なユーザー: {user_id}, 有効フラグ: {user_record.enabled_flg}')
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=constants.LOGOUT_REASON_LOGIN_ERROR)
# メンテユーザーではない場合、ログアウトにリダイレクトする
if user_record is None or not user_record.is_maintenance_user():
logger.info(f'メンテナンスユーザーではない: {user_id}, メンテナンスユーザーフラグ: {user_record.mntuser_flg}')
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=constants.LOGOUT_REASON_LOGIN_ERROR)
logger.info(f'メンテナンスユーザー認証成功: {user_id}')
# CSRFトークンを生成
csrf_token = secrets.token_urlsafe(32)
# DynamoDBにトークンIDを設定する
@ -118,7 +125,8 @@ def sso_authorize(
try:
# トークン検証
verified_token = jwt_token.verify_token()
except JWTTokenVerifyException:
except JWTTokenVerifyException as e:
logger.exception(e)
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=constants.LOGOUT_REASON_SESSION_EXPIRED)
# トークンからユーザーIDを取得
@ -126,11 +134,13 @@ def sso_authorize(
user_record = login_service.logged_in_user(user_id)
# ユーザーが有効ではない場合、ログアウトにリダイレクトする
if not user_record.is_enable_user():
logger.info(f'無効なユーザー: {user_id}, 有効フラグ: {user_record.enabled_flg}')
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=constants.LOGOUT_REASON_LOGIN_ERROR)
# Merckユーザーではない場合、ログアウトにリダイレクトする
if user_record is None or not user_record.is_groupware_user():
logger.info(f'メンテナンスユーザーではない: {user_id}, メンテナンスユーザーフラグ: {user_record.mntuser_flg}')
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=constants.LOGOUT_REASON_LOGIN_ERROR)
logger.info(f'顧客ユーザー認証成功: {user_id}')
# CSRFトークンを生成
csrf_token = secrets.token_urlsafe(32)
# DynamoDBにトークンIDを設定する

View File

@ -5,11 +5,13 @@ from fastapi import Depends
from fastapi.security import APIKeyCookie, APIKeyQuery
from src.error.exceptions import JWTTokenVerifyException
from src.logging.get_logger import get_logger
from src.model.internal.jwt_token import JWTToken
from src.model.internal.session import UserSession
from src.services.session_service import get_session
from src.system_var import environment
logger = get_logger('認証チェック')
cookie_security = APIKeyCookie(name='session', auto_error=False)
code_security = APIKeyQuery(name='code', auto_error=False)
@ -45,6 +47,6 @@ def verify_session(session: Union[UserSession, None] = Depends(check_session_exp
try:
jwt_token.verify_token()
except JWTTokenVerifyException as e:
print(e)
logger.info(e)
return None
return session

View File

@ -12,4 +12,4 @@ def http_exception_handler(request: Request, exc: HTTPException):
raise exc
error_detail = exc.detail if hasattr(exc, 'detail') else ''
reason = parse.quote(error_detail)
return RedirectResponse(f'/logout?reason={reason}', status_code=status.HTTP_303_SEE_OTHER)
return RedirectResponse(f'/logout/?reason={reason}', status_code=status.HTTP_303_SEE_OTHER)

View File

@ -33,4 +33,4 @@ class UserMasterModel(BaseDBModel):
return self.mntuser_flg == '1'
def is_groupware_user(self):
return self.mntuser_flg == '0'
return self.mntuser_flg == '0' or self.mntuser_flg is None

View File

@ -14,11 +14,11 @@ class UserSession(DynamoDBTableModel):
session_key = UnicodeAttribute(hash_key=True)
user_id = UnicodeAttribute()
id_token = UnicodeAttribute()
doc_flg = UnicodeAttribute()
inst_flg = UnicodeAttribute()
bio_flg = UnicodeAttribute()
master_mainte_flg = UnicodeAttribute()
user_flg = UnicodeAttribute()
doc_flg = UnicodeAttribute(null=True)
inst_flg = UnicodeAttribute(null=True)
bio_flg = UnicodeAttribute(null=True)
master_mainte_flg = UnicodeAttribute(null=True)
user_flg = UnicodeAttribute(null=True)
refresh_token = UnicodeAttribute()
csrf_token = UnicodeAttribute()
last_access_time = NumberAttribute()

View File

@ -21,6 +21,3 @@ class UserViewModel(BaseModel):
def has_master_maintenance_permission(self):
return self.master_mainte_flg == '1'
def is_maintenance_user(self):
return self.user_flg == '1'

View File

@ -1,6 +1,9 @@
from src.logging.get_logger import get_logger
from src.model.db.hdke_tbl import HdkeTblModel
from src.repositories.base_repository import BaseRepository
logger = get_logger('日付テーブル取得')
class HdkeTblRepository(BaseRepository):
FETCH_SQL = "SELECT bch_actf FROM src05.hdke_tbl"
@ -13,8 +16,7 @@ class HdkeTblRepository(BaseRepository):
models = [HdkeTblModel(**r) for r in result]
return models
except Exception as e:
# TODO: ファイルへの書き出しはloggerでやる
print(f"[ERROR] DB Error : Exception={e.args}")
logger.exception(f"DB Error : Exception={e}")
raise e
finally:
self._database.disconnect()

View File

@ -1,6 +1,9 @@
from src.logging.get_logger import get_logger
from src.model.db.pharmacy_product_master import PharmacyProductMasterModel
from src.repositories.base_repository import BaseRepository
logger = get_logger('製品取得')
class PharmacyProductMasterRepository(BaseRepository):
@ -31,9 +34,7 @@ class PharmacyProductMasterRepository(BaseRepository):
models = [PharmacyProductMasterModel(**r) for r in result]
return models
except Exception as e:
# TODO: ファイルへの書き出しはloggerでやる
print(f"[ERROR] getOroshiData DB Error. ")
print(f"[ERROR] ErrorMessage: {e.args}")
logger.exception(f"DB Error : Exception={e}")
raise e
finally:
self._database.disconnect()

View File

@ -1,6 +1,9 @@
from src.logging.get_logger import get_logger
from src.model.db.user_master import UserMasterModel
from src.repositories.base_repository import BaseRepository
logger = get_logger('ユーザー取得')
class UserMasterRepository(BaseRepository):
FETCH_SQL = """\
@ -22,8 +25,7 @@ class UserMasterRepository(BaseRepository):
return None
return models[0]
except Exception as e:
# TODO: ファイルへの書き出しはloggerでやる
print(f"[ERROR] DB Error : Exception={e.args}")
logger.exception(f"DB Error : Exception={e}")
raise e
finally:
self._database.disconnect()

View File

@ -1,6 +1,9 @@
from src.logging.get_logger import get_logger
from src.model.db.wholesaler_master import WholesalerMasterModel
from src.repositories.base_repository import BaseRepository
logger = get_logger('卸データ取得')
class WholesalerMasterRepository(BaseRepository):
@ -34,9 +37,7 @@ class WholesalerMasterRepository(BaseRepository):
models = [WholesalerMasterModel(**r) for r in result_data]
return models
except Exception as e:
# TODO: ファイルへの書き出しはloggerでやる
print(f"[ERROR] getOroshiData DB Error. ")
print(f"[ERROR] ErrorMessage: {e.args}")
logger.exception(f"DB Error : Exception={e}")
raise e
finally:
self._database.disconnect()

View File

@ -1,6 +1,9 @@
from src.logging.get_logger import get_logger
from src.model.internal.session import UserSession
logger = get_logger('セッション管理')
def set_session(session: UserSession) -> str:
session.save()
@ -12,5 +15,5 @@ def get_session(key: str) -> UserSession:
session = UserSession.get(hash_key=key, consistent_read=True)
return session
except UserSession.DoesNotExist as e:
print(e)
logger.debug(f'セッション取得失敗:{e}')
return None

View File

@ -3,7 +3,7 @@
// 戻るボタンの関数
// 機能概要:メニュー画面に遷移する
function backToMenu(){
location.href = "/menu";
location.href = "/menu/";
}
// クリアボタンの関数
@ -17,7 +17,7 @@ function clr() {
formInput.value = "";
}
}
// 検索ボタンを再度非活性にする
formBtDisabled();
}
@ -35,7 +35,7 @@ function formBtDisabled(buttonId='search_bt', formId='search', all=false) {
const checkTargetValueLength = formInputElements
.filter((elem) => elem.name.startsWith('ctrl_'))
.map((elem) => elem.value.length)
// 活性、非活性の判断
let validFlg = false;
if (all) {
@ -75,7 +75,7 @@ function selectDropDowList(id, selectedName){
options[i].selected = true;
}
};
}
}
}
/**
@ -98,9 +98,9 @@ function enableDatePicker() {
function autoModifyDate($this){
// 日付フォーマットチェック
if($this.value === "" ||
(!$this.value.match(/^\d{4}\/\d{2}\/\d{2}$/) && !$this.value.match(/^\d{4}\d{2}\d{2}$/)))
{
if($this.value === "" ||
(!$this.value.match(/^\d{4}\/\d{2}\/\d{2}$/) && !$this.value.match(/^\d{4}\d{2}\d{2}$/)))
{
$this.value = "";
return;
}

View File

@ -28,7 +28,7 @@
<tbody>
<tr>
<td class="back_bt" colspan="7" align="right">
<input type="button" name="back" value="メニューへ" onclick="location.href='/menu'">
<input type="button" name="back" value="メニューへ" onclick="location.href='/menu/'">
</td>
</tr>
<tr>
@ -219,12 +219,12 @@
success: function(data) {
try {
if (data.status === 'batch_processing') {
location.href('/logout?reason=batchProcessing')
location.href('/logout/?reason=batchProcessing')
return
}
if (data.status === 'session_expired') {
location.href('/logout?reason=session_expired')
location.href('/logout/?reason=session_expired')
return
}
// データが存在しない場合の考慮が必要
@ -335,7 +335,7 @@
'v_tran_cd',
'iko_flg',
];
const tableRow = document.createElement('tr')
const tableRow = documen.sendt.createElement('tr')
return datas.map(function (data) {
return `
<tr class="result_data">
@ -401,13 +401,13 @@
modal_title='エラー',
message='AWS環境に異常が発生しました。管理者にお問い合わせください。',
icon_key='warning',
modal_close_event='location.href="/logout?reason="',
modal_close_event='location.href="/logout/?reason="',
buttons = [
{
'id': 'error_modal_aws',
'class': 'btn btn-primary',
'text': 'OK',
'onclick_event': 'location.href="/logout?reason=''"'
'onclick_event': 'location.href="/logout/?reason=''"'
}
]
%}
@ -419,13 +419,13 @@
modal_title='エラー',
message='DB接続に失敗しました。管理者にお問い合わせください。',
icon_key='warning',
modal_close_event='location.href="/logout?reason="',
modal_close_event='location.href="/logout/?reason="',
buttons = [
{
'id': 'error_modal_db',
'class': 'btn btn-primary',
'text': 'OK',
'onclick_event': 'location.href="/logout?reason=''"'
'onclick_event': 'location.href="/logout/?reason=''"'
}
]
%}
@ -438,13 +438,13 @@
modal_title='エラー',
message='サーバーエラーが発生しました。管理者にお問い合わせください。',
icon_key='warning',
modal_close_event='location.href="/logout?reason="',
modal_close_event='location.href="/logout/?reason="',
buttons = [
{
'id': 'error_modal_unexpected',
'class': 'btn btn-primary',
'text': 'OK',
'onclick_event': 'location.href="/logout?reason=''"'
'onclick_event': 'location.href="/logout/?reason=''"'
}
]
%}

View File

@ -22,7 +22,7 @@
{% else %}
<div class="notUseBioMsg">生物由来データ参照は <br> 日次バッチ処理中のため利用出来ません</div>
{% endif %}
{% endif %}
{% endif %}
{% if menu.is_available_master_maintenance_menu() %}
{% if not menu.is_batch_processing() %}
<a href="{{masterMaintePath}}" class="btn btn-primary btn-lg btn_width">マスターメンテメニュー</a><br><br>
@ -30,7 +30,7 @@
<div class="notUseBioMsg"> マスターメンテメニューは <br> 日次バッチ処理中のため利用出来ません </div>
{% endif %}
{% endif %}
<br><br><a href="/logout?reason=do_logout" class="btn btn-info btn-lg btn_width">Logout</a>
<br><br><a href="/logout/?reason=do_logout" class="btn btn-info btn-lg btn_width">Logout</a>
</div>
</body>
</html>