diff --git a/README.md b/README.md index fed978c..ef8e815 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ REST API `GET /projects/` +`GET /projects/?team=[team_name]` + `GET /projects/:name` `POST /projects/` @@ -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 \ No newline at end of file +`GET /profile/` + +`GET /profile/:name` + +#### Auth + +`GET /authorize/` + +`POST /authorize/` + +`POST /token/` + +`POST /revoke_token/` \ No newline at end of file diff --git a/api/project.py b/api/project.py index 185de9a..4ca9534 100644 --- a/api/project.py +++ b/api/project.py @@ -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() diff --git a/api/repo.py b/api/repo.py index 080f26c..ab7c752 100644 --- a/api/repo.py +++ b/api/repo.py @@ -2,7 +2,7 @@ # # @name: api/repo.py # @create: Apr. 22th, 2014 -# @update: Aug. 22th, 2014 +# @update: Aug. 27th, 2014 # @author: hitigon@gmail.com from __future__ import print_function import re @@ -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, @@ -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'] @@ -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) diff --git a/api/task.py b/api/task.py index 2bd2079..3e98b98 100644 --- a/api/task.py +++ b/api/task.py @@ -2,7 +2,7 @@ # # @name: api/project.py # @create: Jun. 10th, 2014 -# @update: Aug. 23th, 2014 +# @update: Aug. 27th, 2014 # @author: hitigon@gmail.com from __future__ import print_function from utils import get_utc_time @@ -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() @@ -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 = [] diff --git a/api/user.py b/api/user.py index fe7aca0..4fdfe57 100644 --- a/api/user.py +++ b/api/user.py @@ -2,7 +2,7 @@ # # @name: api/user.py # @create: Apr. 27th, 2014 -# @update: Aug. 22th, 2014 +# @update: Aug. 27th, 2014 # @author: hitigon@gmail.com from __future__ import print_function from utils import parse_path, create_password