filter from owners in get private device or redirect to public and filter devices from owner the manual merge
This commit is contained in:
parent
8a471c98c0
commit
3eecdb4a1e
|
@ -98,7 +98,7 @@ class DeviceView(View):
|
||||||
return super().get(id)
|
return super().get(id)
|
||||||
|
|
||||||
def patch(self, id):
|
def patch(self, id):
|
||||||
dev = Device.query.filter_by(id=id).one()
|
dev = Device.query.filter_by(id=id, owner_id=g.user.id).one()
|
||||||
if isinstance(dev, Computer):
|
if isinstance(dev, Computer):
|
||||||
resource_def = app.resources['Computer']
|
resource_def = app.resources['Computer']
|
||||||
# TODO check how to handle the 'actions_one'
|
# TODO check how to handle the 'actions_one'
|
||||||
|
@ -128,9 +128,9 @@ class DeviceView(View):
|
||||||
|
|
||||||
@auth.Auth.requires_auth
|
@auth.Auth.requires_auth
|
||||||
def one_private(self, id: int):
|
def one_private(self, id: int):
|
||||||
device = Device.query.filter_by(id=id).one()
|
device = Device.query.filter_by(id=id, owner_id=g.user.id).first()
|
||||||
if hasattr(device, 'owner_id') and device.owner_id != g.user.id:
|
if not device:
|
||||||
device = {}
|
return self.one_public(id)
|
||||||
return self.schema.jsonify(device)
|
return self.schema.jsonify(device)
|
||||||
|
|
||||||
@auth.Auth.requires_auth
|
@auth.Auth.requires_auth
|
||||||
|
@ -172,8 +172,8 @@ class DeviceMergeView(View):
|
||||||
return args['id']
|
return args['id']
|
||||||
|
|
||||||
def post(self, id: uuid.UUID):
|
def post(self, id: uuid.UUID):
|
||||||
device = Device.query.filter_by(id=id).one()
|
device = Device.query.filter_by(id=id, owner_id=g.user.id).one()
|
||||||
with_device = Device.query.filter_by(id=self.get_merge_id()).one()
|
with_device = Device.query.filter_by(id=self.get_merge_id(), owner_id=g.user.id).one()
|
||||||
self.merge_devices(device, with_device)
|
self.merge_devices(device, with_device)
|
||||||
|
|
||||||
db.session().final_flush()
|
db.session().final_flush()
|
||||||
|
|
Reference in New Issue