Skip to content

Commit

Permalink
modify project api
Browse files Browse the repository at this point in the history
  • Loading branch information
hitigon committed Aug 27, 2014
1 parent 55808f6 commit 010f173
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
30 changes: 24 additions & 6 deletions api/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# @name: api/project.py
# @create: Apr. 25th, 2014
# @update: Aug. 22th, 2014
# @update: Aug. 27th, 2014
# @author: [email protected]
from __future__ import print_function
from oauth.protector import authenticated
Expand Down Expand Up @@ -42,10 +42,6 @@ class ProjectHandler(BaseHandler):

@authenticated(scopes=['projects'])
def get(self, *args, **kwargs):
# /projects/
# /projects/:name (+)
# /projects/?username= (*)
# /projects/?team= (*)
if 'user' not in kwargs:
self.raise401()

Expand All @@ -59,7 +55,29 @@ def get(self, *args, **kwargs):
self.raise401()
project_data = document_to_json(project, filter_set=_FILTER)
else:
project = Project.objects(members__in=[user]).all()
team_name = self.get_argument('team', None)
username = self.get_argument('username', None)

if team_name:
team = Team.objects(name=team_name).first()
if not team:
self.raise404()
if user not in team.members:
self.raise403()

if username:
if username != user.username:
user = User.objects(username=username).first()
if not user:
self.raise404()

if username and team_name:
project = Project.objects(
members__in=[user], teams__in=[team]).all()
elif team_name:
project = Project.objects(teams__in=[team]).all()
else:
project = Project.objects(members__in=[user]).all()
project_data = query_to_json(project, filter_set=_FILTER)
self.write(project_data)

Expand Down
2 changes: 1 addition & 1 deletion api/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def get_repo_contents(scm_repo, fields):
response = scm_repo.get_commit(fields[1])
response['patches'] = patches
elif obj_type == 'commits':
# TODO
# TODO - Must add limits
response = scm_repo.get_commits()
return obj_type, current_query, response

Expand Down

0 comments on commit 010f173

Please sign in to comment.