DB Fixes
This commit is contained in:
parent
e363ebf5ca
commit
f685c48614
5 changed files with 9 additions and 8 deletions
|
@ -42,7 +42,7 @@ def load_logged_in_user():
|
||||||
g.user = None
|
g.user = None
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
user = UserQuery.get(user_id)
|
user = UserQuery.get(id=user_id)
|
||||||
g.user = user
|
g.user = user
|
||||||
except UserQuery.NotFound:
|
except UserQuery.NotFound:
|
||||||
g.user = None
|
g.user = None
|
||||||
|
|
|
@ -41,7 +41,6 @@ def incoming_platform_message_view(platform, path=None):
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
@app.route("/healthz")
|
@app.route("/healthz")
|
||||||
def healthz():
|
def healthz():
|
||||||
return {}
|
return {}
|
||||||
|
|
|
@ -32,7 +32,7 @@ class Query:
|
||||||
Allows retrieving object by multiple columns.
|
Allows retrieving object by multiple columns.
|
||||||
Raises `NotFound` error if query return no results.
|
Raises `NotFound` error if query return no results.
|
||||||
"""
|
"""
|
||||||
row = db[cls.tablename].find_one()
|
row = db[cls.tablename].find_one(**kwargs)
|
||||||
if not row:
|
if not row:
|
||||||
raise cls.NotFound
|
raise cls.NotFound
|
||||||
return cls.obj(**row)
|
return cls.obj(**row)
|
||||||
|
@ -109,14 +109,14 @@ class ChannelQuery(Query):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get(cls, _id):
|
def get(cls, _id):
|
||||||
channel = super().get(_id)
|
channel = super().get(id=_id)
|
||||||
plugins = ChannelPluginQuery.get_from_channel_id(_id)
|
plugins = ChannelPluginQuery.get_from_channel_id(_id)
|
||||||
channel.plugins = {plugin.plugin_id: plugin for plugin in plugins}
|
channel.plugins = {plugin.plugin_id: plugin for plugin in plugins}
|
||||||
return channel
|
return channel
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_by_platform(cls, platform, platform_channel_id):
|
def get_by_platform(cls, platform, platform_channel_id):
|
||||||
result = cls.tablename.find_one(
|
result = db[cls.tablename].find_one(
|
||||||
platform=platform, platform_channel_id=platform_channel_id
|
platform=platform, platform_channel_id=platform_channel_id
|
||||||
)
|
)
|
||||||
if not result:
|
if not result:
|
||||||
|
@ -154,8 +154,8 @@ class ChannelPluginQuery(Query):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_from_channel_id(cls, channel_id):
|
def get_from_channel_id(cls, channel_id):
|
||||||
yield from [cls.obj(**row) for row in cls.tablename.find(channel_id=channel_id)]
|
yield from [cls.obj(**row) for row in db[cls.tablename].find(channel_id=channel_id)]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def delete_by_channel(cls, channel_id):
|
def delete_by_channel(cls, channel_id):
|
||||||
cls.tablename.delete(channel_id=channel_id)
|
cls.delete(channel_id=channel_id)
|
||||||
|
|
|
@ -82,7 +82,7 @@ class SlackPlatform(Platform):
|
||||||
logger.debug("Parsing message", platform=cls.ID, data=data)
|
logger.debug("Parsing message", platform=cls.ID, data=data)
|
||||||
return Message(
|
return Message(
|
||||||
id=data["event"].get("thread_ts", data["event"]["ts"]),
|
id=data["event"].get("thread_ts", data["event"]["ts"]),
|
||||||
author=data["event"]["user"],
|
author=data["event"].get("user"),
|
||||||
from_bot="bot_id" in data["event"],
|
from_bot="bot_id" in data["event"],
|
||||||
date=datetime.fromtimestamp(int(float(data["event"]["event_ts"]))),
|
date=datetime.fromtimestamp(int(float(data["event"]["event_ts"]))),
|
||||||
text=data["event"]["text"],
|
text=data["event"]["text"],
|
||||||
|
|
|
@ -8,6 +8,7 @@ import structlog
|
||||||
|
|
||||||
from butterrobot.objects import Message
|
from butterrobot.objects import Message
|
||||||
|
|
||||||
|
|
||||||
logger = structlog.get_logger(__name__)
|
logger = structlog.get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,4 +64,5 @@ def get_available_plugins():
|
||||||
module=ep.module_name,
|
module=ep.module_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
logger.info("Plugins loaded", plugins=list(plugins.keys()))
|
||||||
return plugins
|
return plugins
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue