From 4116357447ae5cdfe7881a242541384370c792f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 23 Aug 2017 16:03:54 +0200 Subject: [PATCH] Orgs: some small fixes, mostly for stability / corner cases --- pillar/api/organizations/__init__.py | 7 +++++-- pillar/web/organizations/routes.py | 3 +++ src/templates/organizations/index.jade | 4 ++-- src/templates/organizations/view_embed.jade | 3 +-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pillar/api/organizations/__init__.py b/pillar/api/organizations/__init__.py index 06b01164..14ca5afe 100644 --- a/pillar/api/organizations/__init__.py +++ b/pillar/api/organizations/__init__.py @@ -115,7 +115,7 @@ class OrgManager: # Compute the new members. members = set(org_doc.get('members') or []) | existing_users - unknown_members = set(org_doc.get('unknown_members')) | unknown_users + unknown_members = set(org_doc.get('unknown_members') or []) | unknown_users # Make sure we don't exceed the current seat count. new_seat_count = len(members) + len(unknown_members) @@ -270,7 +270,7 @@ class OrgManager: return False org = self._get_org(org_id, projection={'admin_uid': 1}) - return org['admin_uid'] == uid + return org.get('admin_uid') == uid def unknown_member_roles(self, member_email: str) -> typing.Set[str]: """Returns the set of organization roles for this user. @@ -321,6 +321,9 @@ class OrgManager: """ from pillar.api.utils import str2id + if not member_sting_ids: + return [] + member_ids = [str2id(uid) for uid in member_sting_ids] users_coll = current_app.db('users') users = users_coll.find({'_id': {'$in': member_ids}}, diff --git a/pillar/web/organizations/routes.py b/pillar/web/organizations/routes.py index 9a26f248..21bed490 100644 --- a/pillar/web/organizations/routes.py +++ b/pillar/web/organizations/routes.py @@ -55,6 +55,9 @@ def view_embed(organization_id: str): member['avatar'] = gravatar(member.get('email')) member['_id'] = str(member['_id']) + # Make sure it's never None + organization.unknown_members = organization.unknown_members or [] + can_edit = om.user_is_admin(organization_oid) csrf = flask_wtf.csrf.generate_csrf() diff --git a/src/templates/organizations/index.jade b/src/templates/organizations/index.jade index 2cd03c57..59c8acf9 100644 --- a/src/templates/organizations/index.jade +++ b/src/templates/organizations/index.jade @@ -43,7 +43,7 @@ #item-action-panel | {% if can_create_organization %} - button.btn(onclick='createNewOrganization(this)') Create new organization (max {{max_organizations}}) + button.btn(onclick='createNewOrganization(this)') Create new organization #create_organization_result_panel | {% endif %} @@ -151,7 +151,7 @@ script. // TODO: create a form to get the initial info from the user. $.post( - '{{ url_for('pillar.organizations.create_new') }}', + '{{ url_for('pillar.web.organizations.create_new') }}', { name: 'New Organization', seat_count: 1, diff --git a/src/templates/organizations/view_embed.jade b/src/templates/organizations/view_embed.jade index 8a2a7915..e44cadf1 100644 --- a/src/templates/organizations/view_embed.jade +++ b/src/templates/organizations/view_embed.jade @@ -52,9 +52,8 @@ .table-row.properties-org-roles .table-cell User roles .table-cell(title='Unable to edit, determined by subscription') - | {{ organization.org_roles | sort | join(', ') }} + | {{ organization.org_roles | hide_none | sort | join(', ') }} - .flamenco-box.manager h4 Organization members | {% if can_edit %}