Skip to content

Commit

Permalink
modify apis and README
Browse files Browse the repository at this point in the history
  • Loading branch information
hitigon committed Aug 27, 2014
1 parent 010f173 commit 208f8b0
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 53 deletions.
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ REST API

`GET /projects/`

`GET /projects/?team=[team_name]`

`GET /projects/:name`

`POST /projects/`
Expand All @@ -35,10 +37,50 @@ REST API

#### Tasks

`GET /tasks/`

`GET /tasks/?project=[project_name]`

`POST /tasks/`

`PUT /tasks/:name`

`DELETE /tasks/:name`

#### Repos

`GET /repos/`

`GET /repos/?team=[team_name]`

`POST /repos/`

`PUT /repos/:name`

`DELETE /repos/:name`

#### Teams

`GET /teams/`

`POST /teams/`

`PUT /teams/:name`

`DELETE /teams/:name`

#### Profile

#### Auth
`GET /profile/`

`GET /profile/:name`

#### Auth

`GET /authorize/`

`POST /authorize/`

`POST /token/`

`POST /revoke_token/`
17 changes: 4 additions & 13 deletions api/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,16 @@ def get(self, *args, **kwargs):
project_data = document_to_json(project, filter_set=_FILTER)
else:
team_name = self.get_argument('team', None)
username = self.get_argument('username', None)

try:
team_name = parse_path(team_name)[0]
except IndexError:
team_name = 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()
Expand Down
30 changes: 14 additions & 16 deletions api/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# @name: api/repo.py
# @create: Apr. 22th, 2014
# @update: Aug. 22th, 2014
# @update: Aug. 27th, 2014
# @author: [email protected]
from __future__ import print_function
import re
Expand All @@ -12,6 +12,7 @@
from oauth.protector import authenticated
from scm.git import GitRepo
from models.repo import Repo
from models.team import Team

_SUB_FILTER = {
'password': False,
Expand All @@ -33,12 +34,6 @@ class RepoHandler(BaseHandler):

@authenticated(scopes=['repos'])
def get(self, *args, **kwargs):
# /repos
# /repos/:path
# /repos?username=
# /repos?team=
# /repos?project=
# /repos?tag=
if 'user' not in kwargs:
self.raise401()
user = kwargs['user']
Expand All @@ -63,15 +58,18 @@ def get(self, *args, **kwargs):
self.raise404()
repo_data = document_to_json(repo, filter_set=_FILTER)
else:
username = self.get_argument('username', None)
team = self.get_argument('team_name', None)
project = self.get_argument('project_name', None)
if username:
pass
elif team:
pass
elif project:
pass
team_name = self.get_argument('team_name', None)
try:
team_name = parse_path(team_name)[0]
except IndexError:
team_name = None
if team_name:
team = Team.objects(name=team_name).first()
if not team:
self.raise404()
if user not in team.member:
self.raise403()
repos = Repo.objects(team=team).all()
else:
repos = Repo.objects(owner=user).all()
repo_data = query_to_json(repos, filter_set=_FILTER)
Expand Down
28 changes: 6 additions & 22 deletions api/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# @name: api/project.py
# @create: Jun. 10th, 2014
# @update: Aug. 23th, 2014
# @update: Aug. 27th, 2014
# @author: [email protected]
from __future__ import print_function
from utils import get_utc_time
Expand Down Expand Up @@ -47,13 +47,6 @@ class TaskHandler(BaseHandler):

@authenticated(scopes=['tasks'])
def get(self, *args, **kwargs):
# 1, all tasks in your projects
# 2, all user's tasks
# 3, specified task (id)
# /tasks
# /tasks/:id
# /tasks/?project=
# /tasks/?username=
if 'user' not in kwargs:
self.raise401()

Expand All @@ -68,27 +61,18 @@ def get(self, *args, **kwargs):
self.raise401()
task_data = document_to_json(task, filter_set=_FILTER)
else:
username = self.get_argument('username', None)
project_name = self.get_argument('project', None)
try:
project_name = parse_path(project_name)[0]
except IndexError:
project_name = None
try:
username = parse_path(username)[0]
except IndexError:
username = None
if project_name and username:
user = User.objects(username=username).first()
project = Project.objects(name=project_name).first()
tasks = Task.objects(
project=project, assign_to__in=[user]).all()
elif project_name:
if project_name:
project = Project.objects(name=project_name).first()
if not project:
self.raise404()
if user not in project.members:
self.raise403()
tasks = Task.objects(project=project).all()
elif username:
user = User.objects(username=username).first()
tasks = Task.objects(assign_to__in=[user]).all()
else:
projects = Project.objects(members__in=[user]).all()
tasks = []
Expand Down
2 changes: 1 addition & 1 deletion api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# @name: api/user.py
# @create: Apr. 27th, 2014
# @update: Aug. 22th, 2014
# @update: Aug. 27th, 2014
# @author: [email protected]
from __future__ import print_function
from utils import parse_path, create_password
Expand Down

0 comments on commit 208f8b0

Please sign in to comment.