diff --git a/ereuse_devicehub/config.py b/ereuse_devicehub/config.py index d1f89896..2d44b652 100644 --- a/ereuse_devicehub/config.py +++ b/ereuse_devicehub/config.py @@ -53,6 +53,7 @@ class DevicehubConfig(Config): """The minimum version of ereuse.org workbench that this devicehub accepts. we recommend not changing this value. """ + WORKBENCH_LITE = ["2022.03"] TMP_SNAPSHOTS = config('TMP_SNAPSHOTS', '/tmp/snapshots') TMP_LIVES = config('TMP_LIVES', '/tmp/lives') diff --git a/ereuse_devicehub/resources/action/schemas.py b/ereuse_devicehub/resources/action/schemas.py index 8e6879b0..15e1a972 100644 --- a/ereuse_devicehub/resources/action/schemas.py +++ b/ereuse_devicehub/resources/action/schemas.py @@ -416,34 +416,6 @@ class Install(ActionWithOneDevice): address = Integer(validate=OneOf({8, 16, 32, 64, 128, 256})) -class Snapshot_lite_data(MarshmallowSchema): - dmidecode = String(required=False) - hwinfo = String(required=False) - smart = String(required=False) - lshw = String(required=False) - - -class Snapshot_lite(MarshmallowSchema): - uuid = String(required=True) - version = String(required=True) - software = String(required=True) - wbid = String(required=True) - type = String(required=True) - timestamp = String(required=True) - data = Nested(Snapshot_lite_data) - - @validates_schema - def validate_workbench_version(self, data: dict): - if data['version'] < app.config['MIN_WORKBENCH']: - raise ValidationError( - 'Min. supported Workbench version is ' - '{} but yours is {}.'.format( - app.config['MIN_WORKBENCH'], data['version'] - ), - field_names=['version'], - ) - - class Snapshot(ActionWithOneDevice): __doc__ = m.Snapshot.__doc__ """ diff --git a/ereuse_devicehub/resources/action/views/snapshot.py b/ereuse_devicehub/resources/action/views/snapshot.py index 6c2cb87b..0e531767 100644 --- a/ereuse_devicehub/resources/action/views/snapshot.py +++ b/ereuse_devicehub/resources/action/views/snapshot.py @@ -7,13 +7,12 @@ from datetime import datetime from flask import current_app as app from flask import g -from flask.json import jsonify from sqlalchemy.util import OrderedSet from ereuse_devicehub.db import db from ereuse_devicehub.parser.parser import ParseSnapshotLsHw from ereuse_devicehub.resources.action.models import Snapshot -from ereuse_devicehub.resources.action.schemas import Snapshot_lite +from ereuse_devicehub.parser.schemas import Snapshot_lite from ereuse_devicehub.resources.device.models import Computer from ereuse_devicehub.resources.enums import Severity, SnapshotSoftware from ereuse_devicehub.resources.user.exceptions import InsufficientPermission @@ -78,12 +77,13 @@ class SnapshotView: self.tmp_snapshots = app.config['TMP_SNAPSHOTS'] self.path_snapshot = save_json(snapshot_json, self.tmp_snapshots, g.user.email) snapshot_json.pop('debug', None) - if snapshot_json.get('version') in ["2022.03"]: + version = snapshot_json.get('version') + if self.is_wb_lite_snapshot(version): self.validate_json(snapshot_json) - self.response = self.build_lite() - else: - self.snapshot_json = resource_def.schema.load(snapshot_json) - self.response = self.build() + snapshot_json = self.build_lite() + + self.snapshot_json = resource_def.schema.load(snapshot_json) + self.response = self.build() move_json(self.tmp_snapshots, self.path_snapshot, g.user.email) def post(self): @@ -134,15 +134,6 @@ class SnapshotView: # Check ownership of (non-component) device to from current.user if db_device.owner_id != g.user.id: raise InsufficientPermission() - # Compute ratings - # try: - # rate_computer, price = RateComputer.compute(db_device) - # except CannotRate: - # pass - # else: - # snapshot.actions.add(rate_computer) - # if price: - # snapshot.actions.add(price) elif snapshot.software == SnapshotSoftware.WorkbenchAndroid: pass # TODO try except to compute RateMobile # Check if HID is null and add Severity:Warning to Snapshot @@ -161,7 +152,13 @@ class SnapshotView: self.snapshot_json = self.schema2.load(snapshot_json) def build_lite(self): - snap = ParseSnapshotLsHw(self.snapshot_json) # snap = ParseSnapshot(self.snapshot_json) - self.snapshot_json = self.resource_def.schema.load(snap.snapshot_json) - return self.build() + snap = ParseSnapshotLsHw(self.snapshot_json) + return snap.snapshot_json + + def is_wb_lite_snapshot(self, version: str) -> bool: + is_lite = False + if version in app.config['WORKBENCH_LITE']: + is_lite = True + + return is_lite