Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hivemind
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
hivemind
Commits
56fb8218
Commit
56fb8218
authored
5 years ago
by
roadscape
Browse files
Options
Downloads
Patches
Plain Diff
posting_json_md upgrade path
parent
8537a2ef
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
hive/indexer/accounts.py
+1
-0
1 addition, 0 deletions
hive/indexer/accounts.py
hive/utils/account.py
+10
-3
10 additions, 3 deletions
hive/utils/account.py
tests/utils/test_utils_account.py
+6
-1
6 additions, 1 deletion
tests/utils/test_utils_account.py
with
17 additions
and
4 deletions
hive/indexer/accounts.py
+
1
−
0
View file @
56fb8218
...
@@ -185,6 +185,7 @@ class Accounts:
...
@@ -185,6 +185,7 @@ class Accounts:
# pull out valid profile md and delete the key
# pull out valid profile md and delete the key
profile
=
safe_profile_metadata
(
account
)
profile
=
safe_profile_metadata
(
account
)
del
account
[
'
json_metadata
'
]
del
account
[
'
posting_json_metadata
'
]
del
account
[
'
posting_json_metadata
'
]
active_at
=
max
(
account
[
'
created
'
],
active_at
=
max
(
account
[
'
created
'
],
...
...
This diff is collapsed.
Click to expand it.
hive/utils/account.py
+
10
−
3
View file @
56fb8218
...
@@ -6,12 +6,19 @@ from hive.utils.normalize import trunc
...
@@ -6,12 +6,19 @@ from hive.utils.normalize import trunc
def
safe_profile_metadata
(
account
):
def
safe_profile_metadata
(
account
):
"""
Given an account, return sanitized profile data.
"""
"""
Given an account, return sanitized profile data.
"""
prof
=
{}
prof
=
{}
try
:
try
:
# read from posting_json_metadata, if version==2
prof
=
json
.
loads
(
account
[
'
posting_json_metadata
'
])[
'
profile
'
]
prof
=
json
.
loads
(
account
[
'
posting_json_metadata
'
])[
'
profile
'
]
if
no
t
isinstance
(
prof
,
dict
)
:
asser
t
isinstance
(
prof
,
dict
)
prof
=
{}
assert
'
version
'
in
prof
and
prof
[
'
version
'
]
==
2
except
Exception
:
except
Exception
:
pass
try
:
# fallback to json_metadata
prof
=
json
.
loads
(
account
[
'
json_metadata
'
])[
'
profile
'
]
assert
isinstance
(
prof
,
dict
)
except
Exception
:
prof
=
{}
name
=
str
(
prof
[
'
name
'
])
if
'
name
'
in
prof
else
None
name
=
str
(
prof
[
'
name
'
])
if
'
name
'
in
prof
else
None
about
=
str
(
prof
[
'
about
'
])
if
'
about
'
in
prof
else
None
about
=
str
(
prof
[
'
about
'
])
if
'
about
'
in
prof
else
None
...
...
This diff is collapsed.
Click to expand it.
tests/utils/test_utils_account.py
+
6
−
1
View file @
56fb8218
...
@@ -11,6 +11,7 @@ def test_valid_account():
...
@@ -11,6 +11,7 @@ def test_valid_account():
website
=
'
http://www.davincilife.com/
'
,
website
=
'
http://www.davincilife.com/
'
,
cover_image
=
'
https://steemitimages.com/0x0/https://pbs.twimg.com/profile_banners/816255358066946050/1483447009/1500x500
'
,
cover_image
=
'
https://steemitimages.com/0x0/https://pbs.twimg.com/profile_banners/816255358066946050/1483447009/1500x500
'
,
profile_image
=
'
https://www.parhlo.com/wp-content/uploads/2016/01/tmp617041537745813506.jpg
'
,
profile_image
=
'
https://www.parhlo.com/wp-content/uploads/2016/01/tmp617041537745813506.jpg
'
,
version
=
2
,
)
)
account
=
{
'
name
'
:
'
foo
'
,
'
posting_json_metadata
'
:
json
.
dumps
(
dict
(
profile
=
raw_profile
))}
account
=
{
'
name
'
:
'
foo
'
,
'
posting_json_metadata
'
:
json
.
dumps
(
dict
(
profile
=
raw_profile
))}
...
@@ -26,7 +27,11 @@ def test_invalid_account():
...
@@ -26,7 +27,11 @@ def test_invalid_account():
cover_image
=
'
example.com/avatar.jpg
'
,
cover_image
=
'
example.com/avatar.jpg
'
,
profile_image
=
'
https://example.com/valid-url-but-longer-than-1024-chars
'
+
'
x
'
*
1024
,
profile_image
=
'
https://example.com/valid-url-but-longer-than-1024-chars
'
+
'
x
'
*
1024
,
)
)
account
=
{
'
name
'
:
'
foo
'
,
'
json_metadata
'
:
json
.
dumps
(
dict
(
profile
=
raw_profile
))}
ignore_prof
=
dict
(
name
=
'
Ignore me -- missing version:2!
'
,
)
account
=
{
'
name
'
:
'
foo
'
,
'
json_metadata
'
:
json
.
dumps
(
dict
(
profile
=
raw_profile
)),
'
posting_json_metadata
'
:
json
.
dumps
(
dict
(
profile
=
ignore_prof
))}
safe_profile
=
safe_profile_metadata
(
account
)
safe_profile
=
safe_profile_metadata
(
account
)
assert
safe_profile
[
'
name
'
]
==
'
NameIsTooBigByOne...
'
assert
safe_profile
[
'
name
'
]
==
'
NameIsTooBigByOne...
'
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment