From 5b491bea2a19f673a91171a376568b7e3b0478b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Thu, 1 Sep 2022 10:46:08 +0200 Subject: [PATCH 01/11] New admin panel look&feel --- pkg/siteacc/admin/accounts/accounts.go | 51 ++++++++++++++++++ pkg/siteacc/admin/{ => accounts}/template.go | 20 +++++-- pkg/siteacc/admin/manage/manage.go | 51 ++++++++++++++++++ pkg/siteacc/admin/manage/template.go | 55 ++++++++++++++++++++ pkg/siteacc/admin/panel.go | 52 ++++++++---------- pkg/siteacc/siteacc.go | 2 +- 6 files changed, 195 insertions(+), 36 deletions(-) create mode 100644 pkg/siteacc/admin/accounts/accounts.go rename pkg/siteacc/admin/{ => accounts}/template.go (90%) create mode 100644 pkg/siteacc/admin/manage/manage.go create mode 100644 pkg/siteacc/admin/manage/template.go diff --git a/pkg/siteacc/admin/accounts/accounts.go b/pkg/siteacc/admin/accounts/accounts.go new file mode 100644 index 0000000000..30396e6fa2 --- /dev/null +++ b/pkg/siteacc/admin/accounts/accounts.go @@ -0,0 +1,51 @@ +// Copyright 2018-2020 CERN +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// In applying this license, CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +package accounts + +import "github.com/cs3org/reva/pkg/siteacc/html" + +// PanelTemplate is the content provider for the contact form. +type PanelTemplate struct { + html.ContentProvider +} + +// GetTitle returns the title of the panel. +func (template *PanelTemplate) GetTitle() string { + return "ScienceMesh Site Administrator Accounts" +} + +// GetCaption returns the caption which is displayed on the panel. +func (template *PanelTemplate) GetCaption() string { + return "ScienceMesh Site Administrator Accounts" +} + +// GetContentJavaScript delivers additional JavaScript code. +func (template *PanelTemplate) GetContentJavaScript() string { + return tplJavaScript +} + +// GetContentStyleSheet delivers additional stylesheet code. +func (template *PanelTemplate) GetContentStyleSheet() string { + return tplStyleSheet +} + +// GetContentBody delivers the actual body content. +func (template *PanelTemplate) GetContentBody() string { + return tplBody +} diff --git a/pkg/siteacc/admin/template.go b/pkg/siteacc/admin/accounts/template.go similarity index 90% rename from pkg/siteacc/admin/template.go rename to pkg/siteacc/admin/accounts/template.go index c9aa4a831c..1ff1807291 100644 --- a/pkg/siteacc/admin/template.go +++ b/pkg/siteacc/admin/accounts/template.go @@ -16,7 +16,7 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -package admin +package accounts const tplJavaScript = ` function handleAction(action, email) { @@ -45,13 +45,20 @@ function handleAction(action, email) { const tplStyleSheet = ` html * { - font-family: monospace !important; + font-family: arial !important; +} + +li::marker { + font-weight: bold; } ` -const tplBody = ` +const tplBody = ` +
+

There are currently {{.Accounts | len}} accounts stored in the system:

+
- + +
+
+

Go back to the main page.

` diff --git a/pkg/siteacc/admin/manage/manage.go b/pkg/siteacc/admin/manage/manage.go new file mode 100644 index 0000000000..58c64e699a --- /dev/null +++ b/pkg/siteacc/admin/manage/manage.go @@ -0,0 +1,51 @@ +// Copyright 2018-2020 CERN +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// In applying this license, CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +package manage + +import "github.com/cs3org/reva/pkg/siteacc/html" + +// PanelTemplate is the content provider for the contact form. +type PanelTemplate struct { + html.ContentProvider +} + +// GetTitle returns the title of the panel. +func (template *PanelTemplate) GetTitle() string { + return "ScienceMesh Site Administrators Management" +} + +// GetCaption returns the caption which is displayed on the panel. +func (template *PanelTemplate) GetCaption() string { + return "ScienceMesh Site Administrators Management" +} + +// GetContentJavaScript delivers additional JavaScript code. +func (template *PanelTemplate) GetContentJavaScript() string { + return tplJavaScript +} + +// GetContentStyleSheet delivers additional stylesheet code. +func (template *PanelTemplate) GetContentStyleSheet() string { + return tplStyleSheet +} + +// GetContentBody delivers the actual body content. +func (template *PanelTemplate) GetContentBody() string { + return tplBody +} diff --git a/pkg/siteacc/admin/manage/template.go b/pkg/siteacc/admin/manage/template.go new file mode 100644 index 0000000000..0870dd1172 --- /dev/null +++ b/pkg/siteacc/admin/manage/template.go @@ -0,0 +1,55 @@ +// Copyright 2018-2020 CERN +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// In applying this license, CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +package manage + +const tplJavaScript = ` +function handleEditAccounts() { + setState(STATE_STATUS, "Redirecting to the accounts editor..."); + window.location.replace("{{getServerAddress}}/admin/?path=accounts"); +} + +function handleEditSites() { + setState(STATE_STATUS, "Redirecting to the sites editor..."); + window.location.replace("{{getServerAddress}}/admin/?path=sites"); +} +` + +const tplStyleSheet = ` +html * { + font-family: arial !important; +} +button { + min-width: 150px; +} +` + +const tplBody = ` +
+

Welcome to the ScienceMesh Site Administrators Mangement!

+

Using this service, you can manage all site administrator accounts as well as their corresponding sites.

+
+
+
+
+ + +
+
+
+` diff --git a/pkg/siteacc/admin/panel.go b/pkg/siteacc/admin/panel.go index d322674aad..ef95468d7d 100644 --- a/pkg/siteacc/admin/panel.go +++ b/pkg/siteacc/admin/panel.go @@ -21,6 +21,8 @@ package admin import ( "net/http" + "github.com/cs3org/reva/pkg/siteacc/admin/accounts" + "github.com/cs3org/reva/pkg/siteacc/admin/manage" "github.com/cs3org/reva/pkg/siteacc/config" "github.com/cs3org/reva/pkg/siteacc/data" "github.com/cs3org/reva/pkg/siteacc/html" @@ -31,13 +33,13 @@ import ( // Panel represents the web interface panel of the accounts service administration. type Panel struct { html.PanelProvider - html.ContentProvider htmlPanel *html.Panel } const ( - templateMain = "main" + templateManage = "manage" + templateAccounts = "accounts" ) func (panel *Panel) initialize(conf *config.Configuration, log *zerolog.Logger) error { @@ -49,41 +51,31 @@ func (panel *Panel) initialize(conf *config.Configuration, log *zerolog.Logger) panel.htmlPanel = htmlPanel // Add all templates - if err := panel.htmlPanel.AddTemplate(templateMain, panel); err != nil { - return errors.Wrap(err, "unable to create the main template") + if err := panel.htmlPanel.AddTemplate(templateManage, &manage.PanelTemplate{}); err != nil { + return errors.Wrap(err, "unable to create the mangement template") + } + + if err := panel.htmlPanel.AddTemplate(templateAccounts, &accounts.PanelTemplate{}); err != nil { + return errors.Wrap(err, "unable to create the accounts template") } return nil } // GetActiveTemplate returns the name of the active template. -func (panel *Panel) GetActiveTemplate(*html.Session, string) string { - return templateMain -} - -// GetTitle returns the title of the htmlPanel. -func (panel *Panel) GetTitle() string { - return "ScienceMesh Site Administrator Accounts Panel" -} - -// GetCaption returns the caption which is displayed on the htmlPanel. -func (panel *Panel) GetCaption() string { - return "ScienceMesh Site Administrator Accounts ({{.Accounts | len}})" -} - -// GetContentJavaScript delivers additional JavaScript code. -func (panel *Panel) GetContentJavaScript() string { - return tplJavaScript -} - -// GetContentStyleSheet delivers additional stylesheet code. -func (panel *Panel) GetContentStyleSheet() string { - return tplStyleSheet -} +func (panel *Panel) GetActiveTemplate(session *html.Session, path string) string { + validPaths := []string{templateAccounts} + template := templateManage + + // Only allow valid template paths; redirect to the management page otherwise + for _, valid := range validPaths { + if valid == path { + template = path + break + } + } -// GetContentBody delivers the actual body content. -func (panel *Panel) GetContentBody() string { - return tplBody + return template } // PreExecute is called before the actual template is being executed. diff --git a/pkg/siteacc/siteacc.go b/pkg/siteacc/siteacc.go index f099f4dac5..6bfcc6461a 100644 --- a/pkg/siteacc/siteacc.go +++ b/pkg/siteacc/siteacc.go @@ -185,7 +185,7 @@ func (siteacc *SiteAccounts) AlertsDispatcher() *alerting.Dispatcher { // GetPublicEndpoints returns a list of all public endpoints. func (siteacc *SiteAccounts) GetPublicEndpoints() []string { // TODO: Only for local testing! - // return []string{"/"} + return []string{"/"} endpoints := make([]string, 0, 5) for _, ep := range getEndpoints() { From e3e649e6493f5fede0694205faa1b9b7b1f32ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Thu, 1 Sep 2022 12:32:32 +0200 Subject: [PATCH 02/11] Panel refactoring --- .../{ => panels}/account/contact/contact.go | 0 .../{ => panels}/account/contact/template.go | 0 pkg/siteacc/{ => panels}/account/edit/edit.go | 0 .../{ => panels}/account/edit/template.go | 0 .../{ => panels}/account/login/login.go | 0 .../{ => panels}/account/login/template.go | 0 .../{ => panels}/account/manage/manage.go | 0 .../{ => panels}/account/manage/template.go | 0 pkg/siteacc/{ => panels}/account/panel.go | 154 +++++++----------- .../account/registration/registration.go | 0 .../account/registration/template.go | 0 .../{ => panels}/account/settings/settings.go | 0 .../{ => panels}/account/settings/template.go | 0 .../{ => panels}/account/sites/sites.go | 0 .../{ => panels}/account/sites/template.go | 0 .../{ => panels}/admin/accounts/accounts.go | 0 .../{ => panels}/admin/accounts/template.go | 0 .../{ => panels}/admin/manage/manage.go | 0 .../{ => panels}/admin/manage/template.go | 0 pkg/siteacc/{ => panels}/admin/panel.go | 51 +++--- pkg/siteacc/panels/basepanel.go | 122 ++++++++++++++ pkg/siteacc/siteacc.go | 7 +- 22 files changed, 205 insertions(+), 129 deletions(-) rename pkg/siteacc/{ => panels}/account/contact/contact.go (100%) rename pkg/siteacc/{ => panels}/account/contact/template.go (100%) rename pkg/siteacc/{ => panels}/account/edit/edit.go (100%) rename pkg/siteacc/{ => panels}/account/edit/template.go (100%) rename pkg/siteacc/{ => panels}/account/login/login.go (100%) rename pkg/siteacc/{ => panels}/account/login/template.go (100%) rename pkg/siteacc/{ => panels}/account/manage/manage.go (100%) rename pkg/siteacc/{ => panels}/account/manage/template.go (100%) rename pkg/siteacc/{ => panels}/account/panel.go (60%) rename pkg/siteacc/{ => panels}/account/registration/registration.go (100%) rename pkg/siteacc/{ => panels}/account/registration/template.go (100%) rename pkg/siteacc/{ => panels}/account/settings/settings.go (100%) rename pkg/siteacc/{ => panels}/account/settings/template.go (100%) rename pkg/siteacc/{ => panels}/account/sites/sites.go (100%) rename pkg/siteacc/{ => panels}/account/sites/template.go (100%) rename pkg/siteacc/{ => panels}/admin/accounts/accounts.go (100%) rename pkg/siteacc/{ => panels}/admin/accounts/template.go (100%) rename pkg/siteacc/{ => panels}/admin/manage/manage.go (100%) rename pkg/siteacc/{ => panels}/admin/manage/template.go (100%) rename pkg/siteacc/{ => panels}/admin/panel.go (69%) create mode 100644 pkg/siteacc/panels/basepanel.go diff --git a/pkg/siteacc/account/contact/contact.go b/pkg/siteacc/panels/account/contact/contact.go similarity index 100% rename from pkg/siteacc/account/contact/contact.go rename to pkg/siteacc/panels/account/contact/contact.go diff --git a/pkg/siteacc/account/contact/template.go b/pkg/siteacc/panels/account/contact/template.go similarity index 100% rename from pkg/siteacc/account/contact/template.go rename to pkg/siteacc/panels/account/contact/template.go diff --git a/pkg/siteacc/account/edit/edit.go b/pkg/siteacc/panels/account/edit/edit.go similarity index 100% rename from pkg/siteacc/account/edit/edit.go rename to pkg/siteacc/panels/account/edit/edit.go diff --git a/pkg/siteacc/account/edit/template.go b/pkg/siteacc/panels/account/edit/template.go similarity index 100% rename from pkg/siteacc/account/edit/template.go rename to pkg/siteacc/panels/account/edit/template.go diff --git a/pkg/siteacc/account/login/login.go b/pkg/siteacc/panels/account/login/login.go similarity index 100% rename from pkg/siteacc/account/login/login.go rename to pkg/siteacc/panels/account/login/login.go diff --git a/pkg/siteacc/account/login/template.go b/pkg/siteacc/panels/account/login/template.go similarity index 100% rename from pkg/siteacc/account/login/template.go rename to pkg/siteacc/panels/account/login/template.go diff --git a/pkg/siteacc/account/manage/manage.go b/pkg/siteacc/panels/account/manage/manage.go similarity index 100% rename from pkg/siteacc/account/manage/manage.go rename to pkg/siteacc/panels/account/manage/manage.go diff --git a/pkg/siteacc/account/manage/template.go b/pkg/siteacc/panels/account/manage/template.go similarity index 100% rename from pkg/siteacc/account/manage/template.go rename to pkg/siteacc/panels/account/manage/template.go diff --git a/pkg/siteacc/account/panel.go b/pkg/siteacc/panels/account/panel.go similarity index 60% rename from pkg/siteacc/account/panel.go rename to pkg/siteacc/panels/account/panel.go index a1d27ac45b..869c24a3ae 100644 --- a/pkg/siteacc/account/panel.go +++ b/pkg/siteacc/panels/account/panel.go @@ -23,27 +23,25 @@ import ( "net/url" "strings" - "github.com/cs3org/reva/pkg/siteacc/account/contact" - "github.com/cs3org/reva/pkg/siteacc/account/edit" - "github.com/cs3org/reva/pkg/siteacc/account/login" - "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/sites" "github.com/cs3org/reva/pkg/siteacc/config" "github.com/cs3org/reva/pkg/siteacc/data" "github.com/cs3org/reva/pkg/siteacc/html" + "github.com/cs3org/reva/pkg/siteacc/panels" + "github.com/cs3org/reva/pkg/siteacc/panels/account/contact" + "github.com/cs3org/reva/pkg/siteacc/panels/account/edit" + "github.com/cs3org/reva/pkg/siteacc/panels/account/login" + "github.com/cs3org/reva/pkg/siteacc/panels/account/manage" + "github.com/cs3org/reva/pkg/siteacc/panels/account/registration" + "github.com/cs3org/reva/pkg/siteacc/panels/account/settings" + "github.com/cs3org/reva/pkg/siteacc/panels/account/sites" "github.com/pkg/errors" "github.com/rs/zerolog" ) // Panel represents the account panel. type Panel struct { + panels.BasePanel html.PanelProvider - - conf *config.Configuration - - htmlPanel *html.Panel } const ( @@ -57,45 +55,48 @@ const ( ) func (panel *Panel) initialize(conf *config.Configuration, log *zerolog.Logger) error { - if conf == nil { - return errors.Errorf("no configuration provided") - } - panel.conf = conf - - // Create the internal HTML panel - htmlPanel, err := html.NewPanel("account-panel", panel, conf, log) - if err != nil { - return errors.Wrap(err, "unable to create the account panel") - } - panel.htmlPanel = htmlPanel - - // Add all templates - if err := panel.htmlPanel.AddTemplate(templateLogin, &login.PanelTemplate{}); err != nil { - return errors.Wrap(err, "unable to create the login template") - } - - if err := panel.htmlPanel.AddTemplate(templateManage, &manage.PanelTemplate{}); err != nil { - return errors.Wrap(err, "unable to create the account management template") - } - - if err := panel.htmlPanel.AddTemplate(templateSettings, &settings.PanelTemplate{}); err != nil { - return errors.Wrap(err, "unable to create the account settings template") - } - - if err := panel.htmlPanel.AddTemplate(templateEdit, &edit.PanelTemplate{}); err != nil { - return errors.Wrap(err, "unable to create the account editing template") - } - - if err := panel.htmlPanel.AddTemplate(templateSites, &sites.PanelTemplate{}); err != nil { - return errors.Wrap(err, "unable to create the sites template") - } - - if err := panel.htmlPanel.AddTemplate(templateContact, &contact.PanelTemplate{}); err != nil { - return errors.Wrap(err, "unable to create the contact template") - } - - if err := panel.htmlPanel.AddTemplate(templateRegistration, ®istration.PanelTemplate{}); err != nil { - return errors.Wrap(err, "unable to create the registration template") + // Create templates + templates := []panels.BasePanelTemplate{ + { + ID: templateLogin, + Name: "login", + Provider: &login.PanelTemplate{}, + }, + { + ID: templateManage, + Name: "management", + Provider: &manage.PanelTemplate{}, + }, + { + ID: templateSettings, + Name: "settings", + Provider: &settings.PanelTemplate{}, + }, + { + ID: templateEdit, + Name: "editing", + Provider: &edit.PanelTemplate{}, + }, + { + ID: templateSites, + Name: "sites", + Provider: &sites.PanelTemplate{}, + }, + { + ID: templateContact, + Name: "contact", + Provider: &contact.PanelTemplate{}, + }, + { + ID: templateRegistration, + Name: "registration", + Provider: ®istration.PanelTemplate{}, + }, + } + + // Initialize base + if err := panel.BasePanel.Initialize("user-panel", panel, templates, conf, log); err != nil { + return errors.Wrap(err, "unable to create the user panel") } return nil @@ -104,17 +105,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, templateSites, templateContact, templateRegistration} - template := templateLogin - - // Only allow valid template paths; redirect to the login page otherwise - for _, valid := range validPaths { - if valid == path { - template = path - break - } - } - - return template + return panel.GetPathTemplate(validPaths, templateLogin, path) } // PreExecute is called before the actual template is being executed. @@ -154,7 +145,7 @@ func (panel *Panel) Execute(w http.ResponseWriter, r *http.Request, session *htm flatValues[strings.Title(k)] = v[0] } - availOps, err := data.QueryAvailableOperators(panel.conf.Mentix.URL, panel.conf.Mentix.DataEndpoint) + availOps, err := data.QueryAvailableOperators(panel.Config().Mentix.URL, panel.Config().Mentix.DataEndpoint) if err != nil { return errors.Wrap(err, "unable to query available operators") } @@ -183,13 +174,13 @@ func (panel *Panel) Execute(w http.ResponseWriter, r *http.Request, session *htm return errors.Wrap(err, "unable to query available sites") } - tplData.Operator = panel.cloneUserOperator(user.Operator, availSites) + tplData.Operator = panel.CloneOperator(user.Operator, availSites) tplData.Account = user.Account tplData.Sites = availSites } return tplData } - return panel.htmlPanel.Execute(w, r, session, dataProvider) + return panel.BasePanel.Execute(w, r, session, dataProvider) } func (panel *Panel) redirect(path string, w http.ResponseWriter, r *http.Request) html.ExecutionResult { @@ -211,13 +202,13 @@ func (panel *Panel) redirect(path string, w http.ResponseWriter, r *http.Request } func (panel *Panel) fetchAvailableSites(op *data.Operator) (map[string]string, error) { - ids, err := data.QueryOperatorSites(op.ID, panel.conf.Mentix.URL, panel.conf.Mentix.DataEndpoint) + ids, err := data.QueryOperatorSites(op.ID, panel.Config().Mentix.URL, panel.Config().Mentix.DataEndpoint) if err != nil { return nil, err } sites := make(map[string]string, 10) for _, id := range ids { - if siteName, _ := data.QuerySiteName(id, true, panel.conf.Mentix.URL, panel.conf.Mentix.DataEndpoint); err == nil { + if siteName, _ := data.QuerySiteName(id, true, panel.Config().Mentix.URL, panel.Config().Mentix.DataEndpoint); err == nil { sites[id] = siteName } else { sites[id] = id @@ -226,37 +217,6 @@ func (panel *Panel) fetchAvailableSites(op *data.Operator) (map[string]string, e return sites, nil } -func (panel *Panel) cloneUserOperator(op *data.Operator, sites map[string]string) *data.Operator { - // Clone the user's operator and decrypt all credentials for the panel - opClone := op.Clone(false) - for _, site := range opClone.Sites { - id, secret, err := site.Config.TestClientCredentials.Get(panel.conf.Security.CredentialsPassphrase) - if err == nil { - site.Config.TestClientCredentials.ID = id - site.Config.TestClientCredentials.Secret = secret - } - } - - // Add missing sites - for id := range sites { - siteFound := false - for _, site := range opClone.Sites { - if strings.EqualFold(site.ID, id) { - siteFound = true - break - } - } - if !siteFound { - opClone.Sites = append(opClone.Sites, &data.Site{ - ID: id, - Config: data.SiteConfiguration{}, - }) - } - } - - return opClone -} - // NewPanel creates a new account panel. func NewPanel(conf *config.Configuration, log *zerolog.Logger) (*Panel, error) { form := &Panel{} diff --git a/pkg/siteacc/account/registration/registration.go b/pkg/siteacc/panels/account/registration/registration.go similarity index 100% rename from pkg/siteacc/account/registration/registration.go rename to pkg/siteacc/panels/account/registration/registration.go diff --git a/pkg/siteacc/account/registration/template.go b/pkg/siteacc/panels/account/registration/template.go similarity index 100% rename from pkg/siteacc/account/registration/template.go rename to pkg/siteacc/panels/account/registration/template.go diff --git a/pkg/siteacc/account/settings/settings.go b/pkg/siteacc/panels/account/settings/settings.go similarity index 100% rename from pkg/siteacc/account/settings/settings.go rename to pkg/siteacc/panels/account/settings/settings.go diff --git a/pkg/siteacc/account/settings/template.go b/pkg/siteacc/panels/account/settings/template.go similarity index 100% rename from pkg/siteacc/account/settings/template.go rename to pkg/siteacc/panels/account/settings/template.go diff --git a/pkg/siteacc/account/sites/sites.go b/pkg/siteacc/panels/account/sites/sites.go similarity index 100% rename from pkg/siteacc/account/sites/sites.go rename to pkg/siteacc/panels/account/sites/sites.go diff --git a/pkg/siteacc/account/sites/template.go b/pkg/siteacc/panels/account/sites/template.go similarity index 100% rename from pkg/siteacc/account/sites/template.go rename to pkg/siteacc/panels/account/sites/template.go diff --git a/pkg/siteacc/admin/accounts/accounts.go b/pkg/siteacc/panels/admin/accounts/accounts.go similarity index 100% rename from pkg/siteacc/admin/accounts/accounts.go rename to pkg/siteacc/panels/admin/accounts/accounts.go diff --git a/pkg/siteacc/admin/accounts/template.go b/pkg/siteacc/panels/admin/accounts/template.go similarity index 100% rename from pkg/siteacc/admin/accounts/template.go rename to pkg/siteacc/panels/admin/accounts/template.go diff --git a/pkg/siteacc/admin/manage/manage.go b/pkg/siteacc/panels/admin/manage/manage.go similarity index 100% rename from pkg/siteacc/admin/manage/manage.go rename to pkg/siteacc/panels/admin/manage/manage.go diff --git a/pkg/siteacc/admin/manage/template.go b/pkg/siteacc/panels/admin/manage/template.go similarity index 100% rename from pkg/siteacc/admin/manage/template.go rename to pkg/siteacc/panels/admin/manage/template.go diff --git a/pkg/siteacc/admin/panel.go b/pkg/siteacc/panels/admin/panel.go similarity index 69% rename from pkg/siteacc/admin/panel.go rename to pkg/siteacc/panels/admin/panel.go index ef95468d7d..b6e577c500 100644 --- a/pkg/siteacc/admin/panel.go +++ b/pkg/siteacc/panels/admin/panel.go @@ -21,20 +21,20 @@ package admin import ( "net/http" - "github.com/cs3org/reva/pkg/siteacc/admin/accounts" - "github.com/cs3org/reva/pkg/siteacc/admin/manage" "github.com/cs3org/reva/pkg/siteacc/config" "github.com/cs3org/reva/pkg/siteacc/data" "github.com/cs3org/reva/pkg/siteacc/html" + "github.com/cs3org/reva/pkg/siteacc/panels" + "github.com/cs3org/reva/pkg/siteacc/panels/admin/accounts" + "github.com/cs3org/reva/pkg/siteacc/panels/admin/manage" "github.com/pkg/errors" "github.com/rs/zerolog" ) // Panel represents the web interface panel of the accounts service administration. type Panel struct { + panels.BasePanel html.PanelProvider - - htmlPanel *html.Panel } const ( @@ -43,20 +43,23 @@ const ( ) func (panel *Panel) initialize(conf *config.Configuration, log *zerolog.Logger) error { - // Create the internal HTML panel - htmlPanel, err := html.NewPanel("admin-panel", panel, conf, log) - if err != nil { - return errors.Wrap(err, "unable to create the administration panel") - } - panel.htmlPanel = htmlPanel - - // Add all templates - if err := panel.htmlPanel.AddTemplate(templateManage, &manage.PanelTemplate{}); err != nil { - return errors.Wrap(err, "unable to create the mangement template") + // Create templates + templates := []panels.BasePanelTemplate{ + { + ID: templateManage, + Name: "mangement", + Provider: &manage.PanelTemplate{}, + }, + { + ID: templateAccounts, + Name: "accounts", + Provider: &accounts.PanelTemplate{}, + }, } - if err := panel.htmlPanel.AddTemplate(templateAccounts, &accounts.PanelTemplate{}); err != nil { - return errors.Wrap(err, "unable to create the accounts template") + // Initialize base + if err := panel.BasePanel.Initialize("admin-panel", panel, templates, conf, log); err != nil { + return errors.Wrap(err, "unable to create the administrator panel") } return nil @@ -65,17 +68,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{templateAccounts} - template := templateManage - - // Only allow valid template paths; redirect to the management page otherwise - for _, valid := range validPaths { - if valid == path { - template = path - break - } - } - - return template + return panel.GetPathTemplate(validPaths, templateManage, path) } // PreExecute is called before the actual template is being executed. @@ -84,7 +77,7 @@ func (panel *Panel) PreExecute(*html.Session, string, http.ResponseWriter, *http } // Execute generates the HTTP output of the htmlPanel and writes it to the response writer. -func (panel *Panel) Execute(w http.ResponseWriter, r *http.Request, session *html.Session, accounts *data.Accounts) error { +func (panel *Panel) Execute(w http.ResponseWriter, r *http.Request, session *html.Session, accounts *data.Accounts, operators *data.Operators) error { dataProvider := func(*html.Session) interface{} { type TemplateData struct { Accounts *data.Accounts @@ -94,7 +87,7 @@ func (panel *Panel) Execute(w http.ResponseWriter, r *http.Request, session *htm Accounts: accounts, } } - return panel.htmlPanel.Execute(w, r, session, dataProvider) + return panel.BasePanel.Execute(w, r, session, dataProvider) } // NewPanel creates a new administration panel. diff --git a/pkg/siteacc/panels/basepanel.go b/pkg/siteacc/panels/basepanel.go new file mode 100644 index 0000000000..119637df97 --- /dev/null +++ b/pkg/siteacc/panels/basepanel.go @@ -0,0 +1,122 @@ +// Copyright 2018-2020 CERN +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// In applying this license, CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +package panels + +import ( + "net/http" + "strings" + + "github.com/cs3org/reva/pkg/siteacc/config" + "github.com/cs3org/reva/pkg/siteacc/data" + "github.com/cs3org/reva/pkg/siteacc/html" + "github.com/pkg/errors" + "github.com/rs/zerolog" +) + +// BasePanel represents the base for all panels. +type BasePanel struct { + conf *config.Configuration + + htmlPanel *html.Panel +} + +type BasePanelTemplate struct { + ID string + Name string + Provider html.ContentProvider +} + +// Initialize initializes the base panel. +func (panel *BasePanel) Initialize(name string, panelProvider html.PanelProvider, templates []BasePanelTemplate, conf *config.Configuration, log *zerolog.Logger) error { + if conf == nil { + return errors.Errorf("no configuration provided") + } + panel.conf = conf + + // Create the internal HTML panel + htmlPanel, err := html.NewPanel(name, panelProvider, conf, log) + if err != nil { + return errors.Wrap(err, "unable to create the HTML panel") + } + panel.htmlPanel = htmlPanel + + // Add all templates + for _, template := range templates { + if err := panel.htmlPanel.AddTemplate(template.ID, template.Provider); err != nil { + return errors.Wrapf(err, "unable to create the %v template", template.Name) + } + } + + return nil +} + +// GetPathTemplate returns the name of the active template. +func (panel *BasePanel) GetPathTemplate(validPaths []string, defaultTemplate string, path string) string { + template := defaultTemplate + + // Only allow valid template paths; redirect to the default template otherwise + for _, valid := range validPaths { + if valid == path { + template = path + break + } + } + + return template +} + +func (panel *BasePanel) Execute(w http.ResponseWriter, r *http.Request, session *html.Session, dataProvider html.PanelDataProvider) error { + return panel.htmlPanel.Execute(w, r, session, dataProvider) +} + +// CloneOperator clones an operator and adds missing sites. +func (panel *BasePanel) CloneOperator(op *data.Operator, sites map[string]string) *data.Operator { + // Clone the operator and decrypt all credentials for the panel + opClone := op.Clone(false) + for _, site := range opClone.Sites { + id, secret, err := site.Config.TestClientCredentials.Get(panel.conf.Security.CredentialsPassphrase) + if err == nil { + site.Config.TestClientCredentials.ID = id + site.Config.TestClientCredentials.Secret = secret + } + } + + // Add missing sites + for id := range sites { + siteFound := false + for _, site := range opClone.Sites { + if strings.EqualFold(site.ID, id) { + siteFound = true + break + } + } + if !siteFound { + opClone.Sites = append(opClone.Sites, &data.Site{ + ID: id, + Config: data.SiteConfiguration{}, + }) + } + } + + return opClone +} + +func (panel *BasePanel) Config() *config.Configuration { + return panel.conf +} diff --git a/pkg/siteacc/siteacc.go b/pkg/siteacc/siteacc.go index 6bfcc6461a..11a3b2a96a 100644 --- a/pkg/siteacc/siteacc.go +++ b/pkg/siteacc/siteacc.go @@ -22,13 +22,13 @@ import ( "fmt" "net/http" - accpanel "github.com/cs3org/reva/pkg/siteacc/account" - "github.com/cs3org/reva/pkg/siteacc/admin" "github.com/cs3org/reva/pkg/siteacc/alerting" "github.com/cs3org/reva/pkg/siteacc/config" "github.com/cs3org/reva/pkg/siteacc/data" "github.com/cs3org/reva/pkg/siteacc/html" "github.com/cs3org/reva/pkg/siteacc/manager" + accpanel "github.com/cs3org/reva/pkg/siteacc/panels/account" + "github.com/cs3org/reva/pkg/siteacc/panels/admin" "github.com/pkg/errors" "github.com/rs/zerolog" ) @@ -154,7 +154,8 @@ func (siteacc *SiteAccounts) RequestHandler() http.Handler { func (siteacc *SiteAccounts) ShowAdministrationPanel(w http.ResponseWriter, r *http.Request, session *html.Session) error { // The admin panel only shows the stored accounts and offers actions through links, so let it use cloned data accounts := siteacc.accountsManager.CloneAccounts(true) - return siteacc.adminPanel.Execute(w, r, session, &accounts) + operators := siteacc.operatorsManager.CloneOperators(false) + return siteacc.adminPanel.Execute(w, r, session, &accounts, &operators) } // ShowAccountPanel writes the account panel HTTP output directly to the response writer. From 8393afe30938742ea498c0238835159d5a2d52ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Thu, 1 Sep 2022 12:45:20 +0200 Subject: [PATCH 03/11] Provide operators in admin panel --- pkg/siteacc/panels/account/panel.go | 20 ++------------------ pkg/siteacc/panels/admin/panel.go | 27 ++++++++++++++++++++++++--- pkg/siteacc/panels/basepanel.go | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+), 21 deletions(-) diff --git a/pkg/siteacc/panels/account/panel.go b/pkg/siteacc/panels/account/panel.go index 869c24a3ae..7b9fa8c433 100644 --- a/pkg/siteacc/panels/account/panel.go +++ b/pkg/siteacc/panels/account/panel.go @@ -137,7 +137,7 @@ func (panel *Panel) PreExecute(session *html.Session, path string, w http.Respon return html.ContinueExecution, nil } -// Execute generates the HTTP output of the form and writes it to the response writer. +// Execute generates the HTTP output of the panel and writes it to the response writer. func (panel *Panel) Execute(w http.ResponseWriter, r *http.Request, session *html.Session) error { dataProvider := func(*html.Session) interface{} { flatValues := make(map[string]string, len(r.URL.Query())) @@ -169,7 +169,7 @@ func (panel *Panel) Execute(w http.ResponseWriter, r *http.Request, session *htm Titles: []string{"Mr", "Mrs", "Ms", "Prof", "Dr"}, } if user := session.LoggedInUser(); user != nil { - availSites, err := panel.fetchAvailableSites(user.Operator) + availSites, err := panel.FetchOperatorSites(user.Operator) if err != nil { return errors.Wrap(err, "unable to query available sites") } @@ -201,22 +201,6 @@ func (panel *Panel) redirect(path string, w http.ResponseWriter, r *http.Request return html.AbortExecution } -func (panel *Panel) fetchAvailableSites(op *data.Operator) (map[string]string, error) { - ids, err := data.QueryOperatorSites(op.ID, panel.Config().Mentix.URL, panel.Config().Mentix.DataEndpoint) - if err != nil { - return nil, err - } - sites := make(map[string]string, 10) - for _, id := range ids { - if siteName, _ := data.QuerySiteName(id, true, panel.Config().Mentix.URL, panel.Config().Mentix.DataEndpoint); err == nil { - sites[id] = siteName - } else { - sites[id] = id - } - } - return sites, nil -} - // NewPanel creates a new account panel. func NewPanel(conf *config.Configuration, log *zerolog.Logger) (*Panel, error) { form := &Panel{} diff --git a/pkg/siteacc/panels/admin/panel.go b/pkg/siteacc/panels/admin/panel.go index b6e577c500..7a2a0c4abb 100644 --- a/pkg/siteacc/panels/admin/panel.go +++ b/pkg/siteacc/panels/admin/panel.go @@ -76,20 +76,41 @@ func (panel *Panel) PreExecute(*html.Session, string, http.ResponseWriter, *http return html.ContinueExecution, nil } -// Execute generates the HTTP output of the htmlPanel and writes it to the response writer. +// Execute generates the HTTP output of the panel and writes it to the response writer. func (panel *Panel) Execute(w http.ResponseWriter, r *http.Request, session *html.Session, accounts *data.Accounts, operators *data.Operators) error { + // Clone all operators + opsClone, err := panel.cloneOperators(operators) + if err != nil { + return errors.Wrap(err, "unable to clone operators") + } + dataProvider := func(*html.Session) interface{} { type TemplateData struct { - Accounts *data.Accounts + Accounts *data.Accounts + Operators *data.Operators } return TemplateData{ - Accounts: accounts, + Accounts: accounts, + Operators: opsClone, } } return panel.BasePanel.Execute(w, r, session, dataProvider) } +func (panel *Panel) cloneOperators(operators *data.Operators) (*data.Operators, error) { + // Clone all available operators and decrypt all credentials for the panel + opsClone := make(data.Operators, 0, len(*operators)) + for _, op := range *operators { + availSites, err := panel.FetchOperatorSites(op) + if err != nil { + return nil, errors.Wrapf(err, "unable to query available sites of operator %v", op.ID) + } + opsClone = append(opsClone, panel.CloneOperator(op, availSites)) + } + return &opsClone, nil +} + // NewPanel creates a new administration panel. func NewPanel(conf *config.Configuration, log *zerolog.Logger) (*Panel, error) { panel := &Panel{} diff --git a/pkg/siteacc/panels/basepanel.go b/pkg/siteacc/panels/basepanel.go index 119637df97..9f798eb47e 100644 --- a/pkg/siteacc/panels/basepanel.go +++ b/pkg/siteacc/panels/basepanel.go @@ -36,6 +36,7 @@ type BasePanel struct { htmlPanel *html.Panel } +// BasePanelTemplate represents an HTML template used for initialization. type BasePanelTemplate struct { ID string Name string @@ -81,10 +82,27 @@ func (panel *BasePanel) GetPathTemplate(validPaths []string, defaultTemplate str return template } +// Execute generates the HTTP output of the panel and writes it to the response writer. func (panel *BasePanel) Execute(w http.ResponseWriter, r *http.Request, session *html.Session, dataProvider html.PanelDataProvider) error { return panel.htmlPanel.Execute(w, r, session, dataProvider) } +func (panel *BasePanel) FetchOperatorSites(op *data.Operator) (map[string]string, error) { + ids, err := data.QueryOperatorSites(op.ID, panel.Config().Mentix.URL, panel.Config().Mentix.DataEndpoint) + if err != nil { + return nil, err + } + sites := make(map[string]string, 10) + for _, id := range ids { + if siteName, _ := data.QuerySiteName(id, true, panel.Config().Mentix.URL, panel.Config().Mentix.DataEndpoint); err == nil { + sites[id] = siteName + } else { + sites[id] = id + } + } + return sites, nil +} + // CloneOperator clones an operator and adds missing sites. func (panel *BasePanel) CloneOperator(op *data.Operator, sites map[string]string) *data.Operator { // Clone the operator and decrypt all credentials for the panel From ba9bc95c56a683d342a58b36a2c9daa49c039451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Thu, 1 Sep 2022 12:47:44 +0200 Subject: [PATCH 04/11] Refactoring --- pkg/siteacc/panels/account/panel.go | 25 +++---------------------- pkg/siteacc/panels/basepanel.go | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/pkg/siteacc/panels/account/panel.go b/pkg/siteacc/panels/account/panel.go index 7b9fa8c433..634b2e0b4a 100644 --- a/pkg/siteacc/panels/account/panel.go +++ b/pkg/siteacc/panels/account/panel.go @@ -20,7 +20,6 @@ package account import ( "net/http" - "net/url" "strings" "github.com/cs3org/reva/pkg/siteacc/config" @@ -117,19 +116,19 @@ func (panel *Panel) PreExecute(session *html.Session, path string, w http.Respon case templateSites: // If the logged in user doesn't have sites access, redirect him back to the main account page if !user.Account.Data.SitesAccess { - return panel.redirect(templateManage, w, r), nil + return panel.Redirect(templateManage, w, r), 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 + 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 + return panel.Redirect(templateLogin, w, r), nil } } } @@ -183,24 +182,6 @@ func (panel *Panel) Execute(w http.ResponseWriter, r *http.Request, session *htm return panel.BasePanel.Execute(w, r, session, dataProvider) } -func (panel *Panel) redirect(path string, w http.ResponseWriter, r *http.Request) html.ExecutionResult { - // Check if the original (full) URI path is stored in the request header; if not, use the request URI to get the path - fullPath := r.Header.Get("X-Replaced-Path") - if fullPath == "" { - uri, _ := url.Parse(r.RequestURI) - fullPath = uri.Path - } - - // Modify the original request URL by replacing the path parameter - newURL, _ := url.Parse(fullPath) - params := newURL.Query() - params.Del("path") - params.Add("path", path) - newURL.RawQuery = params.Encode() - http.Redirect(w, r, newURL.String(), http.StatusFound) - return html.AbortExecution -} - // NewPanel creates a new account panel. func NewPanel(conf *config.Configuration, log *zerolog.Logger) (*Panel, error) { form := &Panel{} diff --git a/pkg/siteacc/panels/basepanel.go b/pkg/siteacc/panels/basepanel.go index 9f798eb47e..50ee709e12 100644 --- a/pkg/siteacc/panels/basepanel.go +++ b/pkg/siteacc/panels/basepanel.go @@ -20,6 +20,7 @@ package panels import ( "net/http" + "net/url" "strings" "github.com/cs3org/reva/pkg/siteacc/config" @@ -87,6 +88,25 @@ func (panel *BasePanel) Execute(w http.ResponseWriter, r *http.Request, session return panel.htmlPanel.Execute(w, r, session, dataProvider) } +// Redirect performs an HTTP redirect. +func (panel *BasePanel) Redirect(path string, w http.ResponseWriter, r *http.Request) html.ExecutionResult { + // Check if the original (full) URI path is stored in the request header; if not, use the request URI to get the path + fullPath := r.Header.Get("X-Replaced-Path") + if fullPath == "" { + uri, _ := url.Parse(r.RequestURI) + fullPath = uri.Path + } + + // Modify the original request URL by replacing the path parameter + newURL, _ := url.Parse(fullPath) + params := newURL.Query() + params.Del("path") + params.Add("path", path) + newURL.RawQuery = params.Encode() + http.Redirect(w, r, newURL.String(), http.StatusFound) + return html.AbortExecution +} + func (panel *BasePanel) FetchOperatorSites(op *data.Operator) (map[string]string, error) { ids, err := data.QueryOperatorSites(op.ID, panel.Config().Mentix.URL, panel.Config().Mentix.DataEndpoint) if err != nil { From af8a9325a3638349f025af743afd1aee2ce9a9c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Thu, 1 Sep 2022 12:59:01 +0200 Subject: [PATCH 05/11] Prepare sites panel --- pkg/siteacc/panels/admin/accounts/template.go | 1 - pkg/siteacc/panels/admin/panel.go | 9 +++- pkg/siteacc/panels/admin/sites/sites.go | 51 ++++++++++++++++++ pkg/siteacc/panels/admin/sites/template.go | 54 +++++++++++++++++++ 4 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 pkg/siteacc/panels/admin/sites/sites.go create mode 100644 pkg/siteacc/panels/admin/sites/template.go diff --git a/pkg/siteacc/panels/admin/accounts/template.go b/pkg/siteacc/panels/admin/accounts/template.go index 1ff1807291..ef142d6e84 100644 --- a/pkg/siteacc/panels/admin/accounts/template.go +++ b/pkg/siteacc/panels/admin/accounts/template.go @@ -47,7 +47,6 @@ const tplStyleSheet = ` html * { font-family: arial !important; } - li::marker { font-weight: bold; } diff --git a/pkg/siteacc/panels/admin/panel.go b/pkg/siteacc/panels/admin/panel.go index 7a2a0c4abb..64d3260d59 100644 --- a/pkg/siteacc/panels/admin/panel.go +++ b/pkg/siteacc/panels/admin/panel.go @@ -27,6 +27,7 @@ import ( "github.com/cs3org/reva/pkg/siteacc/panels" "github.com/cs3org/reva/pkg/siteacc/panels/admin/accounts" "github.com/cs3org/reva/pkg/siteacc/panels/admin/manage" + "github.com/cs3org/reva/pkg/siteacc/panels/admin/sites" "github.com/pkg/errors" "github.com/rs/zerolog" ) @@ -40,6 +41,7 @@ type Panel struct { const ( templateManage = "manage" templateAccounts = "accounts" + templateSites = "sites" ) func (panel *Panel) initialize(conf *config.Configuration, log *zerolog.Logger) error { @@ -55,6 +57,11 @@ func (panel *Panel) initialize(conf *config.Configuration, log *zerolog.Logger) Name: "accounts", Provider: &accounts.PanelTemplate{}, }, + { + ID: templateSites, + Name: "sites", + Provider: &sites.PanelTemplate{}, + }, } // Initialize base @@ -67,7 +74,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{templateAccounts} + validPaths := []string{templateManage, templateAccounts, templateSites} return panel.GetPathTemplate(validPaths, templateManage, path) } diff --git a/pkg/siteacc/panels/admin/sites/sites.go b/pkg/siteacc/panels/admin/sites/sites.go new file mode 100644 index 0000000000..93e547df7d --- /dev/null +++ b/pkg/siteacc/panels/admin/sites/sites.go @@ -0,0 +1,51 @@ +// Copyright 2018-2020 CERN +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// In applying this license, CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +package sites + +import "github.com/cs3org/reva/pkg/siteacc/html" + +// PanelTemplate is the content provider for the contact form. +type PanelTemplate struct { + html.ContentProvider +} + +// GetTitle returns the title of the panel. +func (template *PanelTemplate) GetTitle() string { + return "ScienceMesh Site Administrators Sites" +} + +// GetCaption returns the caption which is displayed on the panel. +func (template *PanelTemplate) GetCaption() string { + return "ScienceMesh Site Administrators Sites" +} + +// GetContentJavaScript delivers additional JavaScript code. +func (template *PanelTemplate) GetContentJavaScript() string { + return tplJavaScript +} + +// GetContentStyleSheet delivers additional stylesheet code. +func (template *PanelTemplate) GetContentStyleSheet() string { + return tplStyleSheet +} + +// GetContentBody delivers the actual body content. +func (template *PanelTemplate) GetContentBody() string { + return tplBody +} diff --git a/pkg/siteacc/panels/admin/sites/template.go b/pkg/siteacc/panels/admin/sites/template.go new file mode 100644 index 0000000000..3e0220ef7f --- /dev/null +++ b/pkg/siteacc/panels/admin/sites/template.go @@ -0,0 +1,54 @@ +// Copyright 2018-2020 CERN +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// In applying this license, CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +package sites + +const tplJavaScript = ` +` + +const tplStyleSheet = ` +html * { + font-family: arial !important; +} +li::marker { + font-weight: bold; +} +` + +const tplBody = ` +
+

There are currently {{.Operators | len}} operators stored in the system:

+
+
+
    + {{range .Operators}} +
  1. +
    +
    + {{.ID}}
    +
    +
    +
    +
  2. + {{end}} +
+
+
+

Go back to the main page.

+
+` From dd592a03d85ea53620c468c7a480401ace32559f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Thu, 1 Sep 2022 14:59:13 +0200 Subject: [PATCH 06/11] Minor adjustments --- pkg/siteacc/html/panel.go | 4 ++++ pkg/siteacc/panels/admin/manage/template.go | 12 ++++++------ pkg/siteacc/panels/admin/sites/template.go | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/pkg/siteacc/html/panel.go b/pkg/siteacc/html/panel.go index 3a5376bf91..de6134e23c 100644 --- a/pkg/siteacc/html/panel.go +++ b/pkg/siteacc/html/panel.go @@ -170,6 +170,10 @@ func (panel *Panel) prepareTemplate(tpl *template.Template) { } return strings.Join(sites, ", ") }, + "getSiteName": func(siteID string, fullName bool) string { + siteName, _ := data.QuerySiteName(siteID, fullName, panel.conf.Mentix.URL, panel.conf.Mentix.DataEndpoint) + return siteName + }, }) } diff --git a/pkg/siteacc/panels/admin/manage/template.go b/pkg/siteacc/panels/admin/manage/template.go index 0870dd1172..dc88d3b585 100644 --- a/pkg/siteacc/panels/admin/manage/template.go +++ b/pkg/siteacc/panels/admin/manage/template.go @@ -19,13 +19,13 @@ package manage const tplJavaScript = ` -function handleEditAccounts() { - setState(STATE_STATUS, "Redirecting to the accounts editor..."); +function handleViewAccounts() { + setState(STATE_STATUS, "Redirecting to the accounts overview..."); window.location.replace("{{getServerAddress}}/admin/?path=accounts"); } -function handleEditSites() { - setState(STATE_STATUS, "Redirecting to the sites editor..."); +function handleViewSites() { + setState(STATE_STATUS, "Redirecting to the sites overview..."); window.location.replace("{{getServerAddress}}/admin/?path=sites"); } ` @@ -47,8 +47,8 @@ const tplBody = `
- - + +
diff --git a/pkg/siteacc/panels/admin/sites/template.go b/pkg/siteacc/panels/admin/sites/template.go index 3e0220ef7f..48aa7619ec 100644 --- a/pkg/siteacc/panels/admin/sites/template.go +++ b/pkg/siteacc/panels/admin/sites/template.go @@ -40,7 +40,22 @@ const tplBody = `
  • - {{.ID}}
    + {{.ID}} ({{.Sites | len}} site(s))
    +
    +
    +
      + {{$parent := .}} + {{range .Sites}} +
    • + {{getSiteName .ID true}} ({{.ID}})
      + {{if .Config.TestClientCredentials.ID}} + Test user configured + {{else}} + Test user not configured + {{end}} +
    • + {{end}} +

    From a3b6920385cd391a5bee83950e0ff25919bacd9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Thu, 1 Sep 2022 15:05:38 +0200 Subject: [PATCH 07/11] Remove debug code --- pkg/siteacc/siteacc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/siteacc/siteacc.go b/pkg/siteacc/siteacc.go index 11a3b2a96a..569e0a978f 100644 --- a/pkg/siteacc/siteacc.go +++ b/pkg/siteacc/siteacc.go @@ -186,7 +186,7 @@ func (siteacc *SiteAccounts) AlertsDispatcher() *alerting.Dispatcher { // GetPublicEndpoints returns a list of all public endpoints. func (siteacc *SiteAccounts) GetPublicEndpoints() []string { // TODO: Only for local testing! - return []string{"/"} + // return []string{"/"} endpoints := make([]string, 0, 5) for _, ep := range getEndpoints() { From 7375cd9133dcd7a5d3ff38cc95a104982f85ecb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Thu, 1 Sep 2022 15:20:44 +0200 Subject: [PATCH 08/11] Minor adjustments --- pkg/siteacc/panels/admin/sites/template.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/siteacc/panels/admin/sites/template.go b/pkg/siteacc/panels/admin/sites/template.go index 48aa7619ec..fcde6ad0ea 100644 --- a/pkg/siteacc/panels/admin/sites/template.go +++ b/pkg/siteacc/panels/admin/sites/template.go @@ -43,15 +43,13 @@ const tplBody = ` {{.ID}} ({{.Sites | len}} site(s))
    -
      +
        {{$parent := .}} {{range .Sites}}
      • {{getSiteName .ID true}} ({{.ID}})
        - {{if .Config.TestClientCredentials.ID}} - Test user configured - {{else}} - Test user not configured + {{if not .Config.TestClientCredentials.ID}} + Test user not configured! {{end}}
      • {{end}} From fa0fdb5de16f87e1f8cb4c007ecabe71572b851e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Thu, 1 Sep 2022 15:30:58 +0200 Subject: [PATCH 09/11] Minor adjustments --- pkg/siteacc/panels/admin/sites/template.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/siteacc/panels/admin/sites/template.go b/pkg/siteacc/panels/admin/sites/template.go index fcde6ad0ea..93f3239bb0 100644 --- a/pkg/siteacc/panels/admin/sites/template.go +++ b/pkg/siteacc/panels/admin/sites/template.go @@ -43,7 +43,7 @@ const tplBody = ` {{.ID}} ({{.Sites | len}} site(s))
    -
      +
        {{$parent := .}} {{range .Sites}}
      • From 33673255663f05dc3ec3adc88e59c7243a04dcf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Tue, 6 Sep 2022 12:45:28 +0200 Subject: [PATCH 10/11] Fix endpoints --- pkg/siteacc/endpoints.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/siteacc/endpoints.go b/pkg/siteacc/endpoints.go index da02f21d45..ac2dfe0f6d 100644 --- a/pkg/siteacc/endpoints.go +++ b/pkg/siteacc/endpoints.go @@ -71,13 +71,13 @@ func getEndpoints() []endpoint { {config.EndpointList, callMethodEndpoint, createMethodCallbacks(handleList, nil), false}, {config.EndpointFind, callMethodEndpoint, createMethodCallbacks(handleFind, nil), false}, {config.EndpointCreate, callMethodEndpoint, createMethodCallbacks(nil, handleCreate), true}, - {config.EndpointUpdate, callMethodEndpoint, createMethodCallbacks(nil, handleUpdate), false}, - {config.EndpointConfigure, callMethodEndpoint, createMethodCallbacks(nil, handleConfigure), false}, + {config.EndpointUpdate, callMethodEndpoint, createMethodCallbacks(nil, handleUpdate), true}, + {config.EndpointConfigure, callMethodEndpoint, createMethodCallbacks(nil, handleConfigure), true}, {config.EndpointRemove, callMethodEndpoint, createMethodCallbacks(nil, handleRemove), false}, // Site endpoints {config.EndpointSiteGet, callMethodEndpoint, createMethodCallbacks(handleSiteGet, nil), false}, // Sites endpoints - {config.EndpointSitesConfigure, callMethodEndpoint, createMethodCallbacks(nil, handleSitesConfigure), false}, + {config.EndpointSitesConfigure, callMethodEndpoint, createMethodCallbacks(nil, handleSitesConfigure), true}, // Login endpoints {config.EndpointLogin, callMethodEndpoint, createMethodCallbacks(nil, handleLogin), true}, {config.EndpointLogout, callMethodEndpoint, createMethodCallbacks(handleLogout, nil), true}, From c9a61736cf6ac0b44dbe5396cdf6b9a1bbaa2b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Mon, 12 Sep 2022 14:31:23 +0200 Subject: [PATCH 11/11] Add changelog & Hound fixes --- changelog/unreleased/siteacc-ext.md | 5 +++++ pkg/siteacc/panels/basepanel.go | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 changelog/unreleased/siteacc-ext.md diff --git a/changelog/unreleased/siteacc-ext.md b/changelog/unreleased/siteacc-ext.md new file mode 100644 index 0000000000..1f50de4f54 --- /dev/null +++ b/changelog/unreleased/siteacc-ext.md @@ -0,0 +1,5 @@ +Enhancement: Site Accounts improvements + +The site accounts admin panel has been reworked and now also shows which sites aren't configured properly yet. Furthermore, a bug that prevented users from changing site configurations has been fixed. + +https://github.com/cs3org/reva/pull/3221 diff --git a/pkg/siteacc/panels/basepanel.go b/pkg/siteacc/panels/basepanel.go index 50ee709e12..e7ff5e326d 100644 --- a/pkg/siteacc/panels/basepanel.go +++ b/pkg/siteacc/panels/basepanel.go @@ -107,6 +107,7 @@ func (panel *BasePanel) Redirect(path string, w http.ResponseWriter, r *http.Req return html.AbortExecution } +// FetchOperatorSites fetches all sites for an operator using Mentix. func (panel *BasePanel) FetchOperatorSites(op *data.Operator) (map[string]string, error) { ids, err := data.QueryOperatorSites(op.ID, panel.Config().Mentix.URL, panel.Config().Mentix.DataEndpoint) if err != nil { @@ -155,6 +156,7 @@ func (panel *BasePanel) CloneOperator(op *data.Operator, sites map[string]string return opClone } +// Config gets the configuration object. func (panel *BasePanel) Config() *config.Configuration { return panel.conf }