Skip to content
Snippets Groups Projects
Commit 1f41927b authored by inso's avatar inso
Browse files

Notification about first time certification

parent 37581eaf
No related branches found
No related tags found
No related merge requests found
......@@ -61,6 +61,19 @@ class Account(QObject):
self._identities_registry = identities_registry
self._current_ref = 0
self.notifications = {'membership_expire_soon':
[
self.tr("Warning : Your membership is expiring soon."),
0
],
'warning_certifications':
[
self.tr("Warning : Your could miss certifications soon."),
0
],
'warning_certifying_first_time': True,
}
@classmethod
def create(cls, name, identities_registry):
"""
......
......@@ -71,18 +71,6 @@ class Application(QObject):
'auto_refresh': False
}
self.notifications = {'membership_expire_soon':
[
self.tr("Warning : Your membership is expiring soon."),
0
],
'warning_certifications':
[
self.tr("Warning : Your could miss certifications soon."),
0
]
}
@classmethod
def startup(cls, argv, qapp, loop):
config.parse_arguments(argv)
......@@ -204,6 +192,7 @@ class Application(QObject):
and stop the coroutines
"""
self.save_cache(self.current_account)
self.save_notifications(self.current_account)
self.current_account.stop_coroutines()
def load(self):
......@@ -261,6 +250,17 @@ class Application(QObject):
account.rollback_transaction(self, co))
community.network.root_nodes_changed.connect(lambda acc=account: self.save(acc))
account_notifications_path = os.path.join(config.parameters['home'],
account_name, '__notifications__')
try:
with open(account_notifications_path, 'r') as json_data:
data = json.load(json_data)
account.notifications = data
except FileNotFoundError:
logging.debug("Could not find notifications file")
pass
def load_cache(self, account):
"""
Load an account cache
......@@ -350,6 +350,18 @@ class Application(QObject):
account_path = os.path.join(config.parameters['home'], account.name)
shutil.rmtree(account_path)
def save_notifications(self, account):
"""
Save an account notifications
:param account: The account object to save
"""
account_path = os.path.join(config.parameters['home'],
account.name)
notifications_path = os.path.join(account_path, '__notifications__')
with open(notifications_path, 'w') as outfile:
json.dump(account.notifications, outfile, indent=4, sort_keys=True)
def save_registries(self):
"""
Save the registries
......
......@@ -6,7 +6,7 @@ Created on 24 dec. 2014
import asyncio
import logging
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QApplication
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QApplication, QMessageBox
from PyQt5.QtCore import Qt
......@@ -38,17 +38,27 @@ class CertificationDialog(QDialog, Ui_CertificationDialog):
for contact_name in sorted([c['name'] for c in certifier.contacts], key=str.lower):
self.combo_contact.addItem(contact_name)
if len(certifier.contacts) == 0:
self.radio_pubkey.setChecked(True)
self.radio_contact.setEnabled(False)
@classmethod
async def certify_identity(cls, app, account, password_asker, community, identity):
"""
Certify and identity
:param sakia.core.Application app: the application
:param sakia.core.Account account: the account certifying the identity
:param sakia.gui.password_asker.PasswordAsker password_asker: the password asker
:param sakia.core.Community community: the community
:param sakia.core.registry.Identity identity: the identity certified
:return:
"""
dialog = cls(app, account, password_asker)
dialog.combo_community.setCurrentText(community.name)
dialog.edit_pubkey.setText(identity.pubkey)
dialog.radio_pubkey.setChecked(True)
return (await dialog.async_exec())
return await dialog.async_exec()
@asyncify
async def accept(self):
......@@ -113,6 +123,19 @@ class CertificationDialog(QDialog, Ui_CertificationDialog):
self.button_box.button(QDialogButtonBox.Ok).setEnabled(False)
self.button_box.button(QDialogButtonBox.Ok).setText(self.tr("Not a member"))
def showEvent(self, event):
super().showEvent(event)
self.first_certification_check()
def first_certification_check(self):
if self.account.notifications['warning_certifying_first_time']:
self.account.notifications['warning_certifying_first_time'] = False
QMessageBox.warning(self, "Certifying individuals", """Please follow the following guidelines :
1.) Don't certify an account if you believe the issuers identity might be faked.
2.) Don't certify an account if you believe the issuer already has another certified account.
3.) Don't certify an account if you believe the issuer purposely or carelessly violates rule 1 or 2 (the issuer certifies faked or double accounts
""")
def recipient_mode_changed(self, pubkey_toggled):
self.edit_pubkey.setEnabled(pubkey_toggled)
self.combo_contact.setEnabled(not pubkey_toggled)
......
......@@ -190,10 +190,10 @@ class CommunityWidget(QWidget, Ui_CommunityWidget):
self.status_info.append('membership_expire_soon')
if self.app.preferences['notifications'] and\
self.app.notifications['membership_expire_soon'][1]+24*3600 < time.time():
self.account.notifications['membership_expire_soon'][1]+24*3600 < time.time():
toast.display(self.tr("Membership expiration"),
self.tr("<b>Warning : Membership expiration in {0} days</b>").format(days))
self.app.notifications['membership_expire_soon'][1] = time.time()
self.account.notifications['membership_expire_soon'][1] = time.time()
certifiers_of = await person.unique_valid_certifiers_of(self.app.identities_registry,
self.community)
......@@ -201,12 +201,12 @@ class CommunityWidget(QWidget, Ui_CommunityWidget):
if 'warning_certifications' not in self.status_info:
self.status_info.append('warning_certifications')
if self.app.preferences['notifications'] and\
self.app.notifications['warning_certifications'][1]+24*3600 < time.time():
self.account.notifications['warning_certifications'][1]+24*3600 < time.time():
toast.display(self.tr("Certifications number"),
self.tr("<b>Warning : You are certified by only {0} persons, need {1}</b>")
.format(len(certifiers_of),
parameters['sigQty']))
self.app.notifications['warning_certifications'][1] = time.time()
self.account.notifications['warning_certifications'][1] = time.time()
except MembershipNotFoundError as e:
pass
......
......@@ -3,7 +3,6 @@ from PyQt5.QtCore import Qt, QPointF, QTimeLine, QTimer
from PyQt5.QtGui import QTransform, QColor, QPen, QBrush, QRadialGradient
from ....core.graph.constants import NodeStatus
from .base_node import BaseNode
import logging
import math
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment