This commit is contained in:
Oleg Silkin 2019-12-31 04:59:58 -05:00
parent 2311fa00e6
commit 6250cae13c
2 changed files with 16 additions and 22 deletions

View file

@ -101,20 +101,20 @@ async def hide_comments(app, pieces: list) -> list:
return comment_ids
async def edit_comment(app, comment_id: str, new_comment: str, channel_id: str,
async def edit_comment(app, comment_id: str, comment: str, channel_id: str,
channel_name: str, signature: str, signing_ts: str):
if not(is_valid_credential_input(channel_id, channel_name, signature, signing_ts)
and body_is_valid(new_comment)):
and body_is_valid(comment)):
logging.error('Invalid argument values, check input and try again')
return
comment = db.get_comment_or_none(app['reader'], comment_id)
if not(comment and 'channel_id' in comment and comment['channel_id'] == channel_id.lower()):
cmnt = db.get_comment_or_none(app['reader'], comment_id)
if not(cmnt and 'channel_id' in cmnt and cmnt['channel_id'] == channel_id.lower()):
logging.error("comment doesnt exist")
return
channel = await get_claim_from_id(app, channel_id)
if not validate_signature_from_claim(channel, signature, signing_ts, new_comment):
if not validate_signature_from_claim(channel, signature, signing_ts, comment):
logging.error("signature could not be validated")
return
@ -123,14 +123,10 @@ async def edit_comment(app, comment_id: str, new_comment: str, channel_id: str,
comment_id=comment_id,
signature=signature,
signing_ts=signing_ts,
comment=new_comment
comment=comment
))
if await job.wait():
logging.info('comment successfully edited')
return db.get_comment_or_none(app['reader'], comment_id)
else:
logging.critical('comment could not be edited')
return await job.wait()
async def abandon_comment(app, comment_id, channel_id, signature, signing_ts, **kwargs):

View file

@ -5,12 +5,10 @@ import time
from aiohttp import web
from aiojobs.aiohttp import atomic
from src.database.queries import get_channel_id_from_comment_id
from src.database.queries import get_claim_comments
from src.database.queries import get_claim_hidden_comments
from src.database.queries import get_comments_by_id, get_comment_ids
import src.database.queries as db
from src.database.writes import abandon_comment, create_comment
from src.database.writes import hide_comments
from src.database.writes import edit_comment
from src.server.misc import clean_input_params
from src.server.errors import make_error, report_error
@ -23,23 +21,23 @@ def ping(*args):
def handle_get_channel_from_comment_id(app, kwargs: dict):
return get_channel_id_from_comment_id(app['reader'], **kwargs)
return db.get_channel_id_from_comment_id(app['reader'], **kwargs)
def handle_get_comment_ids(app, kwargs):
return get_comment_ids(app['reader'], **kwargs)
return db.get_comment_ids(app['reader'], **kwargs)
def handle_get_claim_comments(app, kwargs):
return get_claim_comments(app['reader'], **kwargs)
return db.get_claim_comments(app['reader'], **kwargs)
def handle_get_comments_by_id(app, kwargs):
return get_comments_by_id(app['reader'], **kwargs)
return db.get_comments_by_id(app['reader'], **kwargs)
def handle_get_claim_hidden_comments(app, kwargs):
return get_claim_hidden_comments(app['reader'], **kwargs)
return db.get_claim_hidden_comments(app['reader'], **kwargs)
async def handle_abandon_comment(app, params):
@ -51,8 +49,8 @@ async def handle_hide_comments(app, params):
async def handle_edit_comment(app, params):
if handle_edit_comment(app, **params):
pass
if await edit_comment(app, **params):
return db.get_comment_or_none(app['reader'], params['comment_id'])
METHODS = {