From 207e7948d65bb391c7bd8821ca2f0a1e86ed52b1 Mon Sep 17 00:00:00 2001 From: Paul Van Eck Date: Wed, 2 Mar 2016 21:29:56 -0800 Subject: [PATCH] Make profile endpoint not error out This patch makes it so that the check for if a user is a foundation admin will not error out when a foundation org does not exist. Instead an empty list is returned, saying that there are no foundation users. The documentation was also updated to give instructions for creating the Foundation group/organization, and adding a user to it. Closes-Bug: #1552548 Change-Id: If675d856b69ab854a3daf296f81050525ba5d50b --- doc/refstack.md | 32 ++++++++++++++++++++++++++++++++ refstack/db/sqlalchemy/api.py | 5 ++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/doc/refstack.md b/doc/refstack.md index 4bd7d01e..d4860edc 100755 --- a/doc/refstack.md +++ b/doc/refstack.md @@ -196,3 +196,35 @@ Now available: - `http://:8000/v1/results/` with response JSON including the detail test results of the specified `` + +####(Optional) Configure Foundation organization and group + +Overall RefStack admin access is given to users belonging to a "Foundation" +organization. To become a Foundation admin, first a "Foundation" organization +must be created. Note that you must have logged into RefStack at least once so +that a user record for your account is created. + +- Log into MySQL: `mysql -u root -p` + +- Create a group for the "Foundation" organization: + + `INSERT INTO refstack.group (id, name, created_at) VALUES (UUID(), 'Foundation Group', NOW());` + +- Get the group ID for the group you just created: + + `SELECT id from refstack.group WHERE name = 'Foundation Group';` + +- Get your OpenID: + + `SELECT openid from refstack.user WHERE email = '';` + +- Add your user account to the previously created "Foundation" group. Replace + `` and `` with the values retrieved in the two previous steps: + + `INSERT INTO refstack.user_to_group (created_by_user, user_openid, group_id, created_at) + VALUES ('', '', '', NOW());` + +- Create the actual "Foundation" organization using this group: + + `INSERT INTO refstack.organization (id, type, name, group_id, created_by_user, created_at) + VALUES (UUID(), 0, 'Foundation', '', '', NOW());` diff --git a/refstack/db/sqlalchemy/api.py b/refstack/db/sqlalchemy/api.py index 69221d3c..be8cd45d 100644 --- a/refstack/db/sqlalchemy/api.py +++ b/refstack/db/sqlalchemy/api.py @@ -23,6 +23,7 @@ import uuid from oslo_config import cfg from oslo_db import options as db_options from oslo_db.sqlalchemy import session as db_session +from oslo_log import log import six from refstack.api import constants as api_const @@ -32,6 +33,7 @@ from refstack.db.sqlalchemy import models CONF = cfg.CONF _FACADE = None +LOG = log.getLogger(__name__) db_options.set_defaults(cfg.CONF) @@ -490,7 +492,8 @@ def get_foundation_users(): session.query(models.Organization.group_id) .filter_by(type=api_const.FOUNDATION).first()) if organization is None: - raise NotFound('Foundation record could not found in DB.') + LOG.warning('Foundation organization record not found in DB.') + return [] group_id = organization.group_id users = (session.query(models.UserToGroup.user_openid). filter_by(group_id=group_id))