コード例 #1
0
def recreate_debug_environment():
    debug.print_w("Dropping all")
    debug.print_i(db_Findlock().drop_all())

    debug.print_i("Creating dummmy user!")
    debug.print_i(db_User().create_user(debug_data.get_dummy_user()))
    debug.print_i("Creating dummy user with permissions")
    debug.print_i(db_User().create_user(
        debug_data.get_dummy_user_with_permissions()))

    debug.print_i("Adding dummy user w/ permissions to dummy findlock")

    dummy_findlock = debug_data.get_dummy_findlock()
    debug.print_i(
        dummy_findlock.FindlockPermission.addAllowedUuid(
            debug_data.get_dummy_user_with_permissions().user_uuid))

    debug.print_i("Creating dummmy findlock!")
    debug.print_i(db_Findlock().create_findlock(dummy_findlock))

    debug.print_i("Pairing dummy findlock with dummy user!")
    debug.print_i(
        UserLogic.pair_with_findlock(dummy_findlock.device_uuid,
                                     dummy_findlock.master_pincode,
                                     debug_data.get_dummy_user().user_uuid))

    debug.print_i("Sending dummy GPS location to dummy findlock")
    debug.print_i(
        RestLogic.update_findlock(dummy_findlock.device_uuid,
                                  m_FindlockUpdateTypes.gps_location,
                                  debug_data.get_dummy_location().__dict__))
コード例 #2
0
    def update_findlock(device_uuid, update_type,
                        update_data) -> m_LogicReturn:
        if v.value_empty(device_uuid) \
            or v.value_empty(update_data) \
                or v.value_empty(update_type):
            return m_LogicReturn.f_error_msg("post data is missing!")

        db_resp = db_Findlock().get_findlock(m_FindlockEntries.device_uuid,
                                             device_uuid)

        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)

        Findlock = db_resp.addon_data
        Findlock: m_Findlock

        valid_update_types = t.get_types(m_FindlockUpdateTypes())
        if update_type not in valid_update_types:
            return m_LogicReturn.f_error_msg("Unsupported update type!")

        if update_type == m_FindlockUpdateTypes.gps_location:
            try:
                update_data = json.loads(update_data)
                update_data = m_GpsLocation.fromDict(update_data)
            except:
                return m_LogicReturn.f_error_msg("Update data is malformed!")

        if update_type == m_FindlockUpdateTypes.gps_location:
            Findlock.GpsLocationHistory.add_location(update_data)
        else:
            return m_LogicReturn.f_error_msg(
                "this update type is not implemented...")

        db_resp = db_Findlock().update_findlock(Findlock)
        return m_LogicReturn.f_success_msg("Findlock updated!")
コード例 #3
0
    def update_findlock_event(device_uuid, executed: bool) -> m_LogicReturn:

        db_resp = db_Findlock().get_findlock(m_FindlockEntries.device_uuid,
                                             device_uuid)

        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)

        Findlock = db_resp.addon_data
        Findlock: m_Findlock

        Findlock.Event.executed = executed
        db_Findlock().update_findlock(Findlock)
        return m_LogicReturn.f_success_msg("updated!")
コード例 #4
0
    def remove_findlock(findlock_uuid) -> m_LogicReturn:
        if not v.verify_uuid(findlock_uuid).success:
            return m_LogicReturn.f_error_msg("UUID is not valid!")
        db_resp = db_Findlock().get_findlock(m_FindlockEntries.device_uuid,
                                             findlock_uuid)
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)

        _Findlock = db_resp.addon_data
        _Findlock: m_Findlock

        db_resp = db_Findlock().delete_findlock(_Findlock)
        if db_resp.success:
            return m_LogicReturn.f_success_msg(db_resp.content)
        return m_LogicReturn.f_error_msg(db_resp.content)
コード例 #5
0
    def add_gps_location_to_findlock(fl_uuid, lat, lng) -> m_LogicReturn:
        db_resp = db_Findlock().get_findlock(m_FindlockEntries.device_uuid,
                                             fl_uuid)
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)

        _Findlock = db_resp.addon_data
        _Findlock: m_Findlock

        _new_gps_location = m_GpsLocation(lat, lng, str(Tools.get_unix_time()))

        _Findlock.GpsLocationHistory.add_location(_new_gps_location)

        db_Findlock().update_findlock(_Findlock)
        return m_LogicReturn.f_success_msg("ok!")
コード例 #6
0
    def get_list_of_findlocks() -> m_LogicReturn:
        db_resp = db_Findlock().get_all_findlocks()
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)

        _Findlocks = db_resp.addon_data
        _Findlocks: [m_Findlock]
        return m_LogicReturn.f_success(f"List of {len(_Findlocks)} findlocks",
                                       _Findlocks)
コード例 #7
0
    def set_findlock_lock_state(  #using
            device_uuid,
            new_lock_state,  #mEventType
            auth_value,  #
            auth_type):  #userentries

        if not v.verify_uuid(device_uuid).success:
            return m_LogicReturn.f_error_msg(
                f"{device_uuid} is not a valid uuid!")

        event_types = t.get_types(m_EventTypes())
        if new_lock_state not in event_types:
            return m_LogicReturn.f_error_msg(
                f"{new_lock_state} is not a valid event type!")

        auth_types = t.get_types(m_UserEntries())
        if auth_type not in auth_types:
            return m_LogicReturn.f_error_msg(
                f"{auth_type} is not a valid userentry!")

        db_resp = db_Findlock().get_findlock(m_FindlockEntries.device_uuid,
                                             device_uuid)
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)

        _findlock = db_resp.addon_data
        _findlock: m_Findlock

        db_resp = db_User().get_all_users()
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)

        _users = db_resp.addon_data
        user_have_rights = False

        if auth_type == m_UserEntries.finger_id:
            for user in _users:
                if user.finger_id == auth_value:
                    if user.user_uuid == _findlock.FindlockPermission.master_uuid:
                        user_have_rights = True
                    if user.user_uuid in _findlock.FindlockPermission.allowed_uuids:
                        user_have_rights = True
        elif auth_type == m_UserEntries.nfc_id:
            for user in _users:
                if user.nfc_id == auth_value:
                    if user.user_uuid == _findlock.FindlockPermission.master_uuid:
                        user_have_rights = True
                    if user.user_uuid in _findlock.FindlockPermission.allowed_uuids:
                        user_have_rights = True
        else:
            return m_LogicReturn.f_error_msg("Unsupported auth type!")

        if not user_have_rights:
            return m_LogicReturn.f_error_msg("Permission error!")

        return RestLogic.set_findlock_event(device_uuid, new_lock_state)
コード例 #8
0
    def findlock_update(findlock_uuid, data_keys,
                        data_values) -> m_LogicReturn:
        if not v.verify_uuid(findlock_uuid).success:
            return m_LogicReturn.f_error_msg(
                f"{findlock_uuid} is not a valid uuid")
        if len(data_keys) != len(data_values):
            return m_LogicReturn.f_error_msg("Mismatch in data!")

        for i in range(0, len(data_values)):
            data_val = data_values[i]
            if data_val == "None":
                data_values[i] = None
            elif data_val == "True":
                data_values[i] = True
            elif data_val == "False":
                data_values[i] = False

        valid_data_keys = Tools.get_types(m_FindlockEntries())

        db_resp = db_Findlock().get_findlock(m_FindlockEntries.device_uuid,
                                             findlock_uuid)
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)

        _findlock = db_resp.addon_data
        _findlock: m_Findlock

        _findlock_dict = _findlock.toDict()

        for i in range(0, len(data_keys)):
            key = data_keys[i]
            if key not in valid_data_keys:
                return m_LogicReturn.f_error_msg(f"{key} is not a valid key!")
            val = data_values[i]

            _findlock_dict[key] = val

        _findlock = m_Findlock.fromDict(_findlock_dict)
        db_resp = db_Findlock().update_findlock(_findlock)
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)
        return m_LogicReturn.f_success_msg(db_resp.content)
コード例 #9
0
    def wipe_collection(col_name) -> m_LogicReturn:
        valid_col_names = ["users", "findlocks"]

        if col_name not in valid_col_names:
            return m_LogicReturn.f_error_msg(
                f"{col_name} is not a valid col name!")

        if col_name == "users":
            db_User().drop_col()
            db_User().create_user(debug_data.get_dummy_user())
            db_User().create_user(debug_data.get_dummy_user_with_permissions())
        elif col_name == "findlocks":
            db_Findlock().drop_col()
            _findlock = debug_data.get_dummy_findlock()
            _findlock.FindlockPermission.master_uuid = debug_data.get_dummy_user(
            ).user_uuid
            _findlock.FindlockPermission.addAllowedUuid(
                debug_data.get_dummy_user_with_permissions().user_uuid)
            db_Findlock().create_findlock(_findlock)

        return m_LogicReturn.f_success_msg("Executed.")
コード例 #10
0
    def set_findlock_event(device_uuid, event_type) -> m_LogicReturn:  #using
        valid_event_types = t.get_types(m_EventTypes())
        print(valid_event_types)
        if event_type not in valid_event_types:
            return m_LogicReturn.f_error_msg(
                f"{event_type} is not a valid event type!")

        if not v.verify_uuid(device_uuid).success:
            return m_LogicReturn.f_error_msg(
                f"{device_uuid} is not a valid uuid")

        db_resp = db_Findlock().get_findlock(m_FindlockEntries.device_uuid,
                                             device_uuid)
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)
        _findlock = db_resp.addon_data
        _findlock: m_Findlock

        _findlock.Event = m_Event(event_type, t.get_unix_time())

        db_resp = db_Findlock().update_findlock(_findlock)
        return m_LogicReturn.f_success_msg("Event updated!")
コード例 #11
0
    def get_findlock_info(findlock_uuid) -> m_LogicReturn:
        if not v.verify_uuid(findlock_uuid).success:
            return m_LogicReturn.f_error_msg(
                f"{findlock_uuid} is not a valid uuid")
        db_resp = db_Findlock().get_findlock(m_FindlockEntries.device_uuid,
                                             findlock_uuid)
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)

        _findlock = db_resp.addon_data
        _findlock: m_Findlock

        return m_LogicReturn.f_success("Findlock found!", _findlock)
コード例 #12
0
    def get_findlock(device_uuid) -> m_LogicReturn:
        if v.value_empty(device_uuid):
            return m_LogicReturn.f_error_msg("post data is missing")

        db_resp = db_Findlock().get_findlock(m_FindlockEntries.device_uuid,
                                             device_uuid)

        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)

        Findlock = db_resp.addon_data
        Findlock: m_Findlock

        return m_LogicReturn.f_success_msg(Findlock.toDict())
コード例 #13
0
    def get_findlock_event(device_uuid) -> m_LogicReturn:  #using
        if not v.verify_uuid(device_uuid).success:
            return m_LogicReturn.f_error_msg(
                f"{device_uuid} is not a valid uuid")

        db_resp = db_Findlock().get_findlock(m_FindlockEntries.device_uuid,
                                             device_uuid)
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)

        Findlock = db_resp.addon_data
        Findlock: m_Findlock

        # TODO: check if client waits for data in data and not in content
        return m_LogicReturn.f_success("Found event.", Findlock.Event.toDict())
コード例 #14
0
    def get_findlock_location(device_uuid) -> m_LogicReturn:
        if not v.verify_uuid(device_uuid).success:
            return m_LogicReturn.f_error_msg("Invalid UUID")

        db_resp = db_Findlock().get_findlock(m_FindlockEntries.device_uuid,
                                             device_uuid)
        if not db_resp.success:
            return m_LogicReturn.f_error_msg(db_resp.content)

        findlock = db_resp.addon_data
        findlock: m_Findlock

        n_locations = findlock.GpsLocationHistory.get_location_count() - 1
        if n_locations < 0:
            return m_LogicReturn.f_error_msg("No locations")
        return m_LogicReturn.f_success(
            "Returned.",
            findlock.GpsLocationHistory.get_location(n_locations).toDict())