forked from sch/Blasta
Python : Utilize XEP-0004: Data Forms to store configurations;
Python : Fix error in blasta_client.py (Thank you. yvo.); XMPP : Replace node xmpp:blasta:settings:0 by xmpp:blasta:configuration:0;
This commit is contained in:
parent
ea255d84e0
commit
0ab40eedec
3 changed files with 82 additions and 37 deletions
57
blasta.py
57
blasta.py
|
@ -60,7 +60,7 @@ class Data:
|
|||
entry_tags = entry['tags']
|
||||
entry_url_hash = entry['url_hash']
|
||||
tags_to_include = []
|
||||
if query in entry_tags or query in ' '.join([entry['title'], entry['link'], entry['summary']]):
|
||||
if query in ' '.join([entry['title'], entry['link'], entry['summary'], ' '.join(entry_tags)]):
|
||||
item_ids.append(entry_url_hash)
|
||||
tags_to_include += entry_tags
|
||||
for tag_to_include in tags_to_include:
|
||||
|
@ -1387,19 +1387,21 @@ class HttpInstance:
|
|||
path = 'error'
|
||||
return result_post(request, jabber_id, description, message, path)
|
||||
else:
|
||||
iq = await XmppPubsub.get_node_item(xmpp_instance, jabber_id, 'xmpp:blasta:settings:0', 'routine')
|
||||
iq = await XmppPubsub.get_node_item(xmpp_instance, jabber_id, 'xmpp:blasta:configuration:0', 'routine')
|
||||
routine = None
|
||||
if isinstance(iq, slixmpp.stanza.iq.Iq):
|
||||
payload = iq['pubsub']['items']['item']['payload']
|
||||
routine = payload.text if payload else None
|
||||
else:
|
||||
routine = None
|
||||
if payload:
|
||||
xmlns = '{jabber:x:data}'
|
||||
element_value = payload.find('.//' + xmlns + 'field[@var="routine"]/' + xmlns + 'value')
|
||||
if isinstance(element_value, ET.Element): routine = element_value.text
|
||||
match routine:
|
||||
case 'private':
|
||||
response = RedirectResponse(url='/private')
|
||||
case 'read':
|
||||
response = RedirectResponse(url='/read')
|
||||
case _:
|
||||
response = RedirectResponse(url='/jid/' + jabber_id)
|
||||
response = RedirectResponse(url='/jid/')
|
||||
|
||||
else:
|
||||
#del accounts[jabber_id]
|
||||
|
@ -1470,7 +1472,7 @@ class HttpInstance:
|
|||
jabber_id = Utilities.is_jid_matches_to_session(accounts, sessions, request)
|
||||
if jabber_id:
|
||||
xmpp_instance = accounts[jabber_id]
|
||||
if not await XmppPubsub.is_node_exist(xmpp_instance, 'xmpp:blasta:settings:0'):
|
||||
if not await XmppPubsub.is_node_exist(xmpp_instance, 'xmpp:blasta:configuration:0'):
|
||||
iq = XmppPubsub.create_node_config(xmpp_instance, jabber_id)
|
||||
await iq.send(timeout=15)
|
||||
access_models = {}
|
||||
|
@ -1481,10 +1483,13 @@ class HttpInstance:
|
|||
access_models[node_type] = access_model
|
||||
settings = {}
|
||||
for setting in ['enrollment', 'routine']:
|
||||
iq = await XmppPubsub.get_node_item(xmpp_instance, jabber_id, 'xmpp:blasta:settings:0', setting)
|
||||
iq = await XmppPubsub.get_node_item(xmpp_instance, jabber_id, 'xmpp:blasta:configuration:0', setting)
|
||||
if isinstance(iq, slixmpp.stanza.iq.Iq):
|
||||
payload = iq['pubsub']['items']['item']['payload']
|
||||
if payload: settings[setting] = payload.text
|
||||
if payload:
|
||||
xmlns = '{jabber:x:data}'
|
||||
element_value = payload.find('.//' + xmlns + 'field[@var="' + setting + '"]/' + xmlns + 'value')
|
||||
if isinstance(element_value, ET.Element): settings[setting] = element_value.text
|
||||
template_file = 'profile.xhtml'
|
||||
template_dict = {
|
||||
'access_models' : access_models,
|
||||
|
@ -1511,15 +1516,15 @@ class HttpInstance:
|
|||
xmpp_instance = accounts[jabber_id]
|
||||
if routine:
|
||||
message = 'The routine directory has been set to {}'.format(routine)
|
||||
payload = Xml.create_setting_entry(routine)
|
||||
iq = await XmppPubsub.publish_node_item(
|
||||
xmpp_instance, jabber_id, 'xmpp:blasta:settings:0', 'routine', payload)
|
||||
payload = Xml.create_setting_entry(xmpp_instance, 'routine', routine)
|
||||
iq = await XmppPubsub.publish_node_item( # NOTE Consider "configurations" as item ID (see Movim)
|
||||
xmpp_instance, jabber_id, 'xmpp:blasta:configuration:0', 'routine', payload)
|
||||
if enroll:
|
||||
if enroll == '1': message = 'Your database is shared with the Blasta system'
|
||||
else: message = 'Your database is excluded from the Blasta system'
|
||||
payload = Xml.create_setting_entry(enroll)
|
||||
payload = Xml.create_setting_entry(xmpp_instance, 'enroll', enroll)
|
||||
iq = await XmppPubsub.publish_node_item(
|
||||
xmpp_instance, jabber_id, 'xmpp:blasta:settings:0', 'enrollment', payload)
|
||||
xmpp_instance, jabber_id, 'xmpp:blasta:configuration:0', 'enrollment', payload)
|
||||
description = 'Setting has been saved'
|
||||
template_file = 'result.xhtml'
|
||||
template_dict = {
|
||||
|
@ -1663,10 +1668,13 @@ class HttpInstance:
|
|||
if (isinstance(iq, slixmpp.stanza.iq.Iq) and
|
||||
url_hash == iq['pubsub']['items']['item']['id']):
|
||||
return RedirectResponse(url='/url/' + url_hash + '/edit')
|
||||
iq = await XmppPubsub.get_node_item(xmpp_instance, jabber_id, 'xmpp:blasta:settings:0', 'routine')
|
||||
iq = await XmppPubsub.get_node_item(xmpp_instance, jabber_id, 'xmpp:blasta:configuration:0', 'routine')
|
||||
if isinstance(iq, slixmpp.stanza.iq.Iq):
|
||||
payload = iq['pubsub']['items']['item']['payload']
|
||||
routine = payload.text if payload else None
|
||||
if payload:
|
||||
xmlns = '{jabber:x:data}'
|
||||
element_value = payload.find('.//' + xmlns + 'field[@var="routine"]/' + xmlns + 'value')
|
||||
if isinstance(element_value, ET.Element): routine = element_value.text
|
||||
else:
|
||||
routine = None
|
||||
# NOTE Is "message" missing?
|
||||
|
@ -5111,10 +5119,17 @@ class Utilities:
|
|||
|
||||
class Xml:
|
||||
|
||||
def create_setting_entry(value : str):
|
||||
element = ET.Element('value')
|
||||
element.text = value
|
||||
return element
|
||||
def create_setting_entry(xmpp_instance, key : str, value : str):
|
||||
form = xmpp_instance['xep_0004'].make_form('form', 'Settings')
|
||||
form['type'] = 'result'
|
||||
form.add_field(var=key,
|
||||
value=value)
|
||||
return form
|
||||
|
||||
# def create_setting_entry(value : str):
|
||||
# element = ET.Element('value')
|
||||
# element.text = value
|
||||
# return element
|
||||
|
||||
class Configuration:
|
||||
|
||||
|
@ -5222,7 +5237,7 @@ class XmppPubsub:
|
|||
iq = xmpp_instance.Iq(stype='set',
|
||||
sto=jid,
|
||||
sfrom=jid_from)
|
||||
iq['pubsub']['create']['node'] = 'xmpp:blasta:settings:0'
|
||||
iq['pubsub']['create']['node'] = 'xmpp:blasta:configuration:0'
|
||||
form = iq['pubsub']['configure']['form']
|
||||
form['type'] = 'submit'
|
||||
form.addField('pubsub#access_model',
|
||||
|
|
|
@ -16,7 +16,7 @@ class HtmlView:
|
|||
# Open the link using xdg-open
|
||||
subprocess.run(['xdg-open', uri], check=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Failed to open URL: {uri}. Error: {e}")
|
||||
print('Failed to open URL: {}. Error: {}'.format(uri, e))
|
||||
else:
|
||||
# If it is from url_instance, just load it in the webview
|
||||
#webview.load_url(uri)
|
||||
|
|
|
@ -64,14 +64,20 @@
|
|||
|
||||
PubSub bookmarks
|
||||
</h2>
|
||||
<p>» Information of your Jabber ID.</p>
|
||||
<h3>Your Profile</h3>
|
||||
<p>
|
||||
» Information of your Jabber ID.
|
||||
</p>
|
||||
<h3>
|
||||
Your profile
|
||||
</h3>
|
||||
<p>
|
||||
This page provides a general survey of your XMPP account and
|
||||
stored bookmarks.
|
||||
</p>
|
||||
<!--
|
||||
<h4 id="enrollment">Enrollment</h4>
|
||||
<h4 id="enrollment">
|
||||
Enrollment
|
||||
</h4>
|
||||
<p>
|
||||
Blasta does not automatically include your public bookmarks
|
||||
to its database.
|
||||
|
@ -120,7 +126,9 @@
|
|||
therefore.
|
||||
</p>
|
||||
-->
|
||||
<h4 id="export">Export</h4>
|
||||
<h4 id="export">
|
||||
Export
|
||||
</h4>
|
||||
<p>
|
||||
Export bookmarks to a file.
|
||||
</p>
|
||||
|
@ -128,7 +136,9 @@
|
|||
<!-- TODO Add XBEL, XHTML and XML -->
|
||||
<dl>
|
||||
<dt>
|
||||
<strong>Private</strong>
|
||||
<strong>
|
||||
Private
|
||||
</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
<a download="{{jabber_id}}_private.json"
|
||||
|
@ -139,7 +149,9 @@
|
|||
TOML</a>.
|
||||
</dd>
|
||||
<dt>
|
||||
<strong>Public</strong>
|
||||
<strong>
|
||||
Public
|
||||
</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
<a download="{{jabber_id}}_public.json"
|
||||
|
@ -150,7 +162,9 @@
|
|||
TOML</a>.
|
||||
</dd>
|
||||
<dt>
|
||||
<strong>Read</strong>
|
||||
<strong>
|
||||
Read
|
||||
</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
<a download="{{jabber_id}}_read.json"
|
||||
|
@ -162,7 +176,9 @@
|
|||
</dd>
|
||||
</dl>
|
||||
</p>
|
||||
<h4 id="import">Import</h4>
|
||||
<h4 id="import">
|
||||
Import
|
||||
</h4>
|
||||
<p>
|
||||
Import bookmarks from a file, and choose a node to import
|
||||
your bookmarks to.
|
||||
|
@ -175,7 +191,9 @@
|
|||
<tr>
|
||||
<td>
|
||||
<strong>
|
||||
<label for="file">File</label>
|
||||
<label for="file">
|
||||
File
|
||||
</label>
|
||||
</strong>
|
||||
</td>
|
||||
<td>
|
||||
|
@ -189,7 +207,9 @@
|
|||
<tr>
|
||||
<td>
|
||||
<strong>
|
||||
<label for="node">Node</label>
|
||||
<label for="node">
|
||||
Node
|
||||
</label>
|
||||
</strong>
|
||||
</td>
|
||||
<td>
|
||||
|
@ -214,7 +234,9 @@
|
|||
<tr>
|
||||
<td>
|
||||
<strong>
|
||||
<label for="node">Action</label>
|
||||
<label for="node">
|
||||
Action
|
||||
</label>
|
||||
</strong>
|
||||
</td>
|
||||
<td>
|
||||
|
@ -422,7 +444,9 @@ retrieve items only if on a whitelist managed by the node owner.">
|
|||
proceeding.
|
||||
</p>
|
||||
<hr/>
|
||||
<h4 id="termination">Termination</h4>
|
||||
<h4 id="termination">
|
||||
Termination
|
||||
</h4>
|
||||
<p>
|
||||
Due to security concerns, Blasta does not have a built-in
|
||||
mechanism to delete nodes.
|
||||
|
@ -438,7 +462,9 @@ retrieve items only if on a whitelist managed by the node owner.">
|
|||
<a href="https://psi-im.org">Psi</a>, or
|
||||
<a href="https://psi-plus.com">Psi+</a>.
|
||||
</p>
|
||||
<h4>Delete your public bookmarks</h4>
|
||||
<h4>
|
||||
Delete your public bookmarks
|
||||
</h4>
|
||||
<pre>
|
||||
<iq type='set'
|
||||
from='{{jabber_id}}'
|
||||
|
@ -449,7 +475,9 @@ retrieve items only if on a whitelist managed by the node owner.">
|
|||
</pubsub>
|
||||
</iq>
|
||||
</pre>
|
||||
<h4>Delete your private bookmarks</h4>
|
||||
<h4>
|
||||
Delete your private bookmarks
|
||||
</h4>
|
||||
<pre>
|
||||
<iq type='set'
|
||||
from='{{jabber_id}}'
|
||||
|
@ -460,7 +488,9 @@ retrieve items only if on a whitelist managed by the node owner.">
|
|||
</pubsub>
|
||||
</iq>
|
||||
</pre>
|
||||
<h4>Delete your reading list</h4>
|
||||
<h4>
|
||||
Delete your reading list
|
||||
</h4>
|
||||
<pre>
|
||||
<iq type='set'
|
||||
from='{{jabber_id}}'
|
||||
|
|
Loading…
Reference in a new issue