def test_get_liked_list_permissions(): fan_user = f.UserFactory() viewer_unpriviliged_user = f.UserFactory() viewer_priviliged_user = f.UserFactory() project = f.ProjectFactory(is_private=True, name="Testing project") role = f.RoleFactory(project=project, permissions=["view_project", "view_us", "view_tasks", "view_issues"]) membership = f.MembershipFactory(project=project, role=role, user=viewer_priviliged_user) content_type = ContentType.objects.get_for_model(project) f.LikeFactory(content_type=content_type, object_id=project.id, user=fan_user) f.LikesFactory(content_type=content_type, object_id=project.id, count=1) #If the project is private a viewer user without any permission shouldn' see # any vote assert len(get_liked_list(fan_user, viewer_unpriviliged_user)) == 0 #If the project is private but the viewer user has permissions the votes should # be accesible assert len(get_liked_list(fan_user, viewer_priviliged_user)) == 1 #If the project is private but has the required anon permissions the votes should # be accesible by any user too project.anon_permissions = ["view_project", "view_us", "view_tasks", "view_issues"] project.save() assert len(get_liked_list(fan_user, viewer_unpriviliged_user)) == 1
def test_get_liked_list_permissions(): fan_user = f.UserFactory() viewer_unpriviliged_user = f.UserFactory() viewer_priviliged_user = f.UserFactory() project = f.ProjectFactory(is_private=True, name="Testing project") role = f.RoleFactory( project=project, permissions=["view_project", "view_us", "view_tasks", "view_issues"]) membership = f.MembershipFactory(project=project, role=role, user=viewer_priviliged_user) content_type = ContentType.objects.get_for_model(project) f.LikeFactory(content_type=content_type, object_id=project.id, user=fan_user) #If the project is private a viewer user without any permission shouldn' see # any vote assert len(get_liked_list(fan_user, viewer_unpriviliged_user)) == 0 #If the project is private but the viewer user has permissions the votes should # be accesible assert len(get_liked_list(fan_user, viewer_priviliged_user)) == 1 #If the project is private but has the required anon permissions the votes should # be accesible by any user too project.anon_permissions = [ "view_project", "view_us", "view_tasks", "view_issues" ] project.save() assert len(get_liked_list(fan_user, viewer_unpriviliged_user)) == 1
def test_get_liked_list(): fan_user = f.UserFactory() viewer_user = f.UserFactory() project = f.ProjectFactory(is_private=False, name="Testing project") role = f.RoleFactory(project=project, permissions=["view_project", "view_us", "view_tasks", "view_issues"]) membership = f.MembershipFactory(project=project, role=role, user=fan_user) content_type = ContentType.objects.get_for_model(project) f.LikeFactory(content_type=content_type, object_id=project.id, user=fan_user) assert len(get_liked_list(fan_user, viewer_user)) == 1 assert len(get_liked_list(fan_user, viewer_user, type="project")) == 1 assert len(get_liked_list(fan_user, viewer_user, type="unknown")) == 0 assert len(get_liked_list(fan_user, viewer_user, q="project")) == 1 assert len(get_liked_list(fan_user, viewer_user, q="unexisting text")) == 0
def test_get_liked_list_valid_info(): fan_user = f.UserFactory() viewer_user = f.UserFactory() project = f.ProjectFactory(is_private=False, name="Testing project", tags=['test', 'tag']) content_type = ContentType.objects.get_for_model(project) like = f.LikeFactory(content_type=content_type, object_id=project.id, user=fan_user) project.refresh_totals() raw_project_like_info = get_liked_list(fan_user, viewer_user)[0] project_like_info = LikedObjectSerializer(raw_project_like_info).data assert project_like_info["type"] == "project" assert project_like_info["id"] == project.id assert project_like_info["ref"] == None assert project_like_info["slug"] == project.slug assert project_like_info["name"] == project.name assert project_like_info["subject"] == None assert project_like_info["description"] == project.description assert project_like_info["assigned_to"] == None assert project_like_info["status"] == None assert project_like_info["status_color"] == None tags_colors = { tc["name"]: tc["color"] for tc in project_like_info["tags_colors"] } assert "test" in tags_colors assert "tag" in tags_colors assert project_like_info["is_private"] == project.is_private assert project_like_info["logo_small_url"] == get_thumbnail_url( project.logo, settings.THN_LOGO_SMALL) assert project_like_info["is_fan"] == False assert project_like_info["is_watcher"] == False assert project_like_info["total_watchers"] == 0 assert project_like_info["total_fans"] == 1 assert project_like_info["project"] == None assert project_like_info["project_name"] == None assert project_like_info["project_slug"] == None assert project_like_info["project_is_private"] == None assert project_like_info["project_blocked_code"] == None assert project_like_info["assigned_to_username"] == None assert project_like_info["assigned_to_full_name"] == None assert project_like_info["assigned_to_photo"] == None
def test_get_liked_list_valid_info(): fan_user = f.UserFactory() viewer_user = f.UserFactory() project = f.ProjectFactory(is_private=False, name="Testing project", tags=['test', 'tag']) content_type = ContentType.objects.get_for_model(project) like = f.LikeFactory(content_type=content_type, object_id=project.id, user=fan_user) project.refresh_totals() raw_project_like_info = get_liked_list(fan_user, viewer_user)[0] project_like_info = LikedObjectSerializer(raw_project_like_info).data assert project_like_info["type"] == "project" assert project_like_info["id"] == project.id assert project_like_info["ref"] == None assert project_like_info["slug"] == project.slug assert project_like_info["name"] == project.name assert project_like_info["subject"] == None assert project_like_info["description"] == project.description assert project_like_info["assigned_to"] == None assert project_like_info["status"] == None assert project_like_info["status_color"] == None tags_colors = {tc["name"]:tc["color"] for tc in project_like_info["tags_colors"]} assert "test" in tags_colors assert "tag" in tags_colors assert project_like_info["is_private"] == project.is_private assert project_like_info["logo_small_url"] == get_thumbnail_url(project.logo, settings.THN_LOGO_SMALL) assert project_like_info["is_fan"] == False assert project_like_info["is_watcher"] == False assert project_like_info["total_watchers"] == 0 assert project_like_info["total_fans"] == 1 assert project_like_info["project"] == None assert project_like_info["project_name"] == None assert project_like_info["project_slug"] == None assert project_like_info["project_is_private"] == None assert project_like_info["project_blocked_code"] == None assert project_like_info["assigned_to_username"] == None assert project_like_info["assigned_to_full_name"] == None assert project_like_info["assigned_to_photo"] == None
def liked(self, request, *args, **kwargs): for_user = get_object_or_404(models.User, **kwargs) from_user = request.user self.check_permissions(request, 'liked', for_user) filters = { "q": request.GET.get("q", None), } self.object_list = services.get_liked_list(for_user, from_user, **filters) page = self.paginate_queryset(self.object_list) elements = page.object_list if page is not None else self.object_list extra_args = { "user_watching": services.get_watched_content_for_user(request.user), "user_likes": services.get_liked_content_for_user(request.user), } response_data = [serializers.LikedObjectSerializer(elem, **extra_args).data for elem in elements] return response.Ok(response_data)