aboutsummaryrefslogtreecommitdiff
path: root/wqflask/wqflask/model.py
diff options
context:
space:
mode:
authorSam2013-10-31 20:03:11 -0500
committerSam2013-10-31 20:03:11 -0500
commit798012e2d21c48b07710660f1f1596bbaf51d2fe (patch)
treeb2673e67a802ec1ebd39afde7b494ad98b4f0eb5 /wqflask/wqflask/model.py
parent74d803b0de60edf324b1a6ce589d12a055ef312b (diff)
downloadgenenetwork2-798012e2d21c48b07710660f1f1596bbaf51d2fe.tar.gz
Implemented superuser and switching users for debugging purposes
Diffstat (limited to 'wqflask/wqflask/model.py')
-rw-r--r--wqflask/wqflask/model.py44
1 files changed, 38 insertions, 6 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,9 +46,13 @@ 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",
@@ -56,6 +60,14 @@ class User(Base):
)
@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()
@@ -69,6 +81,23 @@ class User(Base):
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:
return self.logins[0]
@@ -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