Files
vikunja/pkg/modules/auth/openid/cron.go
kolaente 05349ddb5c feat!: config for auth providers now use a map instead of an array
The config values for openid providers now use a map with the provider as key instead of an array. For example before:

auth:
  openid:
    providers:
      - name: foo
        clientid: ...

now becomes:

auth:
  openid:
    providers:
      foo:
        clientid: ...

This allows us to read values for openid providers from files using the same syntax as everywhere and makes the configuration more predictable. It also allows configuring providers through env variables, though it is still required to set at least one value via the config file because Vikunja won't discover the provider otherwise.
2024-11-18 10:34:30 +01:00

73 lines
2.0 KiB
Go

// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-present Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public Licensee as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public Licensee for more details.
//
// You should have received a copy of the GNU Affero General Public Licensee
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package openid
import (
"code.vikunja.io/api/pkg/cron"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/models"
"xorm.io/builder"
"xorm.io/xorm"
)
func RemoveEmptySSOTeams(s *xorm.Session) (err error) {
teams := []*models.Team{}
err = s.
Where(
builder.NotIn("id", builder.Expr("select team_members.team_id from team_members")),
builder.Or(builder.Neq{"oidc_id": ""}, builder.NotNull{"oidc_id"}),
).
Find(&teams)
if err != nil {
return err
}
if len(teams) == 0 {
return nil
}
teamIDs := make([]int64, 0, len(teams))
for _, team := range teams {
teamIDs = append(teamIDs, team.ID)
}
log.Debugf("Deleting empty teams: %v", teamIDs)
_, err = s.In("id", teamIDs).Delete(&models.Team{})
return err
}
func RegisterEmptyOpenIDTeamCleanupCron() {
const logPrefix = "[Empty openid Team Cleanup Cron] "
err := cron.Schedule("* * * * *", func() {
s := db.NewSession()
defer s.Close()
err := RemoveEmptySSOTeams(s)
if err != nil {
log.Errorf(logPrefix+"Error removing empty openid team: %s", err)
return
}
})
if err != nil {
log.Fatalf("Could not register empty openid teams cleanup cron: %s", err)
}
}