Skip to content

Commit

Permalink
Changed Email Token Invitation API to be more RESTful
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonXue committed Jun 25, 2015
1 parent 003959c commit a985cad
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions refinery/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@ def res_sharing(self, request, **kwargs):
if not user.is_authenticated() and res and not res.is_public():
return HttpUnauthorized()

logger.info("ere")

if request.method == 'GET':
kwargs['sharing'] = True
return self.process_get(request, res, **kwargs)
Expand Down Expand Up @@ -1297,19 +1295,27 @@ def prepend_urls(self):
url(r'^invitation/update/$',
self.wrap_view('update_db'),
name='api_invitation_update_db'),
url(r'^invitation/send/(?P<group_id>%s)/(?P<email>%s)/$'
% (self.group_id_regex, self.email_regex),
url(r'^invitation/send/$',
self.wrap_view('email_token'),
name='api_invitation_email_token'),

]

def get_token(self, request, **kwargs):
self.update_db(request, **kwargs)

if request.method == 'GET':
if request.method == 'GET' or request.method == 'POST':
user = request.user
group = self.get_group(int(kwargs['group_id']))
group = None

if request.method == 'GET':
group = self.get_group(int(kwargs['group_id']))

if request.method == 'POST':
data = request.raw_post_data
group = self.get_group(int(json.loads(data)['group_id']))

if not group:
return HttpBadRequest()

if not self.user_authorized(user, group):
return HttpUnauthorized()
Expand Down Expand Up @@ -1360,7 +1366,10 @@ def update_db(self, request, **kwargs):


def email_token(self, request, **kwargs):
group = self.get_group(int(kwargs['group_id']))
self.update_db(request, **kwargs)

data = json.loads(request.raw_post_data)
group = self.get_group(int(data['group_id']))

if not self.user_authorized(request.user, group):
return HttpUnauthorized()
Expand All @@ -1371,7 +1380,7 @@ def email_token(self, request, **kwargs):
return HttpUnauthorized()

token = get_token_response.content
address = kwargs['email']
address = data['email']
subject = 'Invitation to join group %s' % group.name
body = """
You have been invited to join %s. Please use the following steps:
Expand Down

0 comments on commit a985cad

Please sign in to comment.