From 049a8a454740048dc99a1bd6e39b29f1dc7b6098 Mon Sep 17 00:00:00 2001 From: thomasDOTde Date: Mon, 4 Dec 2017 22:18:28 +0100 Subject: [PATCH] optimized domain permission check for normal users --- app/models.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/models.py b/app/models.py index 7fe418f..c8adecd 100644 --- a/app/models.py +++ b/app/models.py @@ -366,11 +366,10 @@ class User(db.Model): if self.role.name == "Administrator": return True - query = db.session.query(User, DomainUser, Domain).filter(User.id==self.id).filter(User.id==DomainUser.user_id).filter(Domain.id==DomainUser.domain_id).all() - for q in query: - if q[2].name == domain_name: - return True - return False + query = db.session.query(User, DomainUser, Domain).filter(User.id == self.id).filter( + User.id == DomainUser.user_id).filter(Domain.id == DomainUser.domain_id).filter( + Domain.name == domain_name) + return query.count() >= 1 def delete(self): """