aboutsummaryrefslogtreecommitdiff
path: root/admin.go
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2023-09-25 15:35:54 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2023-09-25 15:35:54 +0200
commitc06f52837e5b4aab5335e5a66885c48c24a148a2 (patch)
treed519f4e53c08e9de2fc3c30606031960c53429fe /admin.go
parentd0ed765be72f80034fa530ba037e488c35abdd9e (diff)
downloadguichet-c06f52837e5b4aab5335e5a66885c48c24a148a2.tar.gz
guichet-c06f52837e5b4aab5335e5a66885c48c24a148a2.zip
WIP refactor (broken templates)
Diffstat (limited to 'admin.go')
-rw-r--r--admin.go98
1 files changed, 49 insertions, 49 deletions
diff --git a/admin.go b/admin.go
index 18d1fb2..3c805fb 100644
--- a/admin.go
+++ b/admin.go
@@ -11,18 +11,18 @@ import (
"github.com/gorilla/mux"
)
-func checkAdminLogin(w http.ResponseWriter, r *http.Request) *LoginStatus {
- login := checkLogin(w, r)
- if login == nil {
+func checkAdminLogin(w http.ResponseWriter, r *http.Request) *LoggedUser {
+ user := RequireUserHtml(w, r)
+ if user == nil {
return nil
}
- if !login.CanAdmin {
+ if !user.Capabilities.CanAdmin {
http.Error(w, "Not authorized to perform administrative operations.", http.StatusUnauthorized)
return nil
}
- return login
+ return user
}
type EntryList []*ldap.Entry
@@ -40,7 +40,7 @@ func (d EntryList) Less(i, j int) bool {
}
type AdminUsersTplData struct {
- Login *LoginStatus
+ User *LoggedUser
UserNameAttr string
UserBaseDN string
Users EntryList
@@ -49,8 +49,8 @@ type AdminUsersTplData struct {
func handleAdminUsers(w http.ResponseWriter, r *http.Request) {
templateAdminUsers := getTemplate("admin_users.html")
- login := checkAdminLogin(w, r)
- if login == nil {
+ user := checkAdminLogin(w, r)
+ if user == nil {
return
}
@@ -61,14 +61,14 @@ func handleAdminUsers(w http.ResponseWriter, r *http.Request) {
[]string{config.UserNameAttr, "dn", "displayname", "givenname", "sn", "mail"},
nil)
- sr, err := login.conn.Search(searchRequest)
+ sr, err := user.Login.conn.Search(searchRequest)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
data := &AdminUsersTplData{
- Login: login,
+ User: user,
UserNameAttr: config.UserNameAttr,
UserBaseDN: config.UserBaseDN,
Users: EntryList(sr.Entries),
@@ -79,7 +79,7 @@ func handleAdminUsers(w http.ResponseWriter, r *http.Request) {
}
type AdminGroupsTplData struct {
- Login *LoginStatus
+ User *LoggedUser
GroupNameAttr string
GroupBaseDN string
Groups EntryList
@@ -88,8 +88,8 @@ type AdminGroupsTplData struct {
func handleAdminGroups(w http.ResponseWriter, r *http.Request) {
templateAdminGroups := getTemplate("admin_groups.html")
- login := checkAdminLogin(w, r)
- if login == nil {
+ user := checkAdminLogin(w, r)
+ if user == nil {
return
}
@@ -100,14 +100,14 @@ func handleAdminGroups(w http.ResponseWriter, r *http.Request) {
[]string{config.GroupNameAttr, "dn", "description"},
nil)
- sr, err := login.conn.Search(searchRequest)
+ sr, err := user.Login.conn.Search(searchRequest)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
data := &AdminGroupsTplData{
- Login: login,
+ User: user,
GroupNameAttr: config.GroupNameAttr,
GroupBaseDN: config.GroupBaseDN,
Groups: EntryList(sr.Entries),
@@ -118,7 +118,7 @@ func handleAdminGroups(w http.ResponseWriter, r *http.Request) {
}
type AdminMailingTplData struct {
- Login *LoginStatus
+ User *LoggedUser
MailingNameAttr string
MailingBaseDN string
MailingLists EntryList
@@ -127,8 +127,8 @@ type AdminMailingTplData struct {
func handleAdminMailing(w http.ResponseWriter, r *http.Request) {
templateAdminMailing := getTemplate("admin_mailing.html")
- login := checkAdminLogin(w, r)
- if login == nil {
+ user := checkAdminLogin(w, r)
+ if user == nil {
return
}
@@ -139,14 +139,14 @@ func handleAdminMailing(w http.ResponseWriter, r *http.Request) {
[]string{config.MailingNameAttr, "dn", "description"},
nil)
- sr, err := login.conn.Search(searchRequest)
+ sr, err := user.Login.conn.Search(searchRequest)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
data := &AdminMailingTplData{
- Login: login,
+ User: user,
MailingNameAttr: config.MailingNameAttr,
MailingBaseDN: config.MailingBaseDN,
MailingLists: EntryList(sr.Entries),
@@ -157,7 +157,7 @@ func handleAdminMailing(w http.ResponseWriter, r *http.Request) {
}
type AdminMailingListTplData struct {
- Login *LoginStatus
+ User *LoggedUser
MailingNameAttr string
MailingBaseDN string
@@ -173,8 +173,8 @@ type AdminMailingListTplData struct {
func handleAdminMailingList(w http.ResponseWriter, r *http.Request) {
templateAdminMailingList := getTemplate("admin_mailing_list.html")
- login := checkAdminLogin(w, r)
- if login == nil {
+ user := checkAdminLogin(w, r)
+ if user == nil {
return
}
@@ -193,7 +193,7 @@ func handleAdminMailingList(w http.ResponseWriter, r *http.Request) {
modify_request := ldap.NewModifyRequest(dn, nil)
modify_request.Add("member", []string{member})
- err := login.conn.Modify(modify_request)
+ err := user.Login.conn.Modify(modify_request)
if err != nil {
dError = err.Error()
} else {
@@ -209,7 +209,7 @@ func handleAdminMailingList(w http.ResponseWriter, r *http.Request) {
fmt.Sprintf("(&(objectClass=organizationalPerson)(mail=%s))", mail),
[]string{"dn", "displayname", "mail"},
nil)
- sr, err := login.conn.Search(searchRequest)
+ sr, err := user.Login.conn.Search(searchRequest)
if err != nil {
dError = err.Error()
} else {
@@ -222,14 +222,14 @@ func handleAdminMailingList(w http.ResponseWriter, r *http.Request) {
if displayname != "" {
req.Attribute("displayname", []string{displayname})
}
- err := login.conn.Add(req)
+ err := user.Login.conn.Add(req)
if err != nil {
dError = err.Error()
} else {
modify_request := ldap.NewModifyRequest(dn, nil)
modify_request.Add("member", []string{guestDn})
- err := login.conn.Modify(modify_request)
+ err := user.Login.conn.Modify(modify_request)
if err != nil {
dError = err.Error()
} else {
@@ -243,7 +243,7 @@ func handleAdminMailingList(w http.ResponseWriter, r *http.Request) {
modify_request := ldap.NewModifyRequest(dn, nil)
modify_request.Add("member", []string{sr.Entries[0].DN})
- err := login.conn.Modify(modify_request)
+ err := user.Login.conn.Modify(modify_request)
if err != nil {
dError = err.Error()
} else {
@@ -258,7 +258,7 @@ func handleAdminMailingList(w http.ResponseWriter, r *http.Request) {
modify_request := ldap.NewModifyRequest(dn, nil)
modify_request.Delete("member", []string{member})
- err := login.conn.Modify(modify_request)
+ err := user.Login.conn.Modify(modify_request)
if err != nil {
dError = err.Error()
} else {
@@ -275,7 +275,7 @@ func handleAdminMailingList(w http.ResponseWriter, r *http.Request) {
[]string{"dn", config.MailingNameAttr, "member", "description"},
nil)
- sr, err := login.conn.Search(searchRequest)
+ sr, err := user.Login.conn.Search(searchRequest)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -307,7 +307,7 @@ func handleAdminMailingList(w http.ResponseWriter, r *http.Request) {
fmt.Sprintf("(objectClass=organizationalPerson)"),
[]string{"dn", "displayname", "mail"},
nil)
- sr, err = login.conn.Search(searchRequest)
+ sr, err = user.Login.conn.Search(searchRequest)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -322,7 +322,7 @@ func handleAdminMailingList(w http.ResponseWriter, r *http.Request) {
}
data := &AdminMailingListTplData{
- Login: login,
+ User: user,
MailingNameAttr: config.MailingNameAttr,
MailingBaseDN: config.MailingBaseDN,
@@ -394,8 +394,8 @@ type PropValues struct {
func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
templateAdminLDAP := getTemplate("admin_ldap.html")
- login := checkAdminLogin(w, r)
- if login == nil {
+ user := checkAdminLogin(w, r)
+ if user == nil {
return
}
@@ -445,7 +445,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
modify_request := ldap.NewModifyRequest(dn, nil)
modify_request.Replace(attr, values_filtered)
- err := login.conn.Modify(modify_request)
+ err := user.Login.conn.Modify(modify_request)
if err != nil {
dError = err.Error()
} else {
@@ -466,7 +466,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
modify_request := ldap.NewModifyRequest(dn, nil)
modify_request.Add(attr, values_filtered)
- err := login.conn.Modify(modify_request)
+ err := user.Login.conn.Modify(modify_request)
if err != nil {
dError = err.Error()
} else {
@@ -478,7 +478,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
modify_request := ldap.NewModifyRequest(dn, nil)
modify_request.Replace(attr, []string{})
- err := login.conn.Modify(modify_request)
+ err := user.Login.conn.Modify(modify_request)
if err != nil {
dError = err.Error()
} else {
@@ -489,7 +489,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
modify_request := ldap.NewModifyRequest(group, nil)
modify_request.Delete("member", []string{dn})
- err := login.conn.Modify(modify_request)
+ err := user.Login.conn.Modify(modify_request)
if err != nil {
dError = err.Error()
} else {
@@ -500,7 +500,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
modify_request := ldap.NewModifyRequest(group, nil)
modify_request.Add("member", []string{dn})
- err := login.conn.Modify(modify_request)
+ err := user.Login.conn.Modify(modify_request)
if err != nil {
dError = err.Error()
} else {
@@ -511,7 +511,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
modify_request := ldap.NewModifyRequest(dn, nil)
modify_request.Delete("member", []string{member})
- err := login.conn.Modify(modify_request)
+ err := user.Login.conn.Modify(modify_request)
if err != nil {
dError = err.Error()
} else {
@@ -519,7 +519,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
}
} else if action == "delete-object" {
del_request := ldap.NewDelRequest(dn, nil)
- err := login.conn.Del(del_request)
+ err := user.Login.conn.Del(del_request)
if err != nil {
dError = err.Error()
} else {
@@ -537,7 +537,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
[]string{},
nil)
- sr, err := login.conn.Search(searchRequest)
+ sr, err := user.Login.conn.Search(searchRequest)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -621,7 +621,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
fmt.Sprintf("(objectClass=organizationalPerson)"),
[]string{"dn", "displayname", "description"},
nil)
- sr, err = login.conn.Search(searchRequest)
+ sr, err = user.Login.conn.Search(searchRequest)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -675,7 +675,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
fmt.Sprintf("(objectClass=groupOfNames)"),
[]string{"dn", "description"},
nil)
- sr, err = login.conn.Search(searchRequest)
+ sr, err = user.Login.conn.Search(searchRequest)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -719,7 +719,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
[]string{"dn", "displayname", "description"},
nil)
- sr, err = login.conn.Search(searchRequest)
+ sr, err = user.Login.conn.Search(searchRequest)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -787,8 +787,8 @@ type CreateData struct {
func handleAdminCreate(w http.ResponseWriter, r *http.Request) {
templateAdminCreate := getTemplate("admin_create.html")
- login := checkAdminLogin(w, r)
- if login == nil {
+ user := checkAdminLogin(w, r)
+ if user == nil {
return
}
@@ -803,7 +803,7 @@ func handleAdminCreate(w http.ResponseWriter, r *http.Request) {
[]string{},
nil)
- sr, err := login.conn.Search(searchRequest)
+ sr, err := user.Login.conn.Search(searchRequest)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -894,7 +894,7 @@ func handleAdminCreate(w http.ResponseWriter, r *http.Request) {
req.Attribute("description", []string{data.Description})
}
- err := login.conn.Add(req)
+ err := user.Login.conn.Add(req)
if err != nil {
data.Error = err.Error()
} else {