Add a module which will create notifications for all users when the license is at its expiration period, and terminate the process when the license expires.
This commit is contained in:
parent
0683f2657e
commit
0ba4201020
8 changed files with 120 additions and 18 deletions
|
@ -1622,14 +1622,20 @@ def list_trigger_builds(namespace_name, repository_name, trigger_uuid,
|
|||
.where(RepositoryBuildTrigger.uuid == trigger_uuid))
|
||||
|
||||
|
||||
def create_notification(kind, target, metadata={}):
|
||||
kind_ref = NotificationKind.get(name=kind)
|
||||
def create_notification(kind_name, target, metadata={}):
|
||||
kind_ref = NotificationKind.get(name=kind_name)
|
||||
notification = Notification.create(kind=kind_ref, target=target,
|
||||
metadata_json=json.dumps(metadata))
|
||||
return notification
|
||||
|
||||
|
||||
def list_notifications(user, kind=None):
|
||||
def create_unique_notification(kind_name, target, metadata={}):
|
||||
with config.app_config['DB_TRANSACTION_FACTORY'](db):
|
||||
if list_notifications(target, kind_name).count() == 0:
|
||||
create_notification(kind_name, target, metadata)
|
||||
|
||||
|
||||
def list_notifications(user, kind_name=None):
|
||||
Org = User.alias()
|
||||
AdminTeam = Team.alias()
|
||||
AdminTeamMember = TeamMember.alias()
|
||||
|
@ -1647,20 +1653,30 @@ def list_notifications(user, kind=None):
|
|||
.join(AdminTeamMember, JOIN_LEFT_OUTER, on=(AdminTeam.id ==
|
||||
AdminTeamMember.team))
|
||||
.join(AdminUser, JOIN_LEFT_OUTER, on=(AdminTeamMember.user ==
|
||||
AdminUser.id)))
|
||||
AdminUser.id))
|
||||
.where((Notification.target == user) |
|
||||
((AdminUser.id == user) & (TeamRole.name == 'admin')))
|
||||
.order_by(Notification.created)
|
||||
.desc())
|
||||
|
||||
where_clause = ((Notification.target == user) |
|
||||
((AdminUser.id == user) &
|
||||
(TeamRole.name == 'admin')))
|
||||
|
||||
if kind:
|
||||
where_clause = where_clause & (NotificationKind.name == kind)
|
||||
if kind_name:
|
||||
query = (query
|
||||
.switch(Notification)
|
||||
.join(NotificationKind)
|
||||
.where(NotificationKind.name == kind_name))
|
||||
|
||||
return query.where(where_clause).order_by(Notification.created).desc()
|
||||
return query
|
||||
|
||||
|
||||
def delete_notifications_by_kind(target, kind):
|
||||
kind_ref = NotificationKind.get(name=kind)
|
||||
def delete_all_notifications_by_kind(kind_name):
|
||||
kind_ref = NotificationKind.get(name=kind_name)
|
||||
(Notification.delete()
|
||||
.where(Notification.kind == kind_ref)
|
||||
.execute())
|
||||
|
||||
|
||||
def delete_notifications_by_kind(target, kind_name):
|
||||
kind_ref = NotificationKind.get(name=kind_name)
|
||||
Notification.delete().where(Notification.target == target,
|
||||
Notification.kind == kind_ref).execute()
|
||||
|
||||
|
|
Reference in a new issue