Commit be07256b authored by Krzysztof Mochocki's avatar Krzysztof Mochocki
Browse files

fixed community name validation

parent 2956ce10
......@@ -8,6 +8,7 @@ from hive.server.common.helpers import (
valid_permlink,
valid_tag,
valid_limit,
check_community,
json_date)
from hive.utils.account import safe_db_profile_metadata
......@@ -250,7 +251,7 @@ async def get_ranked_posts(context, sort:str, start_author:str='', start_permlin
result = await _get_ranked_posts_for_observer_communities(db, sort, start_author, start_permlink, limit, observer)
return await process_query_results(result)
if tag and tag[:5] == 'hive-':
if tag and check_community(tag):
result = await _get_ranked_posts_for_communities(db, sort, tag, start_author, start_permlink, limit, observer)
return await process_query_results(result)
......
......@@ -8,6 +8,7 @@ import datetime
from dateutil.relativedelta import relativedelta
from psycopg2.errors import RaiseException
from jsonrpcserver.exceptions import ApiError as RPCApiError
from hive.indexer.community import Community
log = logging.getLogger(__name__)
......@@ -81,6 +82,14 @@ def get_hive_accounts_info_view_query_string(names, lite = False):
""".format( ( 'hive_accounts_info_view_lite' if lite else 'hive_accounts_info_view' ), values_str )
return sql
def check_community(name) -> bool:
return Community.validated_name(name) is not None
def valid_community(name):
"""Checks is given name of community matches community regex, if not asserts"""
assert check_community(name), "given community name is not valid"
return name
def valid_account(name, allow_empty=False):
"""Returns validated account name or throws Assert."""
if not name:
......
......@@ -1312,7 +1312,7 @@
"permlink": "introduce",
"title": "My introduce post",
"body": "This is a cross post of [@test-creator/introduce](/introduceyourself/@test-creator/introduce) by @test-creator.<br><br>crosspost test",
"json_metadata": "{\"app\":\"peakd/2021.01.3\",\"tags\":[\"cross-post\"],\"image\":[],\"original_author\":\"test-creator\",\"original_permlink\":\"introduce\"}"
"json_metadata": "{\"app\":\"peakd/2021.01.3\",\"tags\":[\"cross-post\", \"hive-engine\"],\"image\":[],\"original_author\":\"test-creator\",\"original_permlink\":\"introduce\"}"
}
},
{
......
Subproject commit c737db85c8fcb68426a232438c9228bd13b9847e
Subproject commit a1da9e7b6beb73f529f0013d3c20c9176b0391a2
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment