Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various improvements #836

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ install_requires =
python-slugify==8.0.4
python-socketio==5.11.3
pytz==2024.1
redis==5.0.7
redis==5.0.8
requests==2.32.3
rq==1.16.2
slackclient==2.9.4
Expand All @@ -95,15 +95,15 @@ dev =
wheel

test =
fakeredis==2.23.3
fakeredis==2.23.4
mixer==7.2.2
pytest-cov==5.0.0
pytest==8.3.2

monitoring =
prometheus-flask-exporter==0.23.1
pygelf==0.4.2
sentry-sdk==2.11.0
sentry-sdk==2.12.0

lint =
autoflake==2.3.1
Expand Down
7 changes: 5 additions & 2 deletions zou/app/services/persons_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,15 @@ def update_password(email, password):
return person.serialize()


def update_person(person_id, data):
def update_person(person_id, data, bypass_protected_accounts=False):
"""
Update person entry with data given in parameter.
"""
person = Person.get(person_id)
if person.email in config.PROTECTED_ACCOUNTS:
if (
not bypass_protected_accounts
and person.email in config.PROTECTED_ACCOUNTS
):
message = None
if data.get("active") is False:
message = (
Expand Down
12 changes: 10 additions & 2 deletions zou/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def reset_migrations():

@cli.command()
@click.argument("email")
@click.option("--password", required=True)
@click.option("--password", default=None)
def create_admin(email, password):
"""
Create an admin user to allow usage of the API when database is empty.
Expand All @@ -149,10 +149,18 @@ def create_admin(email, password):
try:
person = persons_service.get_person_by_email(email)
if person["role"] != "admin":
persons_service.update_person(person["id"], {"role": "admin"})
persons_service.update_person(
person["id"],
{"role": "admin"},
bypass_protected_accounts=True,
)
print("Existing user's role has been upgraded to 'admin'.")
except PersonNotFoundException:
try:
if password is None:
raise click.MissingParameter(
param_type="option", param_hint="--password"
)
auth.validate_password(password)
# Allow "[email protected]" to be invalid.
if email != "[email protected]":
Expand Down
Loading