Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site accounts improvements #2549

Merged
merged 2 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog/unreleased/siteacc-upd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: Site accounts improvements

This PR improves the site accounts:
- Removed/hid API key stuff
- Added quick links to the main panel
- Made alert notifications mandatory

https://github.com/cs3org/reva/pull/2549
25 changes: 9 additions & 16 deletions pkg/siteacc/account/manage/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ function handleRequestAccess() {
window.location.replace("{{getServerAddress}}/account/?path=contact&subject=" + encodeURIComponent("Request GOCDB access"));
}

function handleRequestKey() {
setState(STATE_STATUS, "Redirecting to the contact form...");
window.location.replace("{{getServerAddress}}/account/?path=contact&subject=" + encodeURIComponent("Request API key"));
}

function handleLogout() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "{{getServerAddress}}/logout");
Expand All @@ -63,19 +58,12 @@ const tplStyleSheet = `
html * {
font-family: arial !important;
}

.apikey {
font-family: monospace !important;
background: antiquewhite;
border: 1px solid black;
padding: 2px;
}
`

const tplBody = `
<div>
<p><strong>Hello {{.Account.FirstName}} {{.Account.LastName}},</strong></p>
<p>On this page, you can manage your ScienceMesh user account. This includes editing your personal information, requesting an API key or access to the GOCDB and more.</p>
<p>On this page, you can manage your ScienceMesh user account. This includes editing your personal information, requesting access to the GOCDB and more.</p>
</div>
<div>&nbsp;</div>
<div>
Expand All @@ -92,8 +80,7 @@ const tplBody = `
</div>
<div>
<strong>Account data:</strong>
<ul style="margin-top: 0em;">
<li {{if .Account.Data.APIKey}}style="margin-bottom: 0.2em;"{{end}}>API Key: <em>{{if .Account.Data.APIKey}}<span class="apikey">{{.Account.Data.APIKey}}</span>{{else}}(no key assigned yet){{end}}</em></li>
<ul style="margin-top: 0em;">
<li>GOCDB access: <em>{{if .Account.Data.GOCDBAccess}}Granted{{else}}Not granted{{end}}</em></li>
</ul>
</div>
Expand All @@ -102,10 +89,16 @@ const tplBody = `
<button type="button" onClick="handleSettings();">Settings</button>
<button type="button" onClick="handleEditAccount();">Edit account</button>
<span style="width: 25px;">&nbsp;</span>
<button type="button" onClick="handleRequestKey();" {{if .Account.Data.APIKey}}disabled{{end}}>Request API Key</button>
<button type="button" onClick="handleRequestAccess();" {{if .Account.Data.GOCDBAccess}}disabled{{end}}>Request GOCDB access</button>

<button type="button" onClick="handleLogout();" style="float: right;">Logout</button>
</form>
</div>
<div>
<p>Quick links:</p>
<ul>
<li><a href="https://gocdb.sciencemesh.uni-muenster.de" target="_blank">Central Database (GOCDB)</a></li>
<li><a href="https://developer.sciencemesh.io/docs/technical-documentation/central-database/" target="_blank">Central Database documentation</a></li>
</ul>
</div>
`
4 changes: 2 additions & 2 deletions pkg/siteacc/account/settings/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ const tplBody = `
</div>

<div style="grid-row: 2; grid-column: 1 / span 2;">
<input type="checkbox" id="rcvAlerts" name="rcvAlerts" value="on" {{if .Account.Settings.ReceiveAlerts}}checked{{end}}/>
<label for="rcvAlerts" style="font-weight: normal;">Receive email notifications about site alerts</label>
<input type="checkbox" id="rcvAlerts" name="rcvAlerts" value="on" checked disabled/>
<label for="rcvAlerts" style="font-weight: normal;">Receive email notifications about site alerts <em>(mandatory; always on)</em></label>
</div>

<div style="grid-row: 3; grid-column: 2; text-align: right;">
Expand Down
8 changes: 8 additions & 0 deletions pkg/siteacc/admin/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,34 +68,42 @@ const tplBody = `
</div>
</p>
<p>
<!--
<strong>API Key:</strong> {{if .Data.APIKey}}{{.Data.APIKey}}{{else}}<em>Not assigned</em>{{end}}
<br>
<strong>Site ID:</strong> {{.GetSiteID}}
<br><br>
<strong>Authorized:</strong> <em>{{if .Data.Authorized}}Yes{{else}}No{{end}}</em>
<br>
-->
<strong>GOCDB access:</strong> <em>{{if .Data.GOCDBAccess}}Granted{{else}}Not granted{{end}}</em>
</p>
<p>
<form method="POST" style="width: 100%;">
<!--
<button type="button" onClick="handleAction('assign-api-key', '{{.Email}}');" {{if .Data.APIKey}}disabled{{end}}>Default API Key</button>
<button type="button" onClick="handleAction('assign-api-key?isScienceMesh', '{{.Email}}');" {{if .Data.APIKey}}disabled{{end}}>ScienceMesh API Key</button>
<br><br>
-->

{{if .Data.GOCDBAccess}}
<button type="button" onClick="handleAction('grant-gocdb-access?status=false', '{{.Email}}');">Revoke GOCDB access</button>
{{else}}
<button type="button" onClick="handleAction('grant-gocdb-access?status=true', '{{.Email}}');">Grant GOCDB access</button>
{{end}}

<!--
{{if .Data.Authorized}}
<button type="button" onClick="handleAction('authorize?status=false', '{{.Email}}');" {{if not .Data.APIKey}}disabled{{end}}>Unauthorize</button>
{{else}}
<button type="button" onClick="handleAction('authorize?status=true', '{{.Email}}');" {{if not .Data.APIKey}}disabled{{end}}>Authorize</button>
{{end}}
-->

<!--
<span style="width: 25px;">&nbsp;</span>
<button type="button" onClick="handleAction('unregister-site', '{{.Email}}');" {{if not .Data.APIKey}}disabled{{end}}>Unregister site</button>
-->

<span style="width: 25px;">&nbsp;</span>
<button type="button" onClick="handleAction('remove', '{{.Email}}');" style="float: right;">Remove</button>
Expand Down
2 changes: 1 addition & 1 deletion pkg/siteacc/alerting/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (dispatcher *Dispatcher) DispatchAlerts(alerts *template.Data, accounts dat

// Dispatch the alert to all accounts configured to receive it
for _, account := range accounts {
if strings.EqualFold(account.Site, siteID) && account.Settings.ReceiveAlerts {
if strings.EqualFold(account.Site, siteID) /* && account.Settings.ReceiveAlerts */ { // TODO: Uncomment if alert notifications aren't mandatory anymore
if err := dispatcher.dispatchAlert(alert, account); err != nil {
// Log errors only
dispatcher.log.Err(err).Str("id", alert.Fingerprint).Str("recipient", account.Email).Msg("unable to dispatch alert to user")
Expand Down
2 changes: 1 addition & 1 deletion pkg/siteacc/data/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func NewAccount(email string, title, firstName, lastName string, site, role stri
Authorized: false,
},
Settings: AccountSettings{
ReceiveAlerts: false,
ReceiveAlerts: true,
},
}

Expand Down