Skip to content

Commit

Permalink
[web] add more notification management
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmann committed Mar 22, 2024
1 parent e70a6a3 commit dfe39f1
Show file tree
Hide file tree
Showing 15 changed files with 547 additions and 67 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/jmoiron/sqlx v1.3.5
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
github.com/lestrrat-go/jwx v1.2.28
github.com/oidc-mytoken/api v0.11.2-0.20240227100746-bf79b3e24f65
github.com/oidc-mytoken/api v0.11.2-0.20240322111856-056e17719fbc
github.com/oidc-mytoken/lib v0.7.1
github.com/oidc-mytoken/utils v0.1.3-0.20230731143919-ea5b78243e5d
github.com/patrickmn/go-cache v2.1.0+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/oidc-mytoken/api v0.9.1/go.mod h1:DBIlUbaIgGlf607VZx8zFC97VR3WNN0kaMVO1AqyTdE=
github.com/oidc-mytoken/api v0.11.1/go.mod h1:bd7obYvztiIQW1PoRVBTOg8/clWlauNGwcZEu5mRbwg=
github.com/oidc-mytoken/api v0.11.2-0.20240227100746-bf79b3e24f65 h1:do7qVNvNccmTvqPjO7iSrjrofd71/l+sNyi/ZChodi8=
github.com/oidc-mytoken/api v0.11.2-0.20240227100746-bf79b3e24f65/go.mod h1:E4nGP5D9575NtqQohVaC41rxRjoXvwtJi72aoIO2uUk=
github.com/oidc-mytoken/api v0.11.2-0.20240322111856-056e17719fbc h1:4qXooWWgFrmu6FXHXohAoB+4ZQyBExUqUShTvlnY9b8=
github.com/oidc-mytoken/api v0.11.2-0.20240322111856-056e17719fbc/go.mod h1:E4nGP5D9575NtqQohVaC41rxRjoXvwtJi72aoIO2uUk=
github.com/oidc-mytoken/lib v0.7.1 h1:inqnng/iVU42TU8Cuac7wP8I+JraTYmWMKSXdZvShfU=
github.com/oidc-mytoken/lib v0.7.1/go.mod h1:LLDCpHCFzyodYLWSf69FDI4cvql/8B2sdKhVjmOBPgI=
github.com/oidc-mytoken/utils v0.1.3-0.20230731143919-ea5b78243e5d h1:6FH7MuDNSDWxhSzdzim7qeM4XASDb8TL4nytZAZLpBc=
Expand Down
4 changes: 4 additions & 0 deletions internal/db/dbmigrate/scripts/v0.10.0.pre.sql
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,7 @@ INSERT IGNORE INTO Events (event)
VALUES ('tokeninfo_notifications');
INSERT IGNORE INTO Events (event)
VALUES ('tokeninfo_notifications_other_token');
INSERT IGNORE INTO Events (event)
VALUES ('notification_created');
INSERT IGNORE INTO Events (event)
VALUES ('notification_created_other');
34 changes: 33 additions & 1 deletion internal/endpoints/notification/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,41 @@ func handleNewMailNotification(
emailInfo.Mail, "New Mytoken Notification Subscription",
emailInfo.PreferHTMLMail, "notification-welcome", welcomeData,
)
tokenUpdate, err := rotation.RotateMytokenAfterOtherForResponse(
rlog, tx, req.Mytoken.JWT, mt, *ctxutils.ClientMetaData(ctx), req.Mytoken.OriginalTokenType,
)
if err != nil {
res = model.ErrorToInternalServerErrorResponse(err)
return err
}
resData := pkg.NotificationsCreateResponse{
NotificationsCreateResponse: api.NotificationsCreateResponse{
ManagementCode: managementCode,
},
}
res = &model.Response{
Status: fiber.StatusCreated,
Response: managementCode, //TODO
Response: resData,
}
if tokenUpdate != nil {
resData.TokenUpdate = tokenUpdate
res.Cookies = []*fiber.Cookie{cookies.MytokenCookie(tokenUpdate.Mytoken)}
res.Response = resData
}

e := api.EventNotificationCreated
if req.MomID.HashValid() {
e = api.EventNotificationCreatedOther
}
if err = eventService.LogEvent(
rlog, tx, pkg3.MTEvent{
Event: e,
MTID: mt.ID,
ClientMetaData: *ctxutils.ClientMetaData(ctx),
},
); err != nil {
res = model.ErrorToInternalServerErrorResponse(err)
return err
}
return nil
},
Expand Down
6 changes: 6 additions & 0 deletions internal/endpoints/notification/pkg/notificationrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ type NotificationRemoveTokenRequest struct {
Mytoken universalmytoken.UniversalMytoken `json:"mytoken" xml:"mytoken" form:"mytoken"`
MomID mtid.MOMID `json:"mom_id" xml:"mom_id" form:"mom_id"`
}

// NotificationsCreateResponse is a type holding the response to a notification creation request
type NotificationsCreateResponse struct {
api.NotificationsCreateResponse
TokenUpdate *pkg.MytokenResponse `json:"token_update,omitempty"`
}
6 changes: 6 additions & 0 deletions internal/server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ func homeBindingData() map[string]interface{} {
"modify": map[string]any{
templating.MustacheKeyPrefix: "notifications-modify-",
},
templating.MustacheSubNotificationListing: map[string]any{
templating.MustacheKeyPrefix: "notification-listing-",
templating.MustacheSubNewNotificationModal: map[string]any{
templating.MustacheKeyPrefix: "new-notification-modal-",
},
},
},
"providers": providers,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div class="modal fade" id="delete-notification-modal" tabindex="-1" role="dialog"
aria-labelledby="delete-notifications-modal-title"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal" role="document">
<div class="modal-content bg-my_grey">
<div class="modal-header">
<h5 class="modal-title" id="delete-notifications-modal-title">Delete Notification</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>
<span class="d-none"
id="last-token-hint">This is the last token subscribed to this notification.</span>
You are going to delete this notification. Are you sure?
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-danger" data-dismiss="modal"
onclick="deleteNotification()">Delete Notification
</button>
</div>
</div>
</div>
</div>
58 changes: 55 additions & 3 deletions internal/server/web/partials/notifications/home-pane.mustache
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
{{#notifications}}
{{#notification-listing}}
<h4>Notifications</h4>
<p>
Settings related to notifications can be changed under <a href="/settings#notifications">Settings</a>.
Settings related to email notifications can be changed under <a href="/settings#notifications">Settings</a>.
</p>

<button class="btn btn-success" onclick="newNotificationModal()"><i class="fas fa-plus"></i> Create
new Notification
</button>
{{>notifications/new-notification-modal}}
{{>notifications/delete-notification-modal}}

<button class="btn btn-reload" id="notifications-reload" data-toggle="tooltip" data-placement="bottom"
title="Reload data">
<i class="fas fa-sync"></i>
Expand All @@ -14,5 +21,50 @@
</button>
<p class="card-text" id="notifications-msg"></p>

{{>notifications/modify-container}}
{{/notifications}}

<div class="d-none" id="notifications-modify">
<input id="management-code" type="hidden">

<div class="alert border">
<h5>Subscribed Notification Classes</h5>
<ul class="list-group bg-my_grey list-group-striped">
{{#notification-classes}}
{{> capabilities/part}}
{{/notification-classes}}
</ul>
<button role="button" class="btn btn-primary mt-2" id="btn-save-notification-classes"><i class="fas
fa-save"></i>
</button>
</div>

<div class="alert border">
<div id="subscribed-tokens-details">
<h5>Subscribed Tokens</h5>
<table class="table table-hover table-grey">
<thead>
<tr>
<th style="min-width: 35%;">Token Name</th>
<th>Created</th>
<th>Created from IP</th>
<th>Expires</th>
<th></th>
</tr>
</thead>
<tbody id="notifications-tokens-table">
</tbody>
</table>
<button class="btn btn-success" id="btn-add-token-to-notification"><i class="fa fa-plus-circle"></i>
Add
token
</button>
</div>
<div id="subscribed-tokens-details-user-wide" class="d-none">
<h5>User Wide Notification</h5>
<p>This notification is user-wide and applies to all mytokens.</p>
</div>
</div>

</div>

{{/notification-listing}}
{{/notifications}}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{{#new-notification-modal}}
<div class="modal fade" id="new-notification-modal" tabindex="-1" role="dialog"
aria-labelledby="new-notifications-modal-title"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
<div class="modal-content bg-my_grey">
<div class="modal-header">
<h5 class="modal-title" id="new-notifications-modal-title">
<span class="new-notification-content">New Notification</span>
<span class="only-add-tokens-content">Add Token to Notification</span>
</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="new-notification-content">
<div class="alert border">
<h5>Select Notification Classes</h5>
<ul class="list-group bg-my_grey list-group-striped">
{{#notification-classes}}
{{> capabilities/part}}
{{/notification-classes}}
</ul>
</div>
<div>
<h5>Tokens</h5>
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input"
id="new-notification-user-wide-input">
<label class="custom-control-label" for="new-notification-user-wide-input">User
Wide</label>
</div>
<small class="form-text text-muted mb-2">User wide notifications apply to all your
mytokens.</small>
</div>
<div class="row">
<button class="btn-success btn mx-3 new-notification-save-btn user-wide-toggle-effected d-none col">
<i class="sticky-center mx-auto fas fa-plus"></i> Create User-Wide Notification
</button>
</div>
</div>

<div class="only-add-tokens-content">
<p>
Select tokens to add to this notification.
</p>
</div>

<div class="row mx-1 user-wide-toggle-effected" id="tokens-notifications-select-content">
<button class="btn-success btn col mr-2 d-inline-flex align-items-start new-notification-save-btn"
style="max-width:5%;"
data-toggle="tooltip" data-placement="top" data-original-title="Save">
<i class="sticky-center mx-auto fas fa-save"></i></button>
<table class="col table table-hover table-grey">
<thead>
<tr>
<th></th>
<th style="min-width: 35%;">Token Name</th>
<th>Created</th>
<th>Created from IP</th>
<th>Expires</th>
<th></th>
</tr>
</thead>
<tbody id="notifications-all-tokens-to-subscribe-table">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
{{/new-notification-modal}}
5 changes: 5 additions & 0 deletions internal/server/web/static/css/mytoken.css
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,9 @@ span.user-agent i + i {

.fontawesome {
font-family: 'FontAwesome', Lato, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
}

.sticky-center {
position: sticky;
top: 50%;
}
Loading

0 comments on commit dfe39f1

Please sign in to comment.