Пример #1
0
def process_document_ts_write(data, context):
    """
    Updates create and modified timestamps on documents.
    """
    with setup(data, context):
        from phenoback.functions import documents

        collection_path = get_collection_path(context)
        document_id = get_document_id(context)

        if is_create_event(data):
            log.info(
                "update created ts on document %s (%s)",
                context.resource,
                get_field(data, "source", expected=False),
            )
            documents.update_created_document(collection_path, document_id)
        elif is_update_event(data) and not is_field_updated(
                data, documents.MODIFIED_KEY):
            log.info(
                "update modified ts on document %s %s (%s)",
                context.resource,
                get_fields_updated(data),
                get_field(data, "source", expected=False),
            )
            documents.update_modified_document(collection_path, document_id)
        elif is_delete_event(data):
            log.info("document %s was deleted", context.resource)
        else:
            log.debug(
                "Nothing to do for document %s (%s)",
                context.resource,
                get_field(data, "source", old_value=True, expected=False),
            )
Пример #2
0
def process_user_write(data, context):
    """
    Processes user related documents if a user is created, modified or deleted.
    """
    with setup(data, context):
        from phenoback.functions import users

        user_id = get_document_id(context)

        if is_update_event(data) and is_field_updated(data, "nickname"):
            log.info("update nickname for %s", user_id)
            users.process_update_nickname(
                user_id,
                get_field(data, "nickname", old_value=True),
                get_field(data, "nickname"),
            )
        elif is_delete_event(data):
            log.info("delete user %s", user_id)
            users.process_delete_user(
                user_id, get_field(data, "nickname", old_value=True))
        elif is_create_event(data):
            log.info("create user %s", user_id)
            users.process_new_user(user_id, get_field(data, "nickname"))
        else:
            log.debug("Nothing to do for %s", user_id)
Пример #3
0
def process_observation_update_analytics(data, context):
    """
    Updates analytical values in Firestore if the observation date was modified on a observation document.
    """
    with setup(data, context):
        if is_field_updated(data, "date"):
            process_observation_create_analytics(data, context)
Пример #4
0
def process_invite_write(data, context):
    """
    Send email invites if invite is created or resend is set
    """
    with setup(data, context):
        from phenoback.functions.invite import invite

        # process if new invite or resend was changed but not deleted
        if is_create_event(data) or (is_field_updated(
                data, "resend") and get_field(data, "resend", expected=False)):
            invite.process(
                get_document_id(context),
                get_field(data, "email"),
                get_field(data, "locale"),
                get_field(data, "user"),
                get_field(data, "sent", expected=False),
            )
Пример #5
0
def process_observation_write_activity(data, context):
    """
    Creates an activity when an observation is created, modified or deleted in
    Firestore **and** the user or individual of that observation is being followed.
    """
    with setup(data, context):
        observation_id = get_document_id(context)
        if is_create_event(data):
            log.info("Add create activity for observation %s", observation_id)
            _process_observation_activity(data, context, "create")
        elif is_field_updated(data, "date"):
            log.info("Add modify activity for observation %s", observation_id)
            _process_observation_activity(data, context, "modify")
        elif is_delete_event(data):
            log.info("Add delete activity for observation %s", observation_id)
            _process_observation_activity(data, context, "delete")
        else:
            log.debug("No activity to add")
Пример #6
0
def process_user_write_update_invite(data, context):
    """
    Processes invite related documents if a user is created, modified or deleted.
    """
    with setup(data, context):
        from phenoback.functions.invite import register

        user_id = get_document_id(context)
        nickname = get_field(data, "nickname",
                             expected=False)  # don't warn on delete event

        if is_update_event(data) and is_field_updated(data, "nickname"):
            log.debug("update nickname on invites for user %s", user_id)
            register.change_nickname(user_id, nickname)
        elif is_delete_event(data):
            log.debug("delete invites for user %s", user_id)
            register.delete_user(user_id)
        elif is_create_event(data):
            log.debug("update invites for user %s", user_id)
            register.register_user(user_id, nickname)
        else:
            log.debug("Nothing to do for %s", user_id)