diff --git a/changelog/unreleased/siteacc-site-settings.md b/changelog/unreleased/siteacc-site-settings.md
new file mode 100644
index 0000000000..8a3a6c2468
--- /dev/null
+++ b/changelog/unreleased/siteacc-site-settings.md
@@ -0,0 +1,5 @@
+Enhancement: Site accounts site-global settings
+
+This PR extends the site accounts service by adding site-global settings. These are used to store test user credentials that are in return used by our BBE port to perform CS3API-specific health checks.
+
+https://github.com/cs3org/reva/pull/2738
diff --git a/docs/content/en/docs/config/http/services/siteacc/_index.md b/docs/content/en/docs/config/http/services/siteacc/_index.md
index bf318f18fe..a556106c19 100644
--- a/docs/content/en/docs/config/http/services/siteacc/_index.md
+++ b/docs/content/en/docs/config/http/services/siteacc/_index.md
@@ -19,6 +19,15 @@ prefix = "/siteacc"
{{< /highlight >}}
{{% /dir %}}
+## Security settings
+{{% dir name="creds_passphrase" type="string" default="" %}}
+The passphrase to use when encoding stored credentials. Should be exactly 32 characters long.
+{{< highlight toml >}}
+[http.services.siteacc.security]
+creds_passphrase = "supersecretpasswordthatyouknow!"
+{{< /highlight >}}
+{{% /dir %}}
+
## GOCDB settings
{{% dir name="url" type="string" default="" %}}
The external URL of the central GOCDB instance.
@@ -111,12 +120,20 @@ driver = "file"
{{< /highlight >}}
{{% /dir %}}
-### Storage settings - File driver
-{{% dir name="file" type="string" default="" %}}
-The file location.
+### Storage settings - File drivers
+{{% dir name="sites_file" type="string" default="" %}}
+The sites file location.
+{{< highlight toml >}}
+[http.services.siteacc.storage.file]
+sites_file = "/var/reva/sites.json"
+{{< /highlight >}}
+{{% /dir %}}
+
+{{% dir name="accounts_file" type="string" default="" %}}
+The accounts file location.
{{< highlight toml >}}
[http.services.siteacc.storage.file]
-file = "/var/reva/accounts.json"
+accounts_file = "/var/reva/accounts.json"
{{< /highlight >}}
{{% /dir %}}
diff --git a/examples/siteacc/siteacc.toml b/examples/siteacc/siteacc.toml
index cf081e748e..68a0c52e4f 100644
--- a/examples/siteacc/siteacc.toml
+++ b/examples/siteacc/siteacc.toml
@@ -1,6 +1,11 @@
[http]
address = "0.0.0.0:9600"
+# Security settings
+[http.services.siteacc.security]
+creds_passphrase = "superdupersecret"
+
+# Connection to the GOCDB
[http.services.siteacc.gocdb]
url = "https://sciencemesh-test.uni-muenster.de/gocdb/"
write_url = "https://sciencemesh-test.uni-muenster.de/gocdbpi/"
@@ -10,7 +15,8 @@ apikey = "verysecret"
[http.services.siteacc.storage]
driver = "file"
[http.services.siteacc.storage.file]
-file = "/var/revad/accounts.json"
+sites_file = "/var/revad/sites.json"
+accounts_file = "/var/revad/accounts.json"
# Email related settings
[http.services.siteacc.email]
diff --git a/pkg/siteacc/account/manage/template.go b/pkg/siteacc/account/manage/template.go
index 0d73b00c9d..5dc597dca7 100644
--- a/pkg/siteacc/account/manage/template.go
+++ b/pkg/siteacc/account/manage/template.go
@@ -19,7 +19,7 @@
package manage
const tplJavaScript = `
-function handleSettings() {
+function handleAccountSettings() {
setState(STATE_STATUS, "Redirecting to the account settings...");
window.location.replace("{{getServerAddress}}/account/?path=settings");
}
@@ -29,9 +29,14 @@ function handleEditAccount() {
window.location.replace("{{getServerAddress}}/account/?path=edit");
}
-function handleRequestAccess() {
+function handleSiteSettings() {
+ setState(STATE_STATUS, "Redirecting to the site settings...");
+ window.location.replace("{{getServerAddress}}/account/?path=site");
+}
+
+function handleRequestAccess(scope) {
setState(STATE_STATUS, "Redirecting to the contact form...");
- window.location.replace("{{getServerAddress}}/account/?path=contact&subject=" + encodeURIComponent("Request GOCDB access"));
+ window.location.replace("{{getServerAddress}}/account/?path=contact&subject=" + encodeURIComponent("Request " + scope + " access"));
}
function handleLogout() {
@@ -58,6 +63,9 @@ const tplStyleSheet = `
html * {
font-family: arial !important;
}
+button {
+ min-width: 170px;
+}
`
const tplBody = `
@@ -81,24 +89,44 @@ const tplBody = `
-
Quick links:
-
+
+
+
Notes:
+
+ - The Site access allows you to access and modify the global configuration of your site.
+ - The GOCDB access allows you to log into the central database where all site metadata is stored.
+
+
+
`
diff --git a/pkg/siteacc/account/panel.go b/pkg/siteacc/account/panel.go
index 040ed8ddc8..a3c29ef55e 100644
--- a/pkg/siteacc/account/panel.go
+++ b/pkg/siteacc/account/panel.go
@@ -29,6 +29,7 @@ import (
"github.com/cs3org/reva/pkg/siteacc/account/manage"
"github.com/cs3org/reva/pkg/siteacc/account/registration"
"github.com/cs3org/reva/pkg/siteacc/account/settings"
+ "github.com/cs3org/reva/pkg/siteacc/account/site"
"github.com/cs3org/reva/pkg/siteacc/config"
"github.com/cs3org/reva/pkg/siteacc/data"
"github.com/cs3org/reva/pkg/siteacc/html"
@@ -50,6 +51,7 @@ const (
templateManage = "manage"
templateSettings = "settings"
templateEdit = "edit"
+ templateSite = "site"
templateContact = "contact"
templateRegistration = "register"
)
@@ -84,6 +86,10 @@ func (panel *Panel) initialize(conf *config.Configuration, log *zerolog.Logger)
return errors.Wrap(err, "unable to create the account editing template")
}
+ if err := panel.htmlPanel.AddTemplate(templateSite, &site.PanelTemplate{}); err != nil {
+ return errors.Wrap(err, "unable to create the site template")
+ }
+
if err := panel.htmlPanel.AddTemplate(templateContact, &contact.PanelTemplate{}); err != nil {
return errors.Wrap(err, "unable to create the contact template")
}
@@ -97,7 +103,7 @@ func (panel *Panel) initialize(conf *config.Configuration, log *zerolog.Logger)
// GetActiveTemplate returns the name of the active template.
func (panel *Panel) GetActiveTemplate(session *html.Session, path string) string {
- validPaths := []string{templateLogin, templateManage, templateSettings, templateEdit, templateContact, templateRegistration}
+ validPaths := []string{templateLogin, templateManage, templateSettings, templateEdit, templateSite, templateContact, templateRegistration}
template := templateLogin
// Only allow valid template paths; redirect to the login page otherwise
@@ -113,18 +119,28 @@ func (panel *Panel) GetActiveTemplate(session *html.Session, path string) string
// PreExecute is called before the actual template is being executed.
func (panel *Panel) PreExecute(session *html.Session, path string, w http.ResponseWriter, r *http.Request) (html.ExecutionResult, error) {
- protectedPaths := []string{templateManage, templateSettings, templateEdit, templateContact}
+ protectedPaths := []string{templateManage, templateSettings, templateEdit, templateSite, templateContact}
+
+ if user := session.LoggedInUser(); user != nil {
+ switch path {
+ case templateSite:
+ // If the logged in user doesn't have site access, redirect him back to the main account page
+ if !user.Account.Data.SiteAccess {
+ return panel.redirect(templateManage, w, r), nil
+ }
- if session.LoggedInUser == nil {
+ case templateLogin:
+ case templateRegistration:
+ // If a user is logged in and tries to login or register again, redirect to the main account page
+ return panel.redirect(templateManage, w, r), nil
+ }
+ } else {
// If no user is logged in, redirect protected paths to the login page
for _, protected := range protectedPaths {
if protected == path {
return panel.redirect(templateLogin, w, r), nil
}
}
- } else if path == templateLogin || path == templateRegistration {
- // If a user is logged in and tries to login or register again, redirect to the main account page
- return panel.redirect(templateManage, w, r), nil
}
return html.ContinueExecution, nil
@@ -144,6 +160,7 @@ func (panel *Panel) Execute(w http.ResponseWriter, r *http.Request, session *htm
}
type TemplateData struct {
+ Site *data.Site
Account *data.Account
Params map[string]string
@@ -151,12 +168,18 @@ func (panel *Panel) Execute(w http.ResponseWriter, r *http.Request, session *htm
Sites []data.SiteInformation
}
- return TemplateData{
- Account: session.LoggedInUser,
+ tplData := TemplateData{
+ Site: nil,
+ Account: nil,
Params: flatValues,
Titles: []string{"Mr", "Mrs", "Ms", "Prof", "Dr"},
Sites: availSites,
}
+ if user := session.LoggedInUser(); user != nil {
+ tplData.Site = panel.cloneUserSite(user.Site)
+ tplData.Account = user.Account
+ }
+ return tplData
}
return panel.htmlPanel.Execute(w, r, session, dataProvider)
}
@@ -179,11 +202,22 @@ func (panel *Panel) redirect(path string, w http.ResponseWriter, r *http.Request
return html.AbortExecution
}
+func (panel *Panel) cloneUserSite(site *data.Site) *data.Site {
+ // Clone the user's site and decrypt the credentials for the panel
+ siteClone := site.Clone(true)
+ id, secret, err := site.Config.TestClientCredentials.Get(panel.conf.Security.CredentialsPassphrase)
+ if err == nil {
+ siteClone.Config.TestClientCredentials.ID = id
+ siteClone.Config.TestClientCredentials.Secret = secret
+ }
+ return siteClone
+}
+
// NewPanel creates a new account panel.
func NewPanel(conf *config.Configuration, log *zerolog.Logger) (*Panel, error) {
form := &Panel{}
if err := form.initialize(conf, log); err != nil {
- return nil, errors.Wrapf(err, "unable to initialize the account panel")
+ return nil, errors.Wrap(err, "unable to initialize the account panel")
}
return form, nil
}
diff --git a/pkg/siteacc/account/settings/template.go b/pkg/siteacc/account/settings/template.go
index 182dc73c72..98fec5d61b 100644
--- a/pkg/siteacc/account/settings/template.go
+++ b/pkg/siteacc/account/settings/template.go
@@ -70,7 +70,7 @@ const tplBody = `