Fix ClusterCockpit/cc-frontend#31: Add user role to LDAP users

This commit is contained in:
Lou Knauer 2022-05-02 11:59:24 +02:00
parent f82e78eaeb
commit d67f5dd23b
2 changed files with 4 additions and 4 deletions

View File

@ -206,13 +206,13 @@ func (auth *Authentication) FetchUsers(viaLdap, notJustUser bool) ([]*User, erro
q := sq.Select("username", "name", "email", "roles").From("user")
if !viaLdap {
if notJustUser {
q = q.Where("ldap = 0 OR roles != '[\"user\"]'")
q = q.Where("ldap = 0 OR (roles != '[\"user\"]' AND roles != '[]')")
} else {
q = q.Where("ldap = 0")
}
} else {
if notJustUser {
q = q.Where("ldap = 1 OR roles != '[\"user\"]'")
q = q.Where("ldap = 1 OR (roles != '[\"user\"]' AND roles != '[]')")
} else {
q = q.Where("ldap = 1")
}

View File

@ -149,9 +149,9 @@ func (auth *Authentication) SyncWithLDAP(deleteOldUsers bool) error {
}
} else if where == IN_LDAP {
name := newnames[username]
log.Infof("ldap-sync: add %#v (name: %#v, roles: [], ldap: true)", username, name)
log.Infof("ldap-sync: add %#v (name: %#v, roles: [user], ldap: true)", username, name)
if _, err := auth.db.Exec(`INSERT INTO user (username, ldap, name, roles) VALUES (?, ?, ?, ?)`,
username, 1, name, "[]"); err != nil {
username, 1, name, "[\""+RoleUser+"\"]"); err != nil {
return err
}
}