Skip to content

Commit 4cca9e7

Browse files
committed
Functional but incomplete user/update
Removed stubs for activate. deactivate
1 parent c11a30a commit 4cca9e7

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

src/server/api/user_api.py

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -343,55 +343,37 @@ def user_update():
343343
except:
344344
pass
345345

346-
print(update_dict)
346+
if not update_dict:
347+
return jsonify("No changed items specified")
347348

348-
# If updating password, need to hash first
349+
# TODO: If updating password, need to hash first
349350

350351

351352
# We have a variable number of columns to update.
352353
# We could generate a text query on the fly, but this seems the perfect place to use the ORM
353354
# and let it handle the update for us.
354355

355-
356-
# with engine.connect() as connection:
357-
358-
# for k,v in update_dict.items(): #TODO: Make less awful
359-
# s = text( """UPDATE pdp_users SET :key=:val where username=:u """ )
360-
# s = s.bindparams(u=username, key=k, val=v)
361-
# result = connection.execute(s)
362-
363356
from sqlalchemy import update
364-
from sqlalchemy.orm import Session
357+
from sqlalchemy.orm import Session, sessionmaker
365358

366-
with Session(engine) as session:
359+
Session = sessionmaker(engine)
367360

368-
PU = Table("pdp_users", metadata, autoload=True, autoload_with=engine)
369-
# pr = Table("pdp_user_roles", metadata, autoload=True, autoload_with=engine)
361+
session = Session()
362+
# #TODO: Figure out context manager doesn't work or do try/finally
370363

364+
PU = Table("pdp_users", metadata, autoload=True, autoload_with=engine)
365+
# pr = Table("pdp_user_roles", metadata, autoload=True, autoload_with=engine)
371366

372-
stmt = update(PU).where(PU.username == username).values(update_dict).\
373-
execution_options(synchronize_session="fetch")
374367

375-
result = session.execute(stmt)
368+
stmt = update(PU).where(PU.columns.username == username).values(update_dict).\
369+
execution_options(synchronize_session="fetch")
376370

371+
result = session.execute(stmt)
377372

378-
return jsonify("Work in process")
373+
session.commit()
374+
session.close()
379375

380-
# TODO: A single do-all update_user()
381-
@user_api.route("/api/admin/user/deactivate", methods=["POST"])
382-
@jwt_ops.admin_required
383-
def user_deactivate():
384-
"""Mark user as inactive in DB"""
385-
# TODO
386-
return "", 200
387-
388-
389-
@user_api.route("/api/admin/user/activate", methods=["POST"])
390-
@jwt_ops.admin_required
391-
def user_activate():
392-
"""Mark user as active in DB"""
393-
# TODO
394-
return "", 200
376+
return jsonify("Updated")
395377

396378

397379
@user_api.route("/api/admin/user/get_users", methods=["GET"])

0 commit comments

Comments
 (0)