Orgs: show "My Organizations" in the user's menu

This is shown only when the user is member of or administrator for one or
more organizations, otherwise it's hidden.
This commit is contained in:
2017-08-24 12:35:31 +02:00
parent 95dc799692
commit b9ae4396e5
5 changed files with 50 additions and 3 deletions

View File

@@ -361,6 +361,21 @@ class OrgManager:
projection={'_id': 1, 'full_name': 1, 'email': 1})
return list(users)
def user_has_organizations(self, user_id: bson.ObjectId) -> bool:
"""Returns True iff the user has anything to do with organizations.
That is, if the user is admin for and/or member of any organization.
"""
org_coll = current_app.db('organizations')
org_count = org_coll.count({'$or': [
{'admin_uid': user_id},
{'members': user_id}
]})
return bool(org_count)
def setup_app(app):
from . import patch, hooks