示例#1
0
 def delete(cls):
     uuid = get_authorized_user_uuid()
     user = UserModel.find_by_uuid(uuid)
     if user is None:
         raise NotFoundException("User does not exist")
     user.delete_from_db()
     return '', 204
示例#2
0
 def get(cls, uuid):
     user_uuid = get_authorized_user_uuid()
     device: DeviceModel = DeviceModel.find_by_user_uuid_and_uuid(
         user_uuid, uuid)
     if device is None:
         raise NotFoundException('Device not found')
     return device
示例#3
0
 def delete(cls, device_id):
     user_uuid = get_authorized_user_uuid()
     device: DeviceModel = DeviceModel.find_by_user_uuid_and_device_id(
         user_uuid, device_id)
     if device is None:
         return '', 204  # we are not throwing error even though we didn't match the device_uuid
     device.delete_from_db()
     return '', 204
示例#4
0
 def delete(cls, uuid):
     user_uuid = get_authorized_user_uuid()
     device: DeviceModel = DeviceModel.find_by_user_uuid_and_uuid(
         user_uuid, uuid)
     if device is None:
         raise NotFoundException("Device not found")
     device.delete_from_db()
     return '', 204
示例#5
0
 def patch(cls):
     uuid = get_authorized_user_uuid()
     user = UserModel.find_by_uuid(uuid)
     if not user:
         raise NotFoundException("User does not exist")
     args = parse_user_update()
     user.update(**args)
     return user
示例#6
0
 def get(cls):
     uuid = get_authorized_user_uuid()
     user = UserModel.find_by_uuid(uuid)
     if not user:
         raise NotFoundException("User does not exist")
     output: List[SiteModel] = []
     for site in user.sites:
         output.append(SiteModel.find_by_uuid(site.site_uuid))
     return output
示例#7
0
 def post(cls):
     args = cls.parser.parse_args()
     uuid = str(shortuuid.uuid())
     user_uuid = get_authorized_user_uuid()
     device = DeviceModel.find_by_user_uuid_and_device_id(
         user_uuid, args['device_id'])
     if device:
         return device
     device = DeviceModel(uuid=uuid, user_uuid=user_uuid, **args)
     device.save_to_db()
     return device
示例#8
0
 def patch(cls, uuid):
     parser = reqparse.RequestParser()
     parser.add_argument('device_id',
                         type=str,
                         required=False,
                         store_missing=False)
     args = parser.parse_args()
     user_uuid = get_authorized_user_uuid()
     device: DeviceModel = DeviceModel.find_by_user_uuid_and_uuid(
         user_uuid, uuid)
     if device is None:
         raise NotFoundException("Device not found")
     device.update(**args)
     return device
示例#9
0
 def get(cls):
     device_info: Union[DeviceInfoModel, None] = get_device_info()
     if not device_info:
         logger.error('Please add device_info on Rubix Service')
         return
     uuid = get_authorized_user_uuid()
     user = UserModel.find_by_uuid(uuid)
     output: dict = {}
     for site in user.sites:
         output[site.site_uuid] = {
             'layout_topic':
             f'{device_info.global_uuid}/{site.site_uuid}/layout',
             'alert_topic':
             f'{device_info.global_uuid}/{site.site_uuid}/alerts'
         }
     return output
示例#10
0
 def get(cls):
     user_uuid = get_authorized_user_uuid()
     return DeviceModel.find_all_by_user_uuid(user_uuid=user_uuid)
示例#11
0
 def get(cls):
     username = get_authorized_username()
     uuid_ = get_authorized_user_uuid()
     return encode_jwt_token(uuid_, username)
示例#12
0
 def get(cls):
     uuid = get_authorized_user_uuid()
     user = UserModel.find_by_uuid(uuid)
     if not user:
         raise NotFoundException("User does not exist")
     return user