Skip to content

Commit a08dd38

Browse files
Fix #2672: Pass db_session to user delete method
Also fixed pylint errors including explicit imports, bare except handlings, and undefined requestJson usage. Signed-off-by: Pratyksh Gupta <pratykshgupta9999@gmail.com>
2 parents 76b520d + 3b6f575 commit a08dd38

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

augur/api/gunicorn_conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
# set the log location for gunicorn
4141
logs_directory = get_value('Logging', 'logs_directory')
4242

43-
is_docker = os.getenv("AUGUR_DOCKER_DEPLOY").lower() in ('true', '1', 't', 'y', 'yes')
43+
is_docker = os.getenv("AUGUR_DOCKER_DEPLOY", 'False').lower() in ('true', '1', 't', 'y', 'yes')
4444
accesslog = f"{logs_directory}/gunicorn.log"
4545
errorlog = f"{logs_directory}/gunicorn.log"
4646

augur/api/view/routes.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import logging
55
import math
66
from flask import render_template, request, redirect, url_for, session, flash
7-
from .utils import *
7+
from .utils import getSetting, render_module, renderRepos, render_message
88
from flask_login import login_user, logout_user, current_user, login_required
99

1010
from augur.application.db.models import User, Repo, ClientApplication
1111
from .server import LoginException
12-
from augur.application.util import *
12+
from augur.application.util import get_all_repos, get_all_repos_count
1313
from augur.application.db.lib import get_value
1414
from ..server import app, db_session
1515

@@ -57,7 +57,7 @@ def repo_table_view():
5757
query = request.args.get('q')
5858
try:
5959
page = int(request.args.get('p') or 0)
60-
except:
60+
except (ValueError, TypeError):
6161
page = 1
6262

6363
sorting = request.args.get('s')
@@ -147,19 +147,19 @@ def user_login():
147147
result = User.create_user(username, password, email, first_name, last_name, admin)
148148
if not result[0]:
149149
raise LoginException("An error occurred registering your account")
150-
else:
151-
user = User.get_user(db_session, username)
152-
flash(result[1]["status"])
150+
151+
user = User.get_user(db_session, username)
152+
flash(result[1]["status"])
153153

154154
# Log the user in if the password is valid
155155
if user.validate(password) and login_user(user, remember = remember):
156156
flash(f"Welcome, {username}!")
157157
if "login_next" in session:
158158
return redirect(session.pop("login_next"))
159159
return redirect(url_for('root'))
160-
else:
161-
print("Invalid login")
162-
raise LoginException("Invalid login credentials")
160+
161+
print("Invalid login")
162+
raise LoginException("Invalid login credentials")
163163
except LoginException as e:
164164
flash(str(e))
165165
return render_module('login', title="Login")
@@ -198,10 +198,18 @@ def authorize_user():
198198
@app.route('/account/delete')
199199
@login_required
200200
def user_delete():
201-
if current_user.delete()[0]:
202-
flash(f"Account {current_user.login_name} successfully removed")
203-
logout_user()
204-
else:
201+
try:
202+
username = current_user.login_name
203+
result = current_user.delete(db_session)
204+
205+
if result[0]:
206+
flash(f"Account {username} successfully removed")
207+
logout_user()
208+
else:
209+
logger.error(f"Failed to delete account {username}: {result[1]}")
210+
flash("An error occurred removing the account")
211+
except Exception as e:
212+
logger.error(f"Exception occurred while deleting account: {e}")
205213
flash("An error occurred removing the account")
206214

207215
return redirect(url_for("root"))
@@ -256,7 +264,7 @@ def user_groups_view():
256264

257265
try:
258266
activepage = int(request.args.get('p')) if 'p' in request.args else 0
259-
except:
267+
except (ValueError, TypeError):
260268
activepage = 0
261269

262270
(groups, status) = current_user.get_groups_info(**params)
@@ -291,7 +299,7 @@ def user_group_view(group = None):
291299

292300
try:
293301
params["page"] = int(request.args.get('p') or 0)
294-
except:
302+
except (ValueError, TypeError):
295303
params["page"] = 1
296304

297305
if query := request.args.get('q'):
@@ -337,6 +345,8 @@ def dashboard_view():
337345
]}
338346
]
339347

340-
backend_config = requestJson("config/get", False)
348+
# backend_config = requestJson("config/get", False)
349+
# TODO: requestJson is undefined and causing pylint errors. Setting empty config for now.
350+
backend_config = {}
341351

342352
return render_template('admin-dashboard.j2', sections = empty, config = backend_config)

0 commit comments

Comments
 (0)