def setUp(self): Role.create_defaults() self.config = self.app.loom_config if not BA_FIXTURES['resolver']: schema_dir = os.path.join(FIXTURES, 'schema') load_local_schema(self.config.resolver, schema_dir=schema_dir) BA_FIXTURES['resolver'] = self.config.resolver self.config._resolver = BA_FIXTURES['resolver'] self.es = get_es() get_loom_indexer().configure()
def test_roles(self): res = self.client.get('/api/roles') assert res.json['total'] == 3, res.json assert len(res.json['results']) == 3, res.json res = Role.load_or_create('foo', Role.USER, 'Foo User') session.commit() res = self.client.get('/api/roles') assert res.json['total'] == 4, res.json
def create_user(self, id='tester', name=None, email=None, is_admin=False): role = Role.load_or_create(id, Role.USER, name or id, email=email, is_admin=is_admin) session.commit() return role
def apikey_check(auth_header): if not auth_header.lower().startswith('apikey'): return apikey = auth_header.split(' ', 1).pop() role = Role.by_apikey(apikey) if role is None: return session['roles'] = [Role.SYSTEM_GUEST, Role.SYSTEM_USER, role.id] session['user'] = role.id session['is_admin'] = role.is_admin
def callback(): next_url = url_for('base.index') resp = oauth_provider.authorized_response() if resp is None or isinstance(resp, OAuthException): # FIXME: notify the user, somehow. return redirect(next_url) session['oauth'] = resp Role.create_defaults() session['roles'] = [Role.SYSTEM_GUEST, Role.SYSTEM_USER] if 'googleapis.com' in oauth_provider.base_url: me = oauth_provider.get('userinfo') user_id = 'google:%s' % me.data.get('id') role = Role.load_or_create(user_id, Role.USER, me.data.get('name'), email=me.data.get('email')) elif 'occrp.org' in oauth_provider.base_url or \ 'investigativedashboard.org' in oauth_provider.base_url: me = oauth_provider.get('api/2/accounts/profile/') user_id = 'idashboard:user:%s' % me.data.get('id') role = Role.load_or_create(user_id, Role.USER, me.data.get('display_name'), email=me.data.get('email'), is_admin=me.data.get('is_admin')) for group in me.data.get('groups', []): group_id = 'idashboard:%s' % group.get('id') Role.load_or_create(group_id, Role.GROUP, group.get('name')) session['roles'].append(group_id) else: raise RuntimeError("Unknown OAuth URL: %r" % oauth_provider.base_url) session['roles'].append(user_id) session['user'] = role.id session['is_admin'] = role.is_admin db_session.commit() return redirect(next_url)
def get_session(): role = Role.by_id(request.auth_user) if role is not None: apikey = role.apikey role = role.to_dict() role['apikey'] = apikey return jsonify({ 'logged_in': request.logged_in, 'user': role, 'roles': list(request.auth_roles), 'login_uri': url_for('auth.authorize'), 'sources': request.authz_sources, 'collections': request.authz_collections })
def init(): "Initialize all parts of the system" indexer = get_loom_indexer() indexer.configure() Role.create_defaults() session.commit()