zenodo_accessrequests/models.py
def create(cls, recid=None, receiver=None, sender_full_name=None,
               sender_email=None, justification=None, sender=None):
        """Create a new access request.

        :param recid: Record id (required).
        :param receiver: User object of receiver (required).
        :param sender_full_name: Full name of sender (required).
        :param sender_email: Email address of sender (required).
        :param justification: Justification message (required).
        :param sender: User object of sender (optional).
        """
        sender_user_id = None if sender is None else sender.id

        assert recid
        assert receiver
        assert sender_full_name
        assert sender_email
        assert justification

        # Determine status
        status = RequestStatus.EMAIL_VALIDATION
        if sender and sender.confirmed_at:
            status = RequestStatus.PENDING

        with db.session.begin_nested():
            # Create object
            obj = cls(
                status=status,
                recid=recid,
                receiver_user_id=receiver.id,
                sender_user_id=sender_user_id,
                sender_full_name=sender_full_name,
                sender_email=sender_email,
                justification=justification
            )

            db.session.add(obj)

        # Send signal
        if obj.status == RequestStatus.EMAIL_VALIDATION:
            request_created.send(obj)
        else:
            request_confirmed.send(obj)
        return obj
def create(cls, recid=None, receiver=None, sender_full_name=None,
               sender_email=None, justification=None, sender=None):
        """Create a new access request.

        :param recid: Record id (required).
        :param receiver: User object of receiver (required).
        :param sender_full_name: Full name of sender (required).
        :param sender_email: Email address of sender (required).
        :param justification: Justification message (required).
        :param sender: User object of sender (optional).
        """
        sender_user_id = None if sender is None else sender.id

        assert recid
        assert receiver
        assert sender_full_name
        assert sender_email
        assert justification

        # Determine status
        status = RequestStatus.EMAIL_VALIDATION
        if sender and sender.confirmed_at:
            status = RequestStatus.PENDING

        with db.session.begin_nested():
            # Create object
            obj = cls(
                status=status,
                recid=recid,
                receiver_user_id=receiver.id,
                sender_user_id=sender_user_id,
                sender_full_name=sender_full_name,
                sender_email=sender_email,
                justification=justification
            )

            db.session.add(obj)

        # Send signal
        if obj.status == RequestStatus.EMAIL_VALIDATION:
            request_created.send(obj)
        else:
            request_confirmed.send(obj)
        return obj
Create a new access request.

        :param recid: Record id (required).
        :param receiver: User object of receiver (required).
        :param sender_full_name: Full name of sender (required).
        :param sender_email: Email address of sender (required).
        :param justification: Justification message (required).
        :param sender: User object of sender (optional).