コード例 #1
0
    def delete(cls, id: int):
        '''Delete Application'''
        try:
            claims = get_jwt_claims()
            if not claims['is_admin']:
                return {
                    'message':
                    'You are not authorised to access this resource!'
                }, 403

            application = ApplicationModel.fetch_by_id(id)
            if application:
                ApplicationModel.delete_by_id(id)

                # Record this event in user's logs
                log_method = 'delete'
                log_description = f'Deleted application <{id}>'
                authorization = request.headers.get('Authorization')
                auth_token = {"Authorization": authorization}
                record_user_log(auth_token, log_method, log_description)
                return {'message': f'Deleted software <{id}>'}, 200
            return {'message': 'This record does not exist!'}, 404

        except Exception as e:
            print('========================================')
            print('Error description: ', e)
            print('========================================')
            return {'message': 'Could not delete this application.'}, 500
コード例 #2
0
 def get(cls, id: int):
     '''Get Single Application'''
     try:
         application = ApplicationModel.fetch_by_id(id)
         if application:
             app = application_schema.dump(application)
             license_count = len(app['licenses'])
             app['licenses'] = license_count
             return app, 200
         return {
             'message': 'This antivirus application does not exist.'
         }, 404
     except Exception as e:
         print('========================================')
         print('Error description: ', e)
         print('========================================')
         return {'message': 'Could not retrieve application.'}, 500
コード例 #3
0
    def post(cls):
        '''Post License'''
        try:
            claims = get_jwt_claims()
            if not claims['is_admin']:
                return {
                    'message': 'You are not authorised to use this resource'
                }, 403

            data = api.payload
            if not data:
                return {'message': 'No input data detected'}, 400

            application_id = data['application_id']
            license_key = data['license_key']

            if license_key == '':
                return {'message': 'You have not specified any key.'}, 400

            application = ApplicationModel.fetch_by_id(id=application_id)
            if application:
                new_license = LicenseModel(application_id=application_id,
                                           license_key=license_key)
                new_license.insert_record()

                # Record this event in user's logs
                log_method = 'post'
                log_description = f'Added license to application <{application_id}>'
                authorization = request.headers.get('Authorization')
                auth_token = {"Authorization": authorization}
                record_user_log(auth_token, log_method, log_description)

                return {'message': 'Successfully added license'}, 201
            return {
                'message': 'The specified application does not exist.'
            }, 400
        except Exception as e:
            print('========================================')
            print('Error description: ', e)
            print('========================================')
            return {'message': 'Could not fetch licenses.'}, 500
コード例 #4
0
    def put(cls, id: int):
        '''Update Logo'''
        try:
            claims = get_jwt_claims()
            if not claims['is_admin']:
                return {
                    'message':
                    'You are not authorised to access this resource!'
                }, 403

            args = logo_parser.parse_args()
            image_file = args.get('logo')  # This is FileStorage instance

            application = ApplicationModel.fetch_by_id(id)
            if application:
                if image_file.filename == '':
                    return {'message': 'No logo was found.'}, 400

                if image_file and allowed_file(image_file.filename):
                    logo = secure_filename(image_file.filename)
                    image_file.save(os.path.join('uploads', logo))

                    ApplicationModel.update_logo(id=id, logo=logo)

                    # Record this event in user's logs
                    log_method = 'put'
                    log_description = f'Updated logo for application <{id}>'
                    authorization = request.headers.get('Authorization')
                    auth_token = {"Authorization": authorization}
                    record_user_log(auth_token, log_method, log_description)
                    return application_schema.dump(application), 200
                return {
                    'message': 'The logo you uploaded is not recognised.'
                }, 400
            return {'message': 'This record does not exist!'}, 404

        except Exception as e:
            print('========================================')
            print('Error description: ', e)
            print('========================================')
            return {'message': 'Could not submit software logo.'}, 500
コード例 #5
0
    def put(cls, id: int):
        '''Update Application'''
        try:
            claims = get_jwt_claims()
            if not claims['is_admin']:
                return {
                    'message':
                    'You are not authorised to access this resource!'
                }, 403

            data = api.payload
            if not data:
                return {'message': 'No input data detected!'}, 400

            # description = data['description']
            # download_link = data['download_link']
            # price = data['price']

            application = ApplicationModel.fetch_by_id(id)
            if application:
                ApplicationModel.update_application(
                    id=id, **data
                )  # description=description, download_link=download_link, price=price)

                # Record this event in user's logs
                log_method = 'put'
                log_description = f'Updated application <{id}>'
                authorization = request.headers.get('Authorization')
                auth_token = {"Authorization": authorization}
                record_user_log(auth_token, log_method, log_description)
                return application_schema.dump(application), 200
            return {'message': 'This record does not exist.'}, 404
        except Exception as e:
            print('========================================')
            print('Error description: ', e)
            print('========================================')
            return {'message': 'Could not update application.'}, 500