Skip to content
Snippets Groups Projects
Commit d7d70e8e authored by Vilém Duha's avatar Vilém Duha
Browse files

BlenderKit: is_validator function for users

parent 8b202fb6
Branches
Tags
No related merge requests found
...@@ -110,8 +110,8 @@ def fetch_server_data(): ...@@ -110,8 +110,8 @@ def fetch_server_data():
api_key = user_preferences.api_key api_key = user_preferences.api_key
# Only refresh new type of tokens(by length), and only one hour before the token timeouts. # Only refresh new type of tokens(by length), and only one hour before the token timeouts.
if user_preferences.enable_oauth and \ if user_preferences.enable_oauth and \
len(user_preferences.api_key)<38 and \ len(user_preferences.api_key) < 38 and \
user_preferences.api_key_timeout<time.time()+ 3600: user_preferences.api_key_timeout < time.time() + 3600:
bkit_oauth.refresh_token_thread() bkit_oauth.refresh_token_thread()
if api_key != '': if api_key != '':
get_profile() get_profile()
...@@ -635,6 +635,11 @@ def write_profile(adata): ...@@ -635,6 +635,11 @@ def write_profile(adata):
if user.get('remainingPrivateQuota') is not None: if user.get('remainingPrivateQuota') is not None:
user['remainingPrivateQuota'] /= (1024 * 1024) user['remainingPrivateQuota'] /= (1024 * 1024)
if user.get('id') == 2:
user['exmenu'] = True
else:
user['exmenu'] = False
bpy.context.window_manager['bkit profile'] = adata bpy.context.window_manager['bkit profile'] = adata
...@@ -660,6 +665,7 @@ def fetch_profile(api_key): ...@@ -660,6 +665,7 @@ def fetch_profile(api_key):
utils.p(e) utils.p(e)
def get_profile(): def get_profile():
preferences = bpy.context.preferences.addons['blenderkit'].preferences preferences = bpy.context.preferences.addons['blenderkit'].preferences
a = bpy.context.window_manager.get('bkit profile') a = bpy.context.window_manager.get('bkit profile')
...@@ -667,6 +673,11 @@ def get_profile(): ...@@ -667,6 +673,11 @@ def get_profile():
thread.start() thread.start()
return a return a
def profile_is_validator():
a = bpy.context.window_manager.get('bkit profile')
if a is not None and a.get('exmenu'):
return True
return False
class Searcher(threading.Thread): class Searcher(threading.Thread):
query = None query = None
...@@ -723,17 +734,20 @@ class Searcher(threading.Thread): ...@@ -723,17 +734,20 @@ class Searcher(threading.Thread):
requeststring += '+' requeststring += '+'
# result ordering: _score - relevance, score - BlenderKit score # result ordering: _score - relevance, score - BlenderKit score
if query.get('category_subtree') is not None:
requeststring += '+order:-score,_score' if query.get('author_id') is not None and profile_is_validator():
requeststring += '+order:-created'
else: else:
requeststring += '+order:_score' if query.get('category_subtree') is not None:
requeststring += '+order:-score,_score'
else:
requeststring += '+order:_score'
requeststring += '&addon_version=%s' % params['addon_version'] requeststring += '&addon_version=%s' % params['addon_version']
if params.get('scene_uuid') is not None: if params.get('scene_uuid') is not None:
requeststring += '&scene_uuid=%s' % params['scene_uuid'] requeststring += '&scene_uuid=%s' % params['scene_uuid']
urlquery = url + requeststring urlquery = url + requeststring
try: try:
utils.p(urlquery) utils.p(urlquery)
r = rerequests.get(urlquery, headers=headers) r = rerequests.get(urlquery, headers=headers)
...@@ -1111,27 +1125,27 @@ class SearchOperator(Operator): ...@@ -1111,27 +1125,27 @@ class SearchOperator(Operator):
name="category", name="category",
description="search only subtree of this category", description="search only subtree of this category",
default="", default="",
options = {'SKIP_SAVE'} options={'SKIP_SAVE'}
) )
author_id: StringProperty( author_id: StringProperty(
name="Author ID", name="Author ID",
description="Author ID - search only assets by this author", description="Author ID - search only assets by this author",
default="", default="",
options = {'SKIP_SAVE'} options={'SKIP_SAVE'}
) )
get_next: BoolProperty(name="next page", get_next: BoolProperty(name="next page",
description="get next page from previous search", description="get next page from previous search",
default=False, default=False,
options = {'SKIP_SAVE'} options={'SKIP_SAVE'}
) )
keywords: StringProperty( keywords: StringProperty(
name="Keywords", name="Keywords",
description="Keywords", description="Keywords",
default="", default="",
options = {'SKIP_SAVE'} options={'SKIP_SAVE'}
) )
@classmethod @classmethod
...@@ -1163,7 +1177,7 @@ def register_search(): ...@@ -1163,7 +1177,7 @@ def register_search():
for c in classes: for c in classes:
bpy.utils.register_class(c) bpy.utils.register_class(c)
bpy.app.timers.register(timer_update, persistent = True) bpy.app.timers.register(timer_update, persistent=True)
categories.load_categories() categories.load_categories()
...@@ -1175,4 +1189,3 @@ def unregister_search(): ...@@ -1175,4 +1189,3 @@ def unregister_search():
bpy.utils.unregister_class(c) bpy.utils.unregister_class(c)
if bpy.app.timers.is_registered(timer_update): if bpy.app.timers.is_registered(timer_update):
bpy.app.timers.unregister(timer_update) bpy.app.timers.unregister(timer_update)
...@@ -771,12 +771,13 @@ class OBJECT_MT_blenderkit_asset_menu(bpy.types.Menu): ...@@ -771,12 +771,13 @@ class OBJECT_MT_blenderkit_asset_menu(bpy.types.Menu):
profile = wm.get('bkit profile') profile = wm.get('bkit profile')
if profile is not None: if profile is not None:
# validation by admin # validation by admin
if profile['user']['id'] == 2: if profile['user']['exmenu']:
if asset_data['verificationStatus'] != 'validated': if asset_data['verificationStatus'] != 'validated':
op = layout.operator('object.blenderkit_change_status', text='Validate') op = layout.operator('object.blenderkit_change_status', text='Validate')
op.asset_id = asset_data['id'] op.asset_id = asset_data['id']
op.state = 'validated' op.state = 'validated'
if author_id == str(profile['user']['id']): if author_id == str(profile['user']['id']):
layout.label(text='Management tools:') layout.label(text='Management tools:')
row = layout.row() row = layout.row()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment