Ejemplo n.º 1
0
    def list(self, request, **kwargs):
        serializer = ResolverSerializer(data=request.QUERY_PARAMS)
        if not serializer.is_valid():
            raise exc.BadRequest(serializer.errors)

        data = serializer.data

        project_model = apps.get_model("projects", "Project")
        project = get_object_or_404(project_model, slug=data["project"])

        self.check_permissions(request, "list", project)

        result = {"project": project.pk}

        if data["us"] and user_has_perm(request.user, "view_us", project):
            result["us"] = get_object_or_404(project.user_stories.all(),
                                             ref=data["us"]).pk
        if data["task"] and user_has_perm(request.user, "view_tasks", project):
            result["task"] = get_object_or_404(project.tasks.all(),
                                               ref=data["task"]).pk
        if data["issue"] and user_has_perm(request.user, "view_issues",
                                           project):
            result["issue"] = get_object_or_404(project.issues.all(),
                                                ref=data["issue"]).pk
        if data["milestone"] and user_has_perm(request.user, "view_milestones",
                                               project):
            result["milestone"] = get_object_or_404(project.milestones.all(),
                                                    slug=data["milestone"]).pk
        if data["wikipage"] and user_has_perm(request.user, "view_wiki_pages",
                                              project):
            result["wikipage"] = get_object_or_404(project.wiki_pages.all(),
                                                   slug=data["wikipage"]).pk

        return Response(result)
Ejemplo n.º 2
0
    def list(self, request, **kwargs):
        serializer = ResolverSerializer(data=request.QUERY_PARAMS)
        if not serializer.is_valid():
            raise exc.BadRequest(serializer.errors)

        data = serializer.data

        project_model = apps.get_model("projects", "Project")
        project = get_object_or_404(project_model, slug=data["project"])

        self.check_permissions(request, "list", project)

        result = {"project": project.pk}

        if data["us"] and user_has_perm(request.user, "view_us", project):
            result["us"] = get_object_or_404(project.user_stories.all(),
                                             ref=data["us"]).pk
        if data["task"] and user_has_perm(request.user, "view_tasks", project):
            result["task"] = get_object_or_404(project.tasks.all(),
                                               ref=data["task"]).pk
        if data["issue"] and user_has_perm(request.user, "view_issues", project):
            result["issue"] = get_object_or_404(project.issues.all(),
                                                ref=data["issue"]).pk
        if data["milestone"] and user_has_perm(request.user, "view_milestones", project):
            result["milestone"] = get_object_or_404(project.milestones.all(),
                                                    slug=data["milestone"]).pk
        if data["wikipage"] and user_has_perm(request.user, "view_wiki_pages", project):
            result["wikipage"] = get_object_or_404(project.wiki_pages.all(),
                                                   slug=data["wikipage"]).pk

        return response.Ok(result)
Ejemplo n.º 3
0
def test_authenticated_user_has_perm_on_project_related_object():
    user1 = factories.UserFactory()
    project = factories.ProjectFactory()
    project.public_permissions = ["test"]
    us = factories.UserStoryFactory(project=project)

    assert service.user_has_perm(user1, "test", us) is True
    assert service.user_has_perm(user1, "fail", us) is False
def test_authenticated_user_has_perm_on_project_related_object():
    user1 = factories.UserFactory()
    project = factories.ProjectFactory()
    project.public_permissions = ["test"]
    us = factories.UserStoryFactory(project=project)

    assert service.user_has_perm(user1, "test", us) is True
    assert service.user_has_perm(user1, "fail", us) is False
Ejemplo n.º 5
0
def _filter_by_permissions(obj, user):
    UserStory = apps.get_model("userstories", "UserStory")
    Issue = apps.get_model("issues", "Issue")
    Task = apps.get_model("tasks", "Task")
    WikiPage = apps.get_model("wiki", "WikiPage")

    if isinstance(obj, UserStory):
        return user_has_perm(user, "view_us", obj)
    elif isinstance(obj, Issue):
        return user_has_perm(user, "view_issues", obj)
    elif isinstance(obj, Task):
        return user_has_perm(user, "view_tasks", obj)
    elif isinstance(obj, WikiPage):
        return user_has_perm(user, "view_wiki_pages", obj)
    return False
Ejemplo n.º 6
0
def _filter_by_permissions(obj, user):
    UserStory = apps.get_model("userstories", "UserStory")
    Issue = apps.get_model("issues", "Issue")
    Task = apps.get_model("tasks", "Task")
    WikiPage = apps.get_model("wiki", "WikiPage")

    if isinstance(obj, UserStory):
        return user_has_perm(user, "view_us", obj)
    elif isinstance(obj, Issue):
        return user_has_perm(user, "view_issues", obj)
    elif isinstance(obj, Task):
        return user_has_perm(user, "view_tasks", obj)
    elif isinstance(obj, WikiPage):
        return user_has_perm(user, "view_wiki_pages", obj)
    return False
Ejemplo n.º 7
0
 def check_permissions(self, request, view, obj=None):
     Project = apps.get_model('projects', 'Project')
     project_id = request.QUERY_PARAMS.get("project", None)
     try:
         project = Project.objects.get(pk=project_id)
     except Project.DoesNotExist:
         return False
     return user_has_perm(request.user, self.project_perm, project)
Ejemplo n.º 8
0
 def check_permissions(self, request, view, obj=None):
     Project = apps.get_model('projects', 'Project')
     project_id = request.QUERY_PARAMS.get("project", None)
     try:
         project = Project.objects.get(pk=project_id)
     except Project.DoesNotExist:
         return False
     return user_has_perm(request.user, self.project_perm, project)
Ejemplo n.º 9
0
    def list(self, request, **kwargs):
        text = request.QUERY_PARAMS.get('text', "")
        project_id = request.QUERY_PARAMS.get('project', None)

        project = self._get_project(project_id)

        result = {}
        if user_has_perm(request.user, "view_us", project):
            result["userstories"] = self._search_user_stories(project, text)
        if user_has_perm(request.user, "view_tasks", project):
            result["tasks"] = self._search_tasks(project, text)
        if user_has_perm(request.user, "view_issues", project):
            result["issues"] = self._search_issues(project, text)
        if user_has_perm(request.user, "view_wiki_pages", project):
            result["wikipages"] = self._search_wiki_pages(project, text)

        result["count"] = sum(map(lambda x: len(x), result.values()))
        return Response(result)
Ejemplo n.º 10
0
    def list(self, request, **kwargs):
        serializer = ResolverSerializer(data=request.QUERY_PARAMS)
        if not serializer.is_valid():
            raise exc.BadRequest(serializer.errors)

        data = serializer.data

        project_model = apps.get_model("projects", "Project")
        project = get_object_or_404(project_model, slug=data["project"])

        self.check_permissions(request, "list", project)

        result = {"project": project.pk}

        if data["us"] and user_has_perm(request.user, "view_us", project):
            result["us"] = get_object_or_404(project.user_stories.all(),
                                             ref=data["us"]).pk
        if data["task"] and user_has_perm(request.user, "view_tasks", project):
            result["task"] = get_object_or_404(project.tasks.all(),
                                               ref=data["task"]).pk
        if data["issue"] and user_has_perm(request.user, "view_issues",
                                           project):
            result["issue"] = get_object_or_404(project.issues.all(),
                                                ref=data["issue"]).pk
        if data["milestone"] and user_has_perm(request.user, "view_milestones",
                                               project):
            result["milestone"] = get_object_or_404(project.milestones.all(),
                                                    slug=data["milestone"]).pk
        if data["wikipage"] and user_has_perm(request.user, "view_wiki_pages",
                                              project):
            result["wikipage"] = get_object_or_404(project.wiki_pages.all(),
                                                   slug=data["wikipage"]).pk

        if data["ref"]:
            ref_found = False  # No need to continue once one ref is found
            if user_has_perm(request.user, "view_us", project):
                us = project.user_stories.filter(ref=data["ref"]).first()
                if us:
                    result["us"] = us.pk
                    ref_found = True
            if ref_found is False and user_has_perm(request.user, "view_tasks",
                                                    project):
                task = project.tasks.filter(ref=data["ref"]).first()
                if task:
                    result["task"] = task.pk
                    ref_found = True
            if ref_found is False and user_has_perm(request.user,
                                                    "view_issues", project):
                issue = project.issues.filter(ref=data["ref"]).first()
                if issue:
                    result["issue"] = issue.pk

        return response.Ok(result)
Ejemplo n.º 11
0
    def list(self, request, **kwargs):
        text = request.QUERY_PARAMS.get('text', "")
        project_id = request.QUERY_PARAMS.get('project', None)

        project = self._get_project(project_id)

        result = {}
        with futures.ThreadPoolExecutor(max_workers=4) as executor:
            futures_list = []
            if user_has_perm(request.user, "view_us", project):
                uss_future = executor.submit(self._search_user_stories,
                                             project, text)
                uss_future.result_key = "userstories"
                futures_list.append(uss_future)
            if user_has_perm(request.user, "view_tasks", project):
                tasks_future = executor.submit(self._search_tasks, project,
                                               text)
                tasks_future.result_key = "tasks"
                futures_list.append(tasks_future)
            if user_has_perm(request.user, "view_issues", project):
                issues_future = executor.submit(self._search_issues, project,
                                                text)
                issues_future.result_key = "issues"
                futures_list.append(issues_future)
            if user_has_perm(request.user, "view_wiki_pages", project):
                wiki_pages_future = executor.submit(self._search_wiki_pages,
                                                    project, text)
                wiki_pages_future.result_key = "wikipages"
                futures_list.append(wiki_pages_future)

            for future in futures.as_completed(futures_list):
                data = []
                try:
                    data = future.result()
                except Exception as exc:
                    print('%s generated an exception: %s' %
                          (future.result_key, exc))
                finally:
                    result[future.result_key] = data

        result["count"] = sum(map(lambda x: len(x), result.values()))
        return response.Ok(result)
Ejemplo n.º 12
0
    def list(self, request, **kwargs):
        serializer = ResolverSerializer(data=request.QUERY_PARAMS)
        if not serializer.is_valid():
            raise exc.BadRequest(serializer.errors)

        data = serializer.data

        project_model = apps.get_model("projects", "Project")
        project = get_object_or_404(project_model, slug=data["project"])

        self.check_permissions(request, "list", project)

        result = {"project": project.pk}

        if data["us"] and user_has_perm(request.user, "view_us", project):
            result["us"] = get_object_or_404(project.user_stories.all(),
                                             ref=data["us"]).pk
        if data["task"] and user_has_perm(request.user, "view_tasks", project):
            result["task"] = get_object_or_404(project.tasks.all(),
                                               ref=data["task"]).pk
        if data["issue"] and user_has_perm(request.user, "view_issues", project):
            result["issue"] = get_object_or_404(project.issues.all(),
                                                ref=data["issue"]).pk
        if data["milestone"] and user_has_perm(request.user, "view_milestones", project):
            result["milestone"] = get_object_or_404(project.milestones.all(),
                                                    slug=data["milestone"]).pk
        if data["wikipage"] and user_has_perm(request.user, "view_wiki_pages", project):
            result["wikipage"] = get_object_or_404(project.wiki_pages.all(),
                                                   slug=data["wikipage"]).pk

        if data["ref"]:
            ref_found = False  # No need to continue once one ref is found
            if user_has_perm(request.user, "view_us", project):
                us = project.user_stories.filter(ref=data["ref"]).first()
                if us:
                    result["us"] = us.pk
                    ref_found = True
            if ref_found is False and user_has_perm(request.user, "view_tasks", project):
                task = project.tasks.filter(ref=data["ref"]).first()
                if task:
                    result["task"] = task.pk
                    ref_found = True
            if ref_found is False and user_has_perm(request.user, "view_issues", project):
                issue = project.issues.filter(ref=data["ref"]).first()
                if issue:
                    result["issue"] = issue.pk

        return response.Ok(result)
Ejemplo n.º 13
0
    def list(self, request, **kwargs):
        project_model = apps.get_model("projects", "Project")

        text = request.QUERY_PARAMS.get('text', "")
        project_id = request.QUERY_PARAMS.get('project', None)

        try:
            project = self._get_project(project_id)
        except (project_model.DoesNotExist, TypeError):
            raise excp.PermissionDenied({"detail": "Wrong project id"})

        result = {}
        if user_has_perm(request.user, "view_us", project):
            result["userstories"] = self._search_user_stories(project, text)
        if user_has_perm(request.user, "view_tasks", project):
            result["tasks"] = self._search_tasks(project, text)
        if user_has_perm(request.user, "view_issues", project):
            result["issues"] = self._search_issues(project, text)
        if user_has_perm(request.user, "view_wiki_pages", project):
            result["wikipages"] = self._search_wiki_pages(project, text)

        result["count"] = sum(map(lambda x: len(x), result.values()))
        return Response(result)
Ejemplo n.º 14
0
    def list(self, request, **kwargs):
        text = request.QUERY_PARAMS.get('text', "")
        project_id = request.QUERY_PARAMS.get('project', None)

        project = self._get_project(project_id)

        result = {}
        with futures.ThreadPoolExecutor(max_workers=4) as executor:
            futures_list = []
            if user_has_perm(request.user, "view_us", project):
                uss_future = executor.submit(self._search_user_stories, project, text)
                uss_future.result_key = "userstories"
                futures_list.append(uss_future)
            if user_has_perm(request.user, "view_tasks", project):
                tasks_future = executor.submit(self._search_tasks, project, text)
                tasks_future.result_key = "tasks"
                futures_list.append(tasks_future)
            if user_has_perm(request.user, "view_issues", project):
                issues_future = executor.submit(self._search_issues, project, text)
                issues_future.result_key = "issues"
                futures_list.append(issues_future)
            if user_has_perm(request.user, "view_wiki_pages", project):
                wiki_pages_future = executor.submit(self._search_wiki_pages, project, text)
                wiki_pages_future.result_key = "wikipages"
                futures_list.append(wiki_pages_future)

            for future in futures.as_completed(futures_list):
                data = []
                try:
                    data = future.result()
                except Exception as exc:
                    print('%s generated an exception: %s' % (future.result_key, exc))
                finally:
                    result[future.result_key] = data

        result["count"] = sum(map(lambda x: len(x), result.values()))
        return response.Ok(result)
Ejemplo n.º 15
0
 def check_permissions(self, request, view, obj=None):
     return user_has_perm(request.user, self.project_perm, obj)
Ejemplo n.º 16
0
def test_authenticated_user_has_perm_on_project():
    user1 = factories.UserFactory()
    project = factories.ProjectFactory()
    project.public_permissions = ["test"]
    assert service.user_has_perm(user1, "test", project) == True
    assert service.user_has_perm(user1, "fail", project) == False
Ejemplo n.º 17
0
 def check_permissions(self, request, view, obj=None):
     return user_has_perm(request.user, self.project_perm, obj)
Ejemplo n.º 18
0
def test_authenticated_user_has_perm_on_project():
    user1 = factories.UserFactory()
    project = factories.ProjectFactory()
    project.public_permissions = ["test"]
    assert service.user_has_perm(user1, "test", project) == True
    assert service.user_has_perm(user1, "fail", project) == False
Ejemplo n.º 19
0
def test_anon_user_has_perm():
    project = factories.ProjectFactory()
    project.anon_permissions = ["test"]
    assert service.user_has_perm(AnonymousUser(), "test", project) is True
    assert service.user_has_perm(AnonymousUser(), "fail", project) is False
Ejemplo n.º 20
0
def test_authenticated_user_has_perm_on_invalid_object():
    user1 = factories.UserFactory()
    assert service.user_has_perm(user1, "test", user1) is False
def test_authenticated_user_has_perm_on_invalid_object():
    user1 = factories.UserFactory()
    assert service.user_has_perm(user1, "test", user1) is False
def test_anon_user_has_perm():
    project = factories.ProjectFactory()
    project.anon_permissions = ["test"]
    assert service.user_has_perm(AnonymousUser(), "test", project) is True
    assert service.user_has_perm(AnonymousUser(), "fail", project) is False