Merge remote-tracking branch 'origin/test' into test

pull/101/head
Chris Veilleux 2019-04-03 19:22:16 -05:00
commit 6896718da2
8 changed files with 30 additions and 2 deletions

View File

@ -3,6 +3,7 @@ from flask import Flask
from selene.api import get_base_config, selene_api, SeleneResponse
from selene.api.endpoints import AccountEndpoint, AgreementsEndpoint
from selene.util.cache import SeleneCache
from selene.util.log import configure_logger
from .endpoints import (
PreferencesEndpoint,
@ -29,6 +30,7 @@ acct = Flask(__name__)
acct.config.from_object(get_base_config())
acct.response_class = SeleneResponse
acct.register_blueprint(selene_api)
acct.config['SELENE_CACHE'] = SeleneCache()
account_endpoint = AccountEndpoint.as_view('account_endpoint')
acct.add_url_rule(

View File

@ -3,8 +3,8 @@ from logging import getLogger
from flask import json
from schematics import Model
from schematics.types import StringType
from schematics.exceptions import ValidationError
from schematics.types import StringType
from selene.api import SeleneEndpoint
from selene.data.device import DeviceRepository, Geography, GeographyRepository
@ -41,7 +41,6 @@ class DeviceEndpoint(SeleneEndpoint):
def __init__(self):
super(DeviceEndpoint, self).__init__()
self.devices = None
self.cache = SeleneCache()
def get(self):
self._authenticate()

View File

@ -60,3 +60,4 @@ class SkillSettingsEndpoint(SeleneEndpoint):
skill_id,
new_skill_settings
)
self.etag_manager.expire_skill_etag_by_account_id(self.account.id)

View File

@ -1,15 +1,18 @@
"""Base class for Flask API endpoints"""
from copy import deepcopy
from logging import getLogger
from flask import after_this_request, current_app, request
from flask.views import MethodView
from selene.api.etag import ETagManager
from selene.data.account import (
Account,
AccountRepository,
RefreshTokenRepository
)
from selene.util.auth import AuthenticationError, AuthenticationToken
from selene.util.cache import SeleneCache
from selene.util.db import get_db_connection
ACCESS_TOKEN_COOKIE_NAME = 'seleneAccess'
@ -41,6 +44,8 @@ class SeleneEndpoint(MethodView):
self.account: Account = None
self.access_token = self._init_access_token()
self.refresh_token = self._init_refresh_token()
self.cache: SeleneCache = self.config['SELENE_CACHE']
self.etag_manager: ETagManager = ETagManager(self.cache, self.config)
def _init_access_token(self):
return AuthenticationToken(

View File

@ -82,3 +82,9 @@ class ETagManager(object):
"""Expire the locations' etag for a given device
:param device_id: device uuid"""
self._expire(device_skill_etag_key(device_id))
def expire_skill_etag_by_account_id(self, account_id):
with get_db_connection(self.db_connection_pool) as db:
devices = DeviceRepository(db).get_devices_by_account_id(account_id)
for device in devices:
self.expire_skill_etag_by_device_id(device.id)

View File

@ -17,3 +17,13 @@ class DeviceSkillRepository(RepositoryBase):
)
)
self.cursor.insert(db_request)
def delete(self, device_id, skill_id):
db_request = self._build_db_request(
sql_file_name='delete_device_skill.sql',
args=dict(
device_id=device_id,
skill_id=skill_id
)
)
self.cursor.delete(db_request)

View File

@ -101,6 +101,7 @@ class SkillRepository(RepositoryBase):
settings_display = json.dumps(skill)
skill_settings_display_id = SettingsDisplayRepository(self.db).add(skill_id, settings_display)
settings_value = json.dumps(settings_value)
DeviceSkillRepository(self.db).delete(device_id, skill_id)
DeviceSkillRepository(self.db).add(device_id, skill_id, skill_settings_display_id, settings_value)
return skill_id

View File

@ -0,0 +1,4 @@
DELETE FROM
device.device_skill
WHERE
device_id = %(device_id)s AND skill_id = %(skill_id)s