Tested and fixed trust createorupdate

This commit is contained in:
simonwt 2026-04-07 21:54:52 +01:00
parent 255d6ef37b
commit 766ff5b69d
11 changed files with 100 additions and 4 deletions

View file

@ -8,5 +8,5 @@ def createorupdate(API, payload: dict) -> dict:
Returns:
dict: The trust relationship data.
"""
trust_data = API.make_request("POST", "content", "reltrust", data=payload, authenticate=True)
trust_data = API.make_request("PUT", "content", "reltrust", data=payload, authenticate=True)
return trust_data

View file

@ -2,4 +2,6 @@ from .get_parent_pksk_from_path import get_parent_pksk_from_path
from .get_post_pksk import get_post_pksk
from .make_comment_sk import make_comment_sk
from .make_post_sk import make_post_sk
from .get_child_spksk_from_paths import get_child_spksk_from_paths
from .get_child_spksk_from_paths import get_child_spksk_from_paths
from .get_user_slug_from_path import get_user_slug_from_path
from .get_userprofile_pksk_from_slug import get_userprofile_pksk_from_slug

View file

@ -0,0 +1,21 @@
def get_user_slug_from_path(path: str):
"""
Extracts the user slug from a given path.
Args:
path (str): The path from which to extract the user slug.
Returns:
str: The extracted user slug.
"""
if not isinstance(path, str):
raise ValueError("Input path must be a string.")
if '/userprofile/' in path:
return path.split('/userprofile/')[-1]
elif '/user/' in path:
return path.split('/user/')[-1]
elif '/' not in path:
return path
else:
return None

View file

@ -0,0 +1,6 @@
def get_userprofile_pksk_from_slug(slug: str):
pksk = "userprofile#" + slug
return {
"pk": pksk,
"sk": pksk
}

View file

@ -0,0 +1 @@
from .trust import trust

View file

@ -0,0 +1,22 @@
from trustcafeapiwrapper.utils import get_user_slug_from_path, get_userprofile_pksk_from_slug
def trust(trustLevel: str, userprofile_path: str):
"""
Creates new or update existing trust entry in the API.
Args:
Returns:
dict: A dictionary containing the job name and payload for creating the post
that will be processed by the API client wrapper function.
"""
userProfileSlug = get_user_slug_from_path(userprofile_path)
userPKSK = get_userprofile_pksk_from_slug(userProfileSlug)
return {
"job_function": "trust.createorupdate",
"payload": {
"trustLevel": trustLevel,
"parentSlug": userProfileSlug,
"parent": userPKSK
}
}