Requires credential input for comment creation
This commit is contained in:
parent
6329ef1011
commit
ac69cd6966
2 changed files with 17 additions and 16 deletions
|
@ -18,7 +18,6 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
def create_comment_or_error(conn, comment, claim_id=None, channel_id=None, channel_name=None,
|
||||
signature=None, signing_ts=None, parent_id=None) -> dict:
|
||||
if channel_id and channel_name:
|
||||
insert_channel_or_error(conn, channel_name, channel_id)
|
||||
fn = db.insert_comment if parent_id is None else db.insert_reply
|
||||
comment_id = fn(
|
||||
|
@ -65,7 +64,7 @@ async def _abandon_comment(app, comment_id): # DELETE
|
|||
|
||||
|
||||
async def create_comment(app, params):
|
||||
if is_valid_base_comment(**params) and is_valid_credential_input(**params):
|
||||
if is_valid_base_comment(**params):
|
||||
job = await app['comment_scheduler'].spawn(_create_comment(app, params))
|
||||
comment = await job.wait()
|
||||
if comment:
|
||||
|
|
|
@ -51,22 +51,24 @@ def claim_id_is_valid(claim_id: str) -> bool:
|
|||
|
||||
|
||||
def is_valid_base_comment(comment: str, claim_id: str, parent_id: str = None, **kwargs) -> bool:
|
||||
return comment is not None and body_is_valid(comment) and \
|
||||
((claim_id is not None and claim_id_is_valid(claim_id)) or
|
||||
(parent_id is not None and comment_id_is_valid(parent_id)))
|
||||
return comment and body_is_valid(comment) and \
|
||||
((claim_id and claim_id_is_valid(claim_id)) or # parentid is used in place of claimid in replies
|
||||
(parent_id and comment_id_is_valid(parent_id))) \
|
||||
and is_valid_credential_input(**kwargs)
|
||||
|
||||
|
||||
def is_valid_credential_input(channel_id: str = None, channel_name: str = None,
|
||||
signature: str = None, signing_ts: str = None, **kwargs) -> bool:
|
||||
if channel_id or channel_name or signature or signing_ts:
|
||||
try:
|
||||
assert channel_id and channel_name and signature and signing_ts
|
||||
assert is_valid_channel(channel_id, channel_name)
|
||||
assert len(signature) == 128
|
||||
assert signing_ts.isalnum()
|
||||
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
logger.exception(f'Failed to validate channel: lbry://{channel_name}#{channel_id}, '
|
||||
f'signature: {signature} signing_ts: {signing_ts}')
|
||||
return False
|
||||
finally:
|
||||
return True
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue