Esempio n. 1
0
    def test_rfid_get_no_authorization(self):
        event_id = self.data["event1"].id

        rfid_data = {"atqa": "0004", "sak": "08", "uid": "98ab54ef"}

        rfidcard = RfidCard(
            atqa=rfid_data["atqa"], sak=rfid_data["sak"], uid=rfid_data["uid"], is_active=True, user=self.data["user2"]
        )
        rfidcard.save()

        self.send_and_compare_request_error(
            "juliana.rfid.get",
            [event_id, rfid_data],
            status_code=500,
            error_code=-32602,
            error_name="InvalidParamsError",
            error_message="InvalidParamsError: No authorization found for user",
        )
Esempio n. 2
0
def rfid_add(request, radius_username, identifier):
    """
    Add a new RFID card to the specified user.

    Required user level: Manager

    Returns the RFID card on success.

    radius_username    -- RADIUS username to search for.
    identifier         -- RFID card hardware identiefier.

    Example return value:
    {
        "identifier": "02,98:76:54:32",
        "registered_at": "2014-09-21T14:16:06+00:00"
        "user": "******"
    }

    Raises error -32602 (Invalid params) if the radius_username does not exist.
    Raises error -32602 (Invalid params) if the RFID card already exists for this person.
    Raises error -32602 (Invalid params) if the RFID card is already registered by someone else.
    """

    try:
        user = User.objects.select_for_update().get(authenticationdata__backend=RADIUS_BACKEND_NAME,
                                                    authenticationdata__username=radius_username)
    except User.DoesNotExist:
        raise InvalidParametersError('User with provided radius_username does not exits')

    try:
        rfidcard = RfidCard.objects.select_for_update().get(user=user, identifier=identifier)
    except RfidCard.DoesNotExist:
        if RfidCard.objects.select_for_update().filter(identifier=identifier).exists():
            raise InvalidParametersError('RFID card with provided identifier already registered by someone else')

        rfidcard = RfidCard(user=user, identifier=identifier, is_active=True)
        rfidcard.save()

    if request.organization not in rfidcard.managed_by.all().select_for_update():
        rfidcard.managed_by.add(request.organization)
        rfidcard.save()
        return format_rfidcard(rfidcard)
    else:
        raise InvalidParametersError('RFID card with provided identifier already exists for this person')
Esempio n. 3
0
    def test_rfid_get_no_authorization(self):
        event_id = self.data['event1'].id

        rfid_data = {
            'atqa': '00:04',
            'sak': '08',
            'uid': '98:ab:54:ef',
        }

        rfidcard = RfidCard(identifier='02,98:ab:54:ef', is_active=True, user=self.data['user2'])
        rfidcard.save()

        self.send_and_compare_request_error(
            'juliana.rfid.get', [event_id, rfid_data],
            status_code=500,
            error_code=-32602,
            error_name='InvalidParamsError',
            error_message='InvalidParamsError: No authorization found for user',
        )
Esempio n. 4
0
    def test_rfid_get_no_authorization(self):
        event_id = self.data['event1'].id

        rfid_data = {
            'atqa': '00:04',
            'sak': '08',
            'uid': '98:ab:54:ef',
        }

        rfidcard = RfidCard(identifier='02,98:ab:54:ef', is_active=True, user=self.data['user2'])
        rfidcard.save()

        self.send_and_compare_request_error(
            'juliana.rfid.get', [event_id, rfid_data],
            status_code=500,
            error_code=-32602,
            error_name='InvalidParamsError',
            error_message='InvalidParamsError: No authorization found for user',
        )
Esempio n. 5
0
def rfid_add(request, radius_username, atqa, sak, uid):
    """
    Add a new RFID card to the specified user.

    Required user level: Manager

    Returns the RFID card on success.

    radius_username    -- RADIUS username to search for.
    atqa               -- ATQA of the card (hexadecimal lowercase string, no colons, may be empty as a wildcard)
    sak                -- SAK of the card (hexadecimal lowercase string, no colons, may be empty as a wildcard)
    uid                -- UID of the card (hexadecimal lowercase string, no colons)

    Example return value:
    {
        "atqa": "0004",
        "sak": "08",
        "uid": "98765432",
        "registered_at": "2014-09-21T14:16:06+00:00"
        "user": "******"
    }

    Raises error -32602 (Invalid params) if the radius_username does not exist.
    Raises error -32602 (Invalid params) if the RFID card already exists for this person.
    Raises error -32602 (Invalid params) if the RFID card is already registered by someone else.
    """

    try:
        user = User.objects.select_for_update().get(authenticationdata__backend=RADIUS_BACKEND_NAME,
                                                    authenticationdata__username=radius_username)
    except User.DoesNotExist:
        raise InvalidParametersError('User with provided radius_username does not exits')

    try:
        rfidcard = RfidCard.objects.select_for_update().get(user=user, atqa=atqa, sak=sak, uid=uid)
    except RfidCard.DoesNotExist:
        if RfidCard.objects.select_for_update().filter(atqa=atqa, sak=sak, uid=uid).exists():
            raise InvalidParametersError('RFID card already registered by someone else')

        rfidcard = RfidCard(user=user, atqa=atqa, sak=sak, uid=uid, is_active=True)
        rfidcard.save()

    if request.organization not in rfidcard.managed_by.all().select_for_update():
        rfidcard.managed_by.add(request.organization)
        rfidcard.is_active = True
        rfidcard.save()
        return format_rfidcard(rfidcard)
    else:
        raise InvalidParametersError('RFID card already exists for this person')