Skip to content

Commit dba2733

Browse files
author
Jonathan Spalink
committed
* Added a "minimal" parameter to user lists (users, applications, groups)
* Added an applications/application/:appid/groups call to display groups for the specified applicaiton * updated setup to require >= falcon 1.2
1 parent 91fade2 commit dba2733

File tree

8 files changed

+64
-1
lines changed

8 files changed

+64
-1
lines changed

econtextauth/engine/routes/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
applications.application.Application,
2020
applications.applications.Applications,
2121
applications.users.Users,
22+
applications.groups.Groups,
2223
groups.group.Group,
2324
groups.groups.Groups,
2425
groups.users.Users,
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from . import application
22
from . import applications
33
from . import users
4+
from . import groups
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import logging
2+
from econtextauth.models.application import application
3+
from econtextauth.models.group import group
4+
import falcon
5+
6+
log = logging.getLogger('econtext')
7+
8+
9+
class Groups:
10+
"""
11+
Groups
12+
13+
GET - Retrieve all groups associated with a particular application
14+
"""
15+
routes = ['applications/application/{appid}/groups']
16+
17+
def __init__(self, econtext):
18+
self.econtext = econtext
19+
20+
@staticmethod
21+
def get_route_constructor(*args, **kwargs):
22+
return Groups(*args)
23+
24+
def on_get(self, req, resp, appid):
25+
"""
26+
Retrieve all groups belonging to an application
27+
28+
:param req:
29+
:param resp:
30+
:return:
31+
"""
32+
app = application.Application.get(appid)
33+
if not app:
34+
raise falcon.HTTPInvalidParam("Application could not be found", 'appid')
35+
groups = list(group.Group.filter(application_id=appid))
36+
resp.body = {"groups": groups}
37+
return True

econtextauth/engine/routes/applications/users.py

+2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,7 @@ def on_get(self, req, resp, appid):
3232
if not app:
3333
raise falcon.HTTPInvalidParam("Application could not be found", 'appid')
3434
users = [a for a in app.fields.users.all()]
35+
if req.get_param('minimal'):
36+
users = [u.json_minimal for u in users]
3537
resp.body = {"users": users}
3638
return True

econtextauth/engine/routes/groups/users.py

+6
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ def on_get(self, req, resp, groupid):
3333
grp = group.Group.get(groupid)
3434
if not grp:
3535
raise falcon.HTTPInvalidParam("Group could not be found", 'groupid')
36+
37+
status = req.get_param('status')
3638

3739
query = r.table('_group_users').get_all(groupid, index='group_id').eq_join('user_id', r.table('users'), index='id').map(lambda x: x['right'])
3840
users = [user.User(**u) for u in query.run()]
41+
if status:
42+
users = [u for u in users if u['status'] == status]
43+
if req.get_param('minimal'):
44+
users = [u.json_minimal for u in users]
3945
resp.body = {"users": users}
4046
return True

econtextauth/engine/routes/users/users.py

+2
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@ def on_get(self, req, resp):
2929
:return:
3030
"""
3131
users = list(user.User.all())
32+
if req.get_param('minimal'):
33+
users = [u.json_minimal for u in users]
3234
resp.body = {"users": users}
3335
return True

econtextauth/models/user/user.py

+14
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ def json(self):
5151
'groups': list(self.fields.groups.all())
5252
}
5353

54+
@property
55+
def json_minimal(self):
56+
return { # base user data
57+
'id': self.get('id'),
58+
'name': self.get('name'),
59+
'email': self.get('email'),
60+
'username': self.get('username'),
61+
'custom_data': self.get('custom_data'),
62+
'href': '{}/api/users/user/{}'.format(get_base_url(), self.get('id')),
63+
'created_at': str(self.get('created_at') or ''),
64+
'modified_at': str(self.get('modified_at') or ''),
65+
'status': self.get('status', 'DISABLED')
66+
}
67+
5468
@staticmethod
5569
def create_new(email, password, applications, name=None, custom_data=None, status='UNVERIFIED', id_=None, username=None, groups=None, *args, **kwargs):
5670
"""

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
data_files=data_files,
1717
install_requires=[
1818
'requests',
19-
'falcon >= 1.1',
19+
'falcon >= 1.2',
2020
'gevent',
2121
'gunicorn',
2222
'rethinkdb',

0 commit comments

Comments
 (0)