Beispiel #1
0
def _push_to_timelines(project,
                       user,
                       obj,
                       event_type,
                       created_datetime,
                       extra_data={}):
    if project is not None:
        # Actions related with a project

        ## Project timeline
        _push_to_timeline(project,
                          obj,
                          event_type,
                          created_datetime,
                          namespace=build_project_namespace(project),
                          extra_data=extra_data)

        if hasattr(obj, "get_related_people"):
            related_people = obj.get_related_people()

            _push_to_timeline(related_people,
                              obj,
                              event_type,
                              created_datetime,
                              namespace=build_user_namespace(user),
                              extra_data=extra_data)
    else:
        # Actions not related with a project
        ## - Me
        _push_to_timeline(user,
                          obj,
                          event_type,
                          created_datetime,
                          namespace=build_user_namespace(user),
                          extra_data=extra_data)
Beispiel #2
0
def _push_to_timelines(project, user, obj, event_type, extra_data={}):
    # Project timeline
    _push_to_timeline(project, obj, event_type,
        namespace=build_project_namespace(project),
        extra_data=extra_data)

    # User timeline
    _push_to_timeline(user, obj, event_type,
        namespace=build_user_namespace(user),
        extra_data=extra_data)

    # Calculating related people
    related_people = User.objects.none()

    # Assigned to
    if hasattr(obj, "assigned_to") and obj.assigned_to and user != obj.assigned_to:
        related_people |= User.objects.filter(id=obj.assigned_to.id)

    # Watchers
    watchers = hasattr(obj, "watchers") and obj.watchers.exclude(id=user.id) or User.objects.none()
    if watchers:
        related_people |= watchers

    # Team
    team_members_ids = project.memberships.filter(user__isnull=False).values_list("id", flat=True)
    team = User.objects.filter(id__in=team_members_ids)
    related_people |= team

    related_people = related_people.distinct()

    _push_to_timeline(related_people, obj, event_type,
        namespace=build_user_namespace(user),
        extra_data=extra_data)
Beispiel #3
0
def _push_to_timelines(project, user, obj, event_type, created_datetime, extra_data={}):
    if project is not None:
        # Actions related with a project

        ## Project timeline
        _push_to_timeline(
            project,
            obj,
            event_type,
            created_datetime,
            namespace=build_project_namespace(project),
            extra_data=extra_data,
        )

        project.refresh_totals()

        if hasattr(obj, "get_related_people"):
            related_people = obj.get_related_people()

            _push_to_timeline(
                related_people,
                obj,
                event_type,
                created_datetime,
                namespace=build_user_namespace(user),
                extra_data=extra_data,
            )
    else:
        # Actions not related with a project
        ## - Me
        _push_to_timeline(
            user, obj, event_type, created_datetime, namespace=build_user_namespace(user), extra_data=extra_data
        )
Beispiel #4
0
def store_timeline_entry(project, timeline):
    serialized = serializers.TimelineExportSerializer(data=timeline, context={"project": project})
    if serialized.is_valid():
        serialized.object.project = project
        serialized.object.namespace = build_project_namespace(project)
        serialized.object.object_id = project.id
        serialized.object._importing = True
        serialized.save()
        return serialized
    add_errors("timeline", serialized.errors)
    return serialized
Beispiel #5
0
def store_timeline_entry(project, timeline):
    serialized = serializers.TimelineExportSerializer(data=timeline, context={"project": project})
    if serialized.is_valid():
        serialized.object.project = project
        serialized.object.namespace = build_project_namespace(project)
        serialized.object.object_id = project.id
        serialized.object._importing = True
        serialized.save()
        return serialized
    add_errors("timeline", serialized.errors)
    return serialized
Beispiel #6
0
def _push_to_timelines(project,
                       user,
                       obj,
                       event_type,
                       created_datetime,
                       extra_data={}):
    if project is not None:
        # Actions related with a project

        ## Project timeline
        _push_to_timeline(project,
                          obj,
                          event_type,
                          created_datetime,
                          namespace=build_project_namespace(project),
                          extra_data=extra_data)

        ## User profile timelines
        ## - Me
        related_people = User.objects.filter(id=user.id)

        ## - Owner
        if hasattr(obj, "owner_id") and obj.owner_id:
            related_people |= User.objects.filter(id=obj.owner_id)

        ## - Assigned to
        if hasattr(obj, "assigned_to_id") and obj.assigned_to_id:
            related_people |= User.objects.filter(id=obj.assigned_to_id)

        ## - Watchers
        watchers = getattr(obj, "watchers", None)
        if watchers:
            related_people |= obj.watchers.all()

        ## - Exclude inactive and system users and remove duplicate
        related_people = related_people.exclude(is_active=False)
        related_people = related_people.exclude(is_system=True)
        related_people = related_people.distinct()

        _push_to_timeline(related_people,
                          obj,
                          event_type,
                          created_datetime,
                          namespace=build_user_namespace(user),
                          extra_data=extra_data)
    else:
        # Actions not related with a project
        ## - Me
        _push_to_timeline(user,
                          obj,
                          event_type,
                          created_datetime,
                          namespace=build_user_namespace(user),
                          extra_data=extra_data)
Beispiel #7
0
def _store_timeline_entry(project, timeline):
    validator = validators.TimelineExportValidator(data=timeline, context={"project": project})
    if validator.is_valid():
        validator.object.project = project
        validator.object.namespace = build_project_namespace(project)
        validator.object.object_id = project.id
        validator.object.content_type = ContentType.objects.get_for_model(project.__class__)
        validator.object._importing = True
        validator.save()
        return validator
    add_errors("timeline", validator.errors)
    return validator
Beispiel #8
0
def _store_timeline_entry(project, timeline):
    validator = validators.TimelineExportValidator(data=timeline, context={"project": project})
    if validator.is_valid():
        validator.object.project = project
        validator.object.namespace = build_project_namespace(project)
        validator.object.object_id = project.id
        validator.object.content_type = ContentType.objects.get_for_model(project.__class__)
        validator.object._importing = True
        validator.save()
        return validator
    add_errors("timeline", validator.errors)
    return validator
Beispiel #9
0
def _push_to_timelines(project,
                       user,
                       obj,
                       event_type,
                       created_datetime,
                       extra_data={}):
    if project is not None:
        # Project timeline
        _push_to_timeline(project,
                          obj,
                          event_type,
                          created_datetime,
                          namespace=build_project_namespace(project),
                          extra_data=extra_data)

    # User timeline
    _push_to_timeline(user,
                      obj,
                      event_type,
                      created_datetime,
                      namespace=build_user_namespace(user),
                      extra_data=extra_data)

    # Calculating related people
    related_people = User.objects.none()

    # Assigned to
    if hasattr(obj,
               "assigned_to") and obj.assigned_to and user != obj.assigned_to:
        related_people |= User.objects.filter(id=obj.assigned_to.id)

    # Watchers
    watchers = hasattr(obj, "watchers") and obj.watchers.exclude(
        id=user.id) or User.objects.none()
    if watchers:
        related_people |= watchers

    if project is not None:
        # Team
        team_members_ids = project.memberships.filter(
            user__isnull=False).values_list("id", flat=True)
        team = User.objects.filter(id__in=team_members_ids)
        related_people |= team
        related_people = related_people.distinct()

        _push_to_timeline(related_people,
                          obj,
                          event_type,
                          created_datetime,
                          namespace=build_user_namespace(user),
                          extra_data=extra_data)
Beispiel #10
0
def _push_to_timelines(project, user, obj, event_type, created_datetime, extra_data={}):
    if project is not None:
        # Actions related with a project

        ## Project timeline
        _push_to_timeline(
            project,
            obj,
            event_type,
            created_datetime,
            namespace=build_project_namespace(project),
            extra_data=extra_data,
        )

        ## User profile timelines
        ## - Me
        related_people = User.objects.filter(id=user.id)

        ## - Owner
        if hasattr(obj, "owner_id") and obj.owner_id:
            related_people |= User.objects.filter(id=obj.owner_id)

        ## - Assigned to
        if hasattr(obj, "assigned_to_id") and obj.assigned_to_id:
            related_people |= User.objects.filter(id=obj.assigned_to_id)

        ## - Watchers
        watchers = getattr(obj, "watchers", None)
        if watchers:
            related_people |= obj.watchers.all()

        ## - Exclude inactive and system users and remove duplicate
        related_people = related_people.exclude(is_active=False)
        related_people = related_people.exclude(is_system=True)
        related_people = related_people.distinct()

        _push_to_timeline(
            related_people,
            obj,
            event_type,
            created_datetime,
            namespace=build_user_namespace(user),
            extra_data=extra_data,
        )
    else:
        # Actions not related with a project
        ## - Me
        _push_to_timeline(
            user, obj, event_type, created_datetime, namespace=build_user_namespace(user), extra_data=extra_data
        )
Beispiel #11
0
    def refresh_totals(self, save=True):
        now = timezone.now()
        self.totals_updated_datetime = now

        Like = apps.get_model("likes", "Like")
        content_type = apps.get_model(
            "contenttypes", "ContentType").objects.get_for_model(Project)
        qs = Like.objects.filter(content_type=content_type, object_id=self.id)

        self.total_fans = qs.count()

        qs_week = qs.filter(created_date__gte=now - relativedelta(weeks=1))
        self.total_fans_last_week = qs_week.count()

        qs_month = qs.filter(created_date__gte=now - relativedelta(months=1))
        self.total_fans_last_month = qs_month.count()

        qs_year = qs.filter(created_date__gte=now - relativedelta(years=1))
        self.total_fans_last_year = qs_year.count()

        tl_model = apps.get_model("timeline", "Timeline")
        namespace = build_project_namespace(self)

        qs = tl_model.objects.filter(namespace=namespace)
        self.total_activity = qs.count()

        qs_week = qs.filter(created__gte=now - relativedelta(weeks=1))
        self.total_activity_last_week = qs_week.count()

        qs_month = qs.filter(created__gte=now - relativedelta(months=1))
        self.total_activity_last_month = qs_month.count()

        qs_year = qs.filter(created__gte=now - relativedelta(years=1))
        self.total_activity_last_year = qs_year.count()

        if save:
            self.save(update_fields=[
                'totals_updated_datetime',
                'total_fans',
                'total_fans_last_week',
                'total_fans_last_month',
                'total_fans_last_year',
                'total_activity',
                'total_activity_last_week',
                'total_activity_last_month',
                'total_activity_last_year',
            ])
Beispiel #12
0
    def refresh_totals(self, save=True):
        now = timezone.now()
        self.totals_updated_datetime = now

        Like = apps.get_model("likes", "Like")
        content_type = apps.get_model("contenttypes", "ContentType").objects.get_for_model(Project)
        qs = Like.objects.filter(content_type=content_type, object_id=self.id)

        self.total_fans = qs.count()

        qs_week = qs.filter(created_date__gte=now-relativedelta(weeks=1))
        self.total_fans_last_week = qs_week.count()

        qs_month = qs.filter(created_date__gte=now-relativedelta(months=1))
        self.total_fans_last_month = qs_month.count()

        qs_year = qs.filter(created_date__gte=now-relativedelta(years=1))
        self.total_fans_last_year = qs_year.count()

        tl_model = apps.get_model("timeline", "Timeline")
        namespace = build_project_namespace(self)

        qs = tl_model.objects.filter(namespace=namespace)
        self.total_activity = qs.count()

        qs_week = qs.filter(created__gte=now-relativedelta(weeks=1))
        self.total_activity_last_week = qs_week.count()

        qs_month = qs.filter(created__gte=now-relativedelta(months=1))
        self.total_activity_last_month = qs_month.count()

        qs_year = qs.filter(created__gte=now-relativedelta(years=1))
        self.total_activity_last_year = qs_year.count()

        if save:
            self.save(update_fields=[
                'totals_updated_datetime',
                'total_fans',
                'total_fans_last_week',
                'total_fans_last_month',
                'total_fans_last_year',
                'total_activity',
                'total_activity_last_week',
                'total_activity_last_month',
                'total_activity_last_year',
            ])
Beispiel #13
0
def test_epic_related_uss():
    Timeline.objects.all().delete()

    # Users
    public_project_owner = factories.UserFactory.create(
        username="******")
    not_qualified_private_project_member = factories.UserFactory.create(
        username="******")
    private_project_owner = factories.UserFactory.create(
        username="******")

    # A public project, containing a public epic which contains a private us from a private project
    public_project = factories.ProjectFactory.create(
        is_private=False,
        owner=public_project_owner,
        anon_permissions=[],
        public_permissions=["view_us"])
    factories.MembershipFactory.create(project=public_project,
                                       user=public_project.owner,
                                       is_admin=True)
    public_epic = factories.EpicFactory.create(project=public_project,
                                               owner=public_project_owner)
    public_us = factories.UserStoryFactory.create(project=public_project,
                                                  owner=public_project_owner)
    related_public_us = factories.RelatedUserStory.create(epic=public_epic,
                                                          user_story=public_us)

    # A private project, containing the private user story related to the public epic from the public project
    private_project = factories.ProjectFactory.create(
        is_private=True,
        owner=private_project_owner,
        anon_permissions=[],
        public_permissions=[])
    not_qualified_role = factories.RoleFactory(project=private_project,
                                               permissions=[])
    qualified_role = factories.RoleFactory(project=private_project,
                                           permissions=["view_us"])
    factories.MembershipFactory.create(
        project=private_project,
        user=not_qualified_private_project_member,
        role=not_qualified_role)
    factories.MembershipFactory.create(project=private_project,
                                       user=private_project_owner,
                                       role=qualified_role)
    private_us = factories.UserStoryFactory.create(project=private_project,
                                                   owner=private_project_owner)
    related_private_us = factories.RelatedUserStory.create(
        epic=public_epic, user_story=private_us)

    service.register_timeline_implementation("epics.relateduserstory",
                                             "test",
                                             lambda x, extra_data=None: id(x))
    project_namespace = build_project_namespace(public_project)
    # Timeline entries regarding the first epic-related public US, for both a user and a project namespace
    service._add_to_object_timeline(public_project, related_public_us,
                                    "create", datetime.now(),
                                    project_namespace)
    service._add_to_object_timeline(public_project_owner, related_public_us,
                                    "create", datetime.now(),
                                    build_user_namespace(public_project_owner))
    # Timeline entries regarding the first epic-related private US, for both a user and a project namespace
    service._add_to_object_timeline(public_project, related_private_us,
                                    "create", datetime.now(),
                                    project_namespace)
    service._add_to_object_timeline(
        private_project_owner, related_private_us, "create", datetime.now(),
        build_user_namespace(private_project_owner))
    """
    # A list of users for the test iterations
    #
    # [index0] An anonymous user, who doesn't even have rights to see neither public nor private related USs.
    # [index1] A public project's owner, who related a public US to an epic from her own public project. She just 
    #   has privileges to see her public related USs, and is a simple registered user regarding the private project.
    # [index2] An unprivileged private member, whose role doesn't have access to the private project's USs, 
    #   but is able to view the related-USs from the public project's.
    # [index3] A private project's owner, who linked her private US to an epic from the public project.
                She has privileges to see any related USs.
    """
    users = [
        AnonymousUser(),  # [index 0]
        public_project_owner,  # [index 1]
        not_qualified_private_project_member,  # [index 2]
        private_project_owner
    ]  # [index 3]

    timeline_counters = _helper_get_timelines_for_accessing_users(
        public_project, users)
    assert timeline_counters['project_timelines'] == [0, 1, 1, 2]
    assert timeline_counters['user_timelines'] == {
        # An anonymous user verifies the number of 'epics.relateduserstory' entries in the other users timelines
        #  She can't any epic related US on neither of [index1], [index2], or [index3] timelines
        0: [0, 0, 0],
        # An [index1] user verifies the number of 'epics.relateduserstory' entries in the other users timelines
        #  She can just see the public epic related USs on her own [index1] timeline
        1: [1, 0, 0],
        # An [index2] user verifies the number of 'epics.relateduserstory' entries in the other users timelines
        #  She can just see the public epic related USs on her own [index1] timeline
        2: [1, 0, 0],
        # An [index3] user verifies the number of 'epics.relateduserstory' entries in the other users timelines
        #  She can see both the public epic related USs in [index1] timeline, and in her own [index3] timeline
        3: [1, 0, 1]
    }