- Add data classes for notifications
- Add basic API for notifications - Change the password required to be a notification
This commit is contained in:
parent
e650da5278
commit
368a8da7db
7 changed files with 80 additions and 6 deletions
|
@ -93,6 +93,12 @@ def create_user(username, password, email):
|
|||
|
||||
new_user = User.create(username=username, password_hash=pw_hash,
|
||||
email=email)
|
||||
|
||||
# If the password is None, then add a notification for the user to change
|
||||
# their password ASAP.
|
||||
if not pw_hash:
|
||||
create_notification('password_required', new_user)
|
||||
|
||||
return new_user
|
||||
except Exception as ex:
|
||||
raise DataModelException(ex.message)
|
||||
|
@ -662,6 +668,9 @@ def change_password(user, new_password):
|
|||
user.password_hash = pw_hash
|
||||
user.save()
|
||||
|
||||
# Remove any password required notifications for the user.
|
||||
delete_notifications_by_kind(user, 'password_required')
|
||||
|
||||
|
||||
def change_invoice_email(user, invoice_email):
|
||||
user.invoice_email = invoice_email
|
||||
|
@ -1535,3 +1544,26 @@ def list_trigger_builds(namespace_name, repository_name, trigger_uuid,
|
|||
limit):
|
||||
return (list_repository_builds(namespace_name, repository_name, limit)
|
||||
.where(RepositoryBuildTrigger.uuid == trigger_uuid))
|
||||
|
||||
|
||||
def create_notification(kind, user, metadata={}):
|
||||
kind_ref = NotificationKind.get(name=kind)
|
||||
notification = Notification.create(kind=kind_ref, notification_user=user,
|
||||
metadata_json=json.dumps(metadata))
|
||||
return notification
|
||||
|
||||
|
||||
def list_notifications(user, kind=None):
|
||||
query = (Notification.select()
|
||||
.join(User)
|
||||
.where(Notification.notification_user == user))
|
||||
|
||||
if kind:
|
||||
query = query.join(NotificationKind).where(NotificationKind.name == kind)
|
||||
|
||||
return query.order_by(Notification.created).desc()
|
||||
|
||||
|
||||
def delete_notifications_by_kind(user, kind):
|
||||
kind_ref = NotificationKind.get(name=kind)
|
||||
Notification.delete().where(Notification.user == user, Notification.kind == kind_ref).execute()
|
||||
|
|
Reference in a new issue