You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kibble.apache.org by hu...@apache.org on 2018/02/15 14:55:44 UTC
[kibble] branch master updated: make doubly sure there is a default
org
This is an automated email from the ASF dual-hosted git repository.
humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kibble.git
The following commit(s) were added to refs/heads/master by this push:
new 87747c7 make doubly sure there is a default org
87747c7 is described below
commit 87747c71d587cf9986d5d865410494511ada7f87
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Thu Feb 15 15:55:35 2018 +0100
make doubly sure there is a default org
..and that it exists in the DB, otherwise croak.
This should fix #6.
---
api/pages/sources.py | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/api/pages/sources.py b/api/pages/sources.py
index 9e4856c..a571d35 100644
--- a/api/pages/sources.py
+++ b/api/pages/sources.py
@@ -134,14 +134,15 @@ import yaml
def canModifySource(session):
""" Determine if the user can edit sources in this org """
- if session.user['userlevel'] == 'admin':
- return True
dOrg = session.user['defaultOrganisation'] or "apache"
if session.DB.ES.exists(index=session.DB.dbname, doc_type="organisation", id= dOrg):
xorg = session.DB.ES.get(index=session.DB.dbname, doc_type="organisation", id= dOrg)['_source']
if session.user['email'] in xorg['admins']:
return True
+ if session.user['userlevel'] == 'admin':
+ return True
+ return False
def run(API, environ, indata, session):
@@ -153,12 +154,17 @@ def run(API, environ, indata, session):
if method in ['GET', 'POST']:
# Fetch organisation data
- dOrg = session.user['defaultOrganisation'] or "apache"
+
+ # Make sure we have a default/current org set
+ if 'defaultOrganisation' not in session.user or not session.user['defaultOrganisation']:
+ raise API.exception(400, "You must specify an organisation as default/current in order to add sources.")
+
+ dOrg = session.user['defaultOrganisation']
if session.DB.ES.exists(index=session.DB.dbname, doc_type="organisation", id= dOrg):
org = session.DB.ES.get(index=session.DB.dbname, doc_type="organisation", id= dOrg)['_source']
del org['admins']
else:
- raise API.exception(404, "No such organisation, '%s'" % dOrg)
+ raise API.exception(404, "No such organisation, '%s'" % (dOrg or "(None)"))
sourceTypes = indata.get('types', [])
# Fetch all sources for default org
@@ -230,7 +236,9 @@ def run(API, environ, indata, session):
creds[el] = source[el]
sourceID = hashlib.sha224( ("%s-%s" % (sourceType, sourceURL)).encode('utf-8') ).hexdigest()
- dOrg = session.user['defaultOrganisation'] or "apache"
+ # Make sure we have a default/current org set
+ if 'defaultOrganisation' not in session.user or not session.user['defaultOrganisation']:
+ raise API.exception(400, "You must first specify an organisation as default/current in order to add sources.")
doc = {
'organisation': dOrg,
--
To stop receiving notification emails like this one, please contact
humbedooh@apache.org.