diff --git a/changelog/unreleased/fix-mentix-auth-status.md b/changelog/unreleased/fix-mentix-auth-status.md new file mode 100644 index 0000000000..84918adda3 --- /dev/null +++ b/changelog/unreleased/fix-mentix-auth-status.md @@ -0,0 +1,5 @@ +Bugfix: Mentix site authorization status changes + +If a site changes its authorization status, Mentix did not update its internal data to reflect this change. This PR fixes this issue. + +https://github.com/cs3org/reva/pull/1634 diff --git a/pkg/mentix/connectors/localfile.go b/pkg/mentix/connectors/localfile.go index ed521353fc..8ed918ec31 100755 --- a/pkg/mentix/connectors/localfile.go +++ b/pkg/mentix/connectors/localfile.go @@ -25,6 +25,7 @@ import ( "os" "path/filepath" + "github.com/pkg/errors" "github.com/rs/zerolog" "github.com/cs3org/reva/pkg/mentix/config" @@ -66,19 +67,17 @@ func (connector *LocalFileConnector) Activate(conf *config.Configuration, log *z func (connector *LocalFileConnector) RetrieveMeshData() (*meshdata.MeshData, error) { jsonData, err := ioutil.ReadFile(connector.filePath) if err != nil { - connector.log.Warn().Err(err).Msgf("unable to read file '%v'", connector.filePath) - return &meshdata.MeshData{}, nil + return nil, errors.Wrapf(err, "unable to read file '%v'", connector.filePath) } meshData := &meshdata.MeshData{} - if err := json.Unmarshal(jsonData, &meshData.Sites); err == nil { - // Enforce site types - connector.setSiteTypes(meshData) - meshData.InferMissingData() - } else { - connector.log.Warn().Err(err).Msgf("invalid file '%v'", connector.filePath) + if err := json.Unmarshal(jsonData, &meshData.Sites); err != nil { + return nil, errors.Wrapf(err, "invalid file '%v'", connector.filePath) } + connector.setSiteTypes(meshData) + meshData.InferMissingData() + return meshData, nil } diff --git a/pkg/mentix/exchangers/exchanger.go b/pkg/mentix/exchangers/exchanger.go index 908b2ba27d..341442b979 100644 --- a/pkg/mentix/exchangers/exchanger.go +++ b/pkg/mentix/exchangers/exchanger.go @@ -134,7 +134,7 @@ func (exchanger *BaseExchanger) cloneMeshData(clean bool) *meshdata.MeshData { cleanedSites := make([]*meshdata.Site, 0, len(meshDataClone.Sites)) for _, site := range meshDataClone.Sites { // Only keep authorized sites - if site.IsAuthorized() { + if site.IsAuthorized { cleanedSites = append(cleanedSites, site) } } diff --git a/pkg/mentix/mentix.go b/pkg/mentix/mentix.go index cb499ae870..856d857af2 100644 --- a/pkg/mentix/mentix.go +++ b/pkg/mentix/mentix.go @@ -208,8 +208,7 @@ func (mntx *Mentix) tick(updateTimestamp *time.Time) { if meshDataUpdated || time.Since(*updateTimestamp) >= mntx.updateInterval { // Retrieve and update the mesh data; if the importers modified any data, these changes will // be reflected automatically here - meshDataSet, err := mntx.retrieveMeshDataSet() - if err == nil { + if meshDataSet, err := mntx.retrieveMeshDataSet(); err == nil { if err := mntx.applyMeshDataSet(meshDataSet); err != nil { mntx.log.Err(err).Msg("failed to apply mesh data") } @@ -244,10 +243,11 @@ func (mntx *Mentix) retrieveMeshDataSet() (meshdata.Map, error) { for _, connector := range mntx.connectors.Connectors { meshData, err := connector.RetrieveMeshData() - if err != nil { - return nil, fmt.Errorf("retrieving mesh data from connector '%v' failed: %v", connector.GetName(), err) + if err == nil { + meshDataSet[connector.GetID()] = meshData + } else { + mntx.log.Err(err).Msgf("retrieving mesh data from connector '%v' failed", connector.GetName()) } - meshDataSet[connector.GetID()] = meshData } return meshDataSet, nil diff --git a/pkg/mentix/meshdata/site.go b/pkg/mentix/meshdata/site.go index e48ab6c363..a6fdae8f42 100644 --- a/pkg/mentix/meshdata/site.go +++ b/pkg/mentix/meshdata/site.go @@ -39,7 +39,9 @@ type SiteType int // Site represents a single site managed by Mentix. type Site struct { - Type SiteType `json:"-"` + // Internal settings + Type SiteType `json:"-"` + IsAuthorized bool `json:"-"` ID string Name string @@ -116,6 +118,8 @@ func (site *Site) Verify() error { // InferMissingData infers missing data from other data where possible. func (site *Site) InferMissingData() { // Infer missing data + site.IsAuthorized = site.getAuthorizationStatus() + if site.Homepage == "" { site.Homepage = fmt.Sprintf("http://www.%v", site.Domain) } else if site.Domain == "" { @@ -130,9 +134,7 @@ func (site *Site) InferMissingData() { } } -// IsAuthorized checks whether the site is authorized. ScienceMesh are always authorized, while for community sites, -// the accounts service is queried. -func (site *Site) IsAuthorized() bool { +func (site *Site) getAuthorizationStatus() bool { // ScienceMesh sites are always authorized if site.Type == SiteTypeScienceMesh { return true