From 798012e2d21c48b07710660f1f1596bbaf51d2fe Mon Sep 17 00:00:00 2001
From: Sam
Date: Thu, 31 Oct 2013 20:03:11 -0500
Subject: Implemented superuser and switching users for debugging purposes
---
wqflask/wqflask/model.py | 44 +++++++++++++---
wqflask/wqflask/templates/admin/group_manager.html | 12 ++---
.../wqflask/templates/admin/ind_user_manager.html | 33 +++++++++---
wqflask/wqflask/templates/admin/user_manager.html | 9 ++--
wqflask/wqflask/templates/base.html | 2 +-
wqflask/wqflask/user_manager.py | 58 +++++++++++++++++++---
6 files changed, 125 insertions(+), 33 deletions(-)
diff --git a/wqflask/wqflask/model.py b/wqflask/wqflask/model.py
index cf9e58e1..b508f18e 100644
--- a/wqflask/wqflask/model.py
+++ b/wqflask/wqflask/model.py
@@ -23,11 +23,11 @@ from wqflask.database import Base, init_db
# Column('user_id', Integer(), ForeignKey('user.the_id')),
# Column('role_id', Integer(), ForeignKey('role.the_id')))
-class Role(Base):
- __tablename__ = "role"
- id = Column(Unicode(36), primary_key=True, default=lambda: unicode(uuid.uuid4()))
- name = Column(Unicode(80), unique=True, nullable=False)
- description = Column(Unicode(255))
+#class Role(Base):
+# __tablename__ = "role"
+# id = Column(Unicode(36), primary_key=True, default=lambda: unicode(uuid.uuid4()))
+# name = Column(Unicode(80), unique=True, nullable=False)
+# description = Column(Unicode(255))
class User(Base):
__tablename__ = "user"
@@ -46,15 +46,27 @@ class User(Base):
confirmed = Column(Text) # json detailing when they confirmed, etc.
+ superuser = Column(Text) # json detailing when they became a superuser, otherwise empty
+ # if not superuser
+
logins = relationship("Login",
order_by="desc(Login.timestamp)",
- lazy='dynamic' # Necessary for filter in login_count
+ lazy='dynamic', # Necessary for filter in login_count
+ foreign_keys="Login.user",
)
user_collections = relationship("UserCollection",
order_by="asc(UserCollection.name)",
)
+ @property
+ def name_and_org(self):
+ """Nice shortcut for printing out who the user is"""
+ if self.organization:
+ return "{} from {}".format(self.full_name, self.organization)
+ else:
+ return self.full_name
+
@property
def login_count(self):
return self.logins.filter_by(successful=True).count()
@@ -68,6 +80,23 @@ class User(Base):
else:
return None
+ @property
+ def superuser_info(self):
+ if self.superuser:
+ return json.loads(self.superuser)
+ else:
+ return None
+
+ @property
+ def crowner(self):
+ """If made superuser, returns object of person who did the crowning"""
+ if self.superuser:
+ superuser_info = json.loads(self.superuser)
+ crowner = User.query.get(superuser_info['crowned_by'])
+ return crowner
+ else:
+ return None
+
@property
def most_recent_login(self):
try:
@@ -89,6 +118,9 @@ class Login(Base):
successful = Column(Boolean(), nullable=False) # False if wrong password was entered
session_id = Column(Text) # Set only if successfully logged in, otherwise should be blank
+ # Set to user who assumes identity if this was a login for debugging purposes by a superuser
+ assumed_by = Column(Unicode(36), ForeignKey('user.id'))
+
def __init__(self, user):
self.user = user.id
self.ip_address = request.remote_addr
diff --git a/wqflask/wqflask/templates/admin/group_manager.html b/wqflask/wqflask/templates/admin/group_manager.html
index df3eda33..ea9026a6 100644
--- a/wqflask/wqflask/templates/admin/group_manager.html
+++ b/wqflask/wqflask/templates/admin/group_manager.html
@@ -2,11 +2,7 @@
{% block title %}Group Manager{% endblock %}
{% block content %}
- Group Manager
-
+ + Become this user for debugging + + | +