Пример #1
0
 def clean_expired_itips(self, store):
     """
     This function, checks all the InternalTips and their expiration date.
     if expired InternalTips are found, it removes that along with
     all the related DB entries comment and tip related.
     """
     db_delete_itips(store, store.find(models.InternalTip, models.InternalTip.expiration_date < datetime_now()))
Пример #2
0
def perform_tips_operation(session, tid, receiver_id, operation, rtips_ids):
    """
    Transaction for performing operation on submissions (postpone/delete)

    :param session: An ORM session
    :param tid: A tenant ID
    :param receiver_id: A recipient ID
    :param operation: An operation command (postpone/delete)
    :param rtips_ids: The set of submissions on which performing the specified operation
    """
    receiver = models.db_get(session, models.User,
                             models.User.id == receiver_id)

    can_postpone_expiration = State.tenant_cache[
        tid].can_postpone_expiration or receiver.can_postpone_expiration
    can_delete_submission = State.tenant_cache[
        tid].can_delete_submission or receiver.can_delete_submission

    itips = session.query(models.InternalTip) \
                   .filter(models.ReceiverTip.receiver_id == receiver_id,
                           models.ReceiverTip.id.in_(rtips_ids),
                           models.InternalTip.id == models.ReceiverTip.internaltip_id,
                           models.InternalTip.tid == tid)

    if operation == 'postpone' and can_postpone_expiration:
        for itip in itips:
            db_postpone_expiration(session, itip)

    elif operation == 'delete' and can_delete_submission:
        db_delete_itips(session, [itip.id for itip in itips])

    else:
        raise errors.ForbiddenOperation
Пример #3
0
 def clean_expired_itips(self, store):
     """
     This function, checks all the InternalTips and their expiration date.
     if expired InternalTips are found, it removes that along with
     all the related DB entries comment and tip related.
     """
     db_delete_itips(store, store.find(models.InternalTip, models.InternalTip.expiration_date < datetime_now()))
Пример #4
0
 def clean_expired_itips(self, session):
     """
     This function, checks all the InternalTips and their expiration date.
     if expired InternalTips are found, it removes that along with
     all the related DB entries comment and tip related.
     """
     itips_ids = [id[0] for id in session.query(models.InternalTip.id).filter(models.InternalTip.expiration_date < datetime_now())]
     if itips_ids:
         db_delete_itips(session, itips_ids)
Пример #5
0
 def db_clean_expired_itips(self, session):
     """
     This function, checks all the InternalTips and their expiration date.
     if expired InternalTips are found, it removes that along with
     all the related DB entries comment and tip related.
     """
     itips_ids = [id[0] for id in session.query(models.InternalTip.id).filter(models.InternalTip.expiration_date < datetime_now())]
     if itips_ids:
         db_delete_itips(session, itips_ids)
Пример #6
0
def reset_submissions(session, tid):
    """
    Transaction to reset the submissions of the specified tenant

    :param session: An ORM session
    :param tid: A tenant ID
    """
    session.query(Config).filter(Config.tid == tid, Config.var_name == 'counter_submissions').update({'value': 0})

    itip_ids = [x[0] for x in session.query(InternalTip.id).filter(InternalTip.tid == tid)]

    db_delete_itips(session, itip_ids)