Skip to content

Commit

Permalink
[FLPY-37] Modified submit confirmation to work per-session
Browse files Browse the repository at this point in the history
  • Loading branch information
awkrupka committed Oct 4, 2023
1 parent 523db63 commit 5035ff0
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 77 deletions.
1 change: 0 additions & 1 deletion examples/dev/dev_change_account_and_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from flow360.examples import OM6wing

fl.Env.dev.active()
fl.UserConfig.set_profile("dev")

# choose shared account interactively
fl.Accounts.choose_shared_account()
Expand Down
10 changes: 10 additions & 0 deletions flow360/accounts_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class AccountsUtils:
def __init__(self):
self._current_email = None
self._current_user_identity = None
self._confirmed_submit = False

@staticmethod
def _interactive_selection(users):
Expand Down Expand Up @@ -90,6 +91,14 @@ def _check_state_consistency(self):
self._current_email = None
self._current_user_identity = None

def is_confirmed(self):
"""check if the user confirmed that he wants to submit resources to a shared account"""
return self._confirmed_submit

def confirm_submit(self):
"""confirm submit for the current session"""
self._confirmed_submit = True

def choose_shared_account(self, email=None):
"""choose a shared account to impersonate
Expand Down Expand Up @@ -122,6 +131,7 @@ def choose_shared_account(self, email=None):

Env.impersonate = user_id

self._confirmed_submit = False
self._current_email = user_email
self._current_user_identity = user_id

Expand Down
35 changes: 1 addition & 34 deletions flow360/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,7 @@ def flow360():
is_flag=True,
help='Whether to show warnings for "submit()" when creating new Case, new VolumeMesh etc.',
)
@click.option(
"--suppress-shared-account-prompt",
type=bool,
is_flag=True,
help='Do not prompt for confirmation for "submit()" when creating new resources while logged into a shared account',
)
@click.option(
"--show-shared-account-prompt",
type=bool,
is_flag=True,
help='Always prompt for confirmation for "submit()" when creating new resources while logged into a shared account',
)
# pylint: disable=too-many-arguments
def configure(
apikey,
profile,
suppress_submit_warning,
show_submit_warning,
suppress_shared_account_prompt,
show_shared_account_prompt,
):
def configure(apikey, profile, suppress_submit_warning, show_submit_warning):
"""
Configure flow360.
"""
Expand Down Expand Up @@ -92,19 +72,6 @@ def configure(
config.update({"user": {"config": {"suppress_submit_warning": False}}})
changed = True

if suppress_submit_warning and show_submit_warning:
raise click.ClickException(
"You cannot use both --suppress-shared-account-prompt AND --show-shared-account-prompt"
)

if suppress_shared_account_prompt:
config.update({"user": {"config": {"suppress_shared_account_prompt": True}}})
changed = True

if show_shared_account_prompt:
config.update({"user": {"config": {"suppress_shared_account_prompt": False}}})
changed = True

with open(config_file, "w", encoding="utf-8") as file_handler:
file_handler.write(toml.dumps(config))

Expand Down
10 changes: 4 additions & 6 deletions flow360/component/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from ..exceptions import TypeError as FlTypeError
from ..exceptions import ValueError as FlValueError
from ..log import log
from ..user_config import UserConfig


# pylint: disable=redefined-builtin
Expand Down Expand Up @@ -55,16 +54,15 @@ def confirm_proceed():
"""
Prompts confirmation from user when submitting a resource from a shared account
"""
if (
Accounts.shared_account_info() is not None
and not UserConfig.is_suppress_shared_account_prompt()
):
log.warning(shared_submit_warning)
email = Accounts.shared_account_info()
if email is not None and not Accounts.is_confirmed():
log.warning(shared_submit_warning(email))
print("Are you sure you want to proceed? (y/n): ")
while True:
try:
value = input()
if value.lower() == "y":
Accounts.confirm_submit()
return True
if value.lower() == "n":
return False
Expand Down
13 changes: 7 additions & 6 deletions flow360/error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
"""


shared_submit_warning = """\
You are submitting a resource from a shared account.
To suppress this message run: flow360 configure --suppress-shared-account-prompt
"""


def change_solver_version_error(from_version, to_version):
return f"""\
Cannot change solver version from parent to child.
Expand All @@ -25,6 +19,13 @@ def change_solver_version_error(from_version, to_version):
"""


def shared_submit_warning(email):
return f"""\
You are submitting a resource to a shared account {email}.
This message will not be shown again for this session if you confirm.
"""


def params_fetching_error(err_msg):
return f"""\
There was a problem when fetching params for this case
Expand Down
2 changes: 1 addition & 1 deletion flow360/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def set_logging_file(
filemode: str = "a",
level: LogValue = DEFAULT_LEVEL,
back_up_count: int = 10,
max_bytes: int = 10000,
max_bytes: int = 100000000,
) -> None:
"""Set a file to write log to, independently from the stdout and stderr
output chosen using :meth:`set_logging_level`.
Expand Down
29 changes: 0 additions & 29 deletions flow360/user_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def __init__(self):
self._check_env_apikey()
self._do_validation = True
self._suppress_submit_warning = None
self._suppress_shared_account_prompt = None

def _check_env_profile(self):
simcloud_profile = os.environ.get("SIMCLOUD_PROFILE", None)
Expand Down Expand Up @@ -77,30 +76,6 @@ def apikey(self):
return self._apikey
return self.config.get(self.profile, {}).get("apikey", "")

def suppress_shared_account_prompt(self):
"""locally suppress warning when trying to submit from a shared account"""
self._suppress_shared_account_prompt = True

def show_shared_account_prompt(self):
"""locally show warning when trying to submit from a shared account"""
self._suppress_shared_account_prompt = False

def is_suppress_shared_account_prompt(self):
"""suppress shared account submit warning config
Returns
-------
bool
whether to suppress shared account submit warnings
"""
if self._suppress_shared_account_prompt is not None:
return self._suppress_shared_account_prompt
return (
self.config.get("user", {})
.get("config", {})
.get("suppress_shared_account_prompt", False)
)

def suppress_submit_warning(self):
"""locally suppress submit warning"""
self._suppress_submit_warning = True
Expand All @@ -125,10 +100,6 @@ def cancel_local_submit_warning_settings(self):
"""cancel local submit warning settings"""
self._suppress_submit_warning = None

def cancel_local_shared_account_prompt_settings(self):
"""cancel local shared account submit warning settings"""
self._suppress_shared_account_prompt = None

@property
def do_validation(self):
"""for handling user side validation (pydantic)
Expand Down

0 comments on commit 5035ff0

Please sign in to comment.