def get(self, *args, **kwargs): if 'user' not in kwargs: self.raise401() if not args: self.raise404() path = parse_path(args[0]) task = Task.objects(id=path[0]).first() if not task: self.raise404() user = kwargs['user'] if user not in task.project.members: self.raise401() limit = self.get_argument('limit', None) start = self.get_argument('start', None) try: limit = int(limit) except: limit = None try: start = int(start) except: start = None comments = task.comments if limit and start: comments = task.comments[start:start+limit] elif limit: comments = task.comments[:limit] elif start: comments = task.comments[start:] else: comments = task.comments comment_data = query_to_json(comments, filter_set=_COMMENT_FILTER) self.write(comment_data)
def get(self, *args, **kwargs): if 'user' not in kwargs: self.raise401() if not args: self.raise404() path = parse_path(args[0]) task = Task.objects(id=path[0]).first() if not task: self.raise404() user = kwargs['user'] if user not in task.project.members: self.raise401() limit = self.get_argument('limit', None) start = self.get_argument('start', None) try: limit = int(limit) except: limit = None try: start = int(start) except: start = None comments = task.comments if limit and start: comments = task.comments[start:start + limit] elif limit: comments = task.comments[:limit] elif start: comments = task.comments[start:] else: comments = task.comments comment_data = query_to_json(comments, filter_set=_COMMENT_FILTER) self.write(comment_data)
def get(self, *args, **kwargs): # /clients # /clients/:app_name if 'user' not in kwargs: self.raise401() user = kwargs['user'] if args: path = parse_path(args[0]) client = Client.objects(user=user, app_name=path[0]).first() if not client: self.raise404() client_data = document_to_json(client, filter_set=_FILTER) else: limit = self.get_argument('limit', None) start = self.get_argument('start', None) try: limit = int(limit) except: limit = None try: start = int(start) except: start = None clients = Client.objects(user=user) if limit and start: clients = clients[start: start+limit] elif limit: clients = clients[:limit] elif start: clients = clients[start:] client_data = query_to_json(clients, filter_set=_FILTER) self.write(client_data)
def get(self, *args, **kwargs): if 'user' not in kwargs: self.raise401() user = kwargs['user'] if args: path = parse_path(args[0]) task = Task.objects(id=path[0]).first() if not task: self.raise404() if user not in task.project.members: self.raise401() task_data = document_to_json(task, filter_set=_FILTER) else: project_name = self.get_argument('project', None) limit = self.get_argument('limit', None) start = self.get_argument('start', None) try: limit = int(limit) except: limit = None try: start = int(start) except: start = None try: project_name = parse_path(project_name)[0] except IndexError: project_name = None 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) else: projects = Project.objects(members__in=[user]).all() tasks = [] for project in projects: ts = Task.objects(project=project).all() tasks += list(ts) if limit and start: tasks = tasks[start: start+limit] elif limit: tasks = tasks[:limit] elif start: tasks = tasks[start:] task_data = query_to_json(tasks, filter_set=_FILTER) self.write(task_data)
def get(self, *args, **kwargs): if 'user' not in kwargs: self.raise401() user = kwargs['user'] if args: path = parse_path(args[0]) task = Task.objects(id=path[0]).first() if not task: self.raise404() if user not in task.project.members: self.raise401() task_data = document_to_json(task, filter_set=_FILTER) else: project_name = self.get_argument('project', None) limit = self.get_argument('limit', None) start = self.get_argument('start', None) try: limit = int(limit) except: limit = None try: start = int(start) except: start = None try: project_name = parse_path(project_name)[0] except IndexError: project_name = None 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) else: projects = Project.objects(members__in=[user]).all() tasks = [] for project in projects: ts = Task.objects(project=project).all() tasks += list(ts) if limit and start: tasks = tasks[start:start + limit] elif limit: tasks = tasks[:limit] elif start: tasks = tasks[start:] task_data = query_to_json(tasks, filter_set=_FILTER) self.write(task_data)
def get(self, *args, **kwargs): if 'user' not in kwargs: self.raise401() user = kwargs['user'] if args: path = parse_path(args[0]) team = Team.objects(name=path[0]).first() if not team: self.raise404() team_data = document_to_json(team, filter_set=_FILTER) else: # username = self.get_argument('username', None) # try: # username = parse_path(username)[0] # except IndexError: # username = None # if username: # user = User.objects(username=username).fisrt() limit = self.get_argument('limit', None) start = self.get_argument('start', None) try: limit = int(limit) except: limit = None try: start = int(start) except: start = None teams = Team.objects(members__in=[user]) if limit and start: teams = teams[start: start+limit] elif limit: teams = teams[:limit] elif start: teams = teams[start:] team_data = query_to_json(teams, filter_set=_FILTER) self.write(team_data)
def get(self, *args, **kwargs): if 'user' not in kwargs: self.raise401() user = kwargs['user'] repo_type = None repo_query = None repo_contents = None repo_branches = None repo_tags = None repo_info = None limit = self.get_argument('limit', None) start = self.get_argument('start', None) try: limit = int(limit) except: limit = None if args: # author = self.get_argument('author', None) path = parse_path(args[0]) if not path: self.raise404() repo = Repo.objects(owner=user, name=path[0]).first() if repo: scm_repo = GitRepo(repo.path) repo_info = scm_repo.get_info() repo_branches, repo_tags = get_repo_branches_tags(scm_repo) repo_type, repo_query, repo_contents = get_repo_contents( scm_repo, path[1:], limit=limit, start=start) if not repo_contents: self.raise404() repo_data = document_to_json(repo, filter_set=_FILTER) else: team_name = self.get_argument('team_name', None) try: start = int(start) except: start = 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) else: repos = Repo.objects(owner=user) if limit and start: repos = repos[start: start+limit] elif limit: repos = repos[:limit] elif start: repos = repos[start:] repo_data = query_to_json(repos, filter_set=_FILTER) if repo_type and repo_contents: repo_data['repo_info'] = repo_info repo_data['repo_type'] = repo_type repo_data['repo_query'] = repo_query repo_data['repo_branches'] = repo_branches repo_data['repo_tags'] = repo_tags repo_data['repo_contents'] = repo_contents self.write(repo_data)
def get(self, *args, **kwargs): """Retrieve the resources of projects for the current user. If `*args` is provided by matching the URL pattern, the first element in the args is considered as a project name, then the project data will be retrieved from Database and send back to the client and the source owner in the format of JSON. Otherwise, it responses with a list of projects parcipated by the user. The request can provide three arugments: `team`, `limit` and `start`. `team` is used for querying the projects of one team by its name, which the user is one of its memebers. `limit` is the max number of items sent back to the client. `start` is the starting index of the querying results. Only authenticated user/resouce owner can access by using access_token, and his/her scopes must include `projects`. The retrieved resource should always be related to the user, and it is not allowed to access others' projects or other teams' projects. .. todo:: restrict the response data and add default limits """ if 'user' not in kwargs: self.raise401() user = kwargs['user'] if args: path = parse_path(args[0]) project = Project.objects(name=path[0]).first() if not project: self.raise404() if project and user not in project.members: self.raise401() project_data = document_to_json(project, filter_set=_FILTER) else: team_name = self.get_argument('team', None) limit = self.get_argument('limit', None) start = self.get_argument('start', None) try: team_name = parse_path(team_name)[0] except IndexError: team_name = None try: limit = int(limit) except Exception: limit = None try: start = int(start) except Exception: start = None if team_name: team = Team.objects(name=team_name).first() if not team: self.raise404() if user not in team.members: self.raise403() project = Project.objects(teams__in=[team]) else: project = Project.objects(members__in=[user]) if limit and start: project = project[start:start + limit] elif limit: project = project[:limit] elif start: project = project[start:] project_data = query_to_json(project, filter_set=_FILTER) self.write(project_data)