예제 #1
0
def get_event_object_context(
        event_content_object: Any,
        event_type: str) -> Optional[EventItemContextSpec]:
    # Deleted objects don't have a content object any more
    if not event_content_object:
        return EventItemContextSpec(name=None, url=None, object_id=None)

    event_subject = get_event_subject(event_type)

    object_id = None
    object_url = None
    object_name = None
    if hasattr(event_content_object, "id"):
        object_id = event_content_object.id

    if hasattr(event_content_object, "unique_name"):
        object_name = event_content_object.unique_name
        if event_subject == event_subjects.PROJECT:
            object_url = get_project_url(object_name)
        elif event_subject == event_subjects.RUN:
            object_url = get_fqn_run_url(object_name)

    elif hasattr(event_content_object, "name"):
        object_name = event_content_object.name
    elif hasattr(event_content_object, "username"):
        object_name = event_content_object.username
        object_url = get_owner_url(event_content_object.username)

    # Set proper url
    object_url = absolute_uri("ui{}".format(object_url))
    return EventItemContextSpec(name=object_name,
                                url=object_url,
                                object_id=object_id)
예제 #2
0
def get_event_actor_context(
        event: "Event",  # noqa: F821
) -> Optional[EventItemContextSpec]:
    if not event.actor:
        return None

    username = event.data.get(event.actor_name)
    if username is None:
        return None
    if username == user_system.USER_SYSTEM_NAME:
        return EventItemContextSpec(name=username, url="/", object_id=None)
    return EventItemContextSpec(name=username,
                                url=get_owner_url(username),
                                object_id=None)
예제 #3
0
 def test_get_owner_url(self):
     self.assertEqual(get_owner_url("foo"), "/foo")