From f77697f50147f34aad34fd13aab85f335f6a9746 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 8 Feb 2023 16:46:13 +0100 Subject: mailing list: ability to add guest users --- admin.go | 62 +++++++++++++++++++++++++++++++++++++-- main.go | 16 +++++----- templates/admin_create.html | 25 ++++++++++------ templates/admin_mailing.html | 2 +- templates/admin_mailing_list.html | 62 +++++++++++++++++++++++++++++++++------ templates/layout.html | 2 +- 6 files changed, 139 insertions(+), 30 deletions(-) diff --git a/admin.go b/admin.go index b057d13..18d1fb2 100644 --- a/admin.go +++ b/admin.go @@ -164,6 +164,7 @@ type AdminMailingListTplData struct { MailingList *ldap.Entry Members EntryList PossibleNewMembers EntryList + AllowGuest bool Error string Success bool @@ -198,6 +199,60 @@ func handleAdminMailingList(w http.ResponseWriter, r *http.Request) { } else { dSuccess = true } + } else if action == "add-external" { + mail := strings.Join(r.Form["mail"], "") + displayname := strings.Join(r.Form["displayname"], "") + + searchRequest := ldap.NewSearchRequest( + config.UserBaseDN, + ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, + fmt.Sprintf("(&(objectClass=organizationalPerson)(mail=%s))", mail), + []string{"dn", "displayname", "mail"}, + nil) + sr, err := login.conn.Search(searchRequest) + if err != nil { + dError = err.Error() + } else { + if len(sr.Entries) == 0 { + if config.MailingGuestsBaseDN != "" { + guestDn := fmt.Sprintf("%s=%s,%s", config.UserNameAttr, mail, config.MailingGuestsBaseDN) + req := ldap.NewAddRequest(guestDn, nil) + req.Attribute("objectclass", []string{"inetOrgPerson", "organizationalPerson", "person", "top"}) + req.Attribute("mail", []string{mail}) + if displayname != "" { + req.Attribute("displayname", []string{displayname}) + } + err := 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) + if err != nil { + dError = err.Error() + } else { + dSuccess = true + } + } + } else { + dError = "Adding guest users not supported, the user must already have an LDAP account." + } + } else if len(sr.Entries) == 1 { + modify_request := ldap.NewModifyRequest(dn, nil) + modify_request.Add("member", []string{sr.Entries[0].DN}) + + err := login.conn.Modify(modify_request) + if err != nil { + dError = err.Error() + } else { + dSuccess = true + } + } else { + dError = fmt.Sprintf("Multiple users exist with email address %s", mail) + } + } } else if action == "delete-member" { member := strings.Join(r.Form["member"], "") modify_request := ldap.NewModifyRequest(dn, nil) @@ -217,7 +272,7 @@ func handleAdminMailingList(w http.ResponseWriter, r *http.Request) { dn, ldap.ScopeBaseObject, ldap.NeverDerefAliases, 0, 0, false, fmt.Sprintf("(objectclass=groupOfNames)"), - []string{"dn", config.MailingNameAttr, "member"}, + []string{"dn", config.MailingNameAttr, "member", "description"}, nil) sr, err := login.conn.Search(searchRequest) @@ -274,6 +329,7 @@ func handleAdminMailingList(w http.ResponseWriter, r *http.Request) { MailingList: ml, Members: members, PossibleNewMembers: possibleNewMembers, + AllowGuest: config.MailingGuestsBaseDN != "", Error: dError, Success: dSuccess, @@ -785,7 +841,7 @@ func handleAdminCreate(w http.ResponseWriter, r *http.Request) { data.IdType = config.UserNameAttr data.StructuralObjectClass = "inetOrgPerson" data.ObjectClass = "inetOrgPerson\norganizationalPerson\nperson\ntop" - } else if template == "group" { + } else if template == "group" || template == "ml" { data.IdType = config.UserNameAttr data.StructuralObjectClass = "groupOfNames" data.ObjectClass = "groupOfNames\ntop" @@ -842,7 +898,7 @@ func handleAdminCreate(w http.ResponseWriter, r *http.Request) { if err != nil { data.Error = err.Error() } else { - if super_dn == config.MailingBaseDN && data.IdType == config.MailingNameAttr { + if template == "ml" { http.Redirect(w, r, "/admin/mailing/"+data.IdValue, http.StatusFound) } else { http.Redirect(w, r, "/admin/ldap/"+dn, http.StatusFound) diff --git a/main.go b/main.go index 5577784..31d5ac3 100644 --- a/main.go +++ b/main.go @@ -23,13 +23,15 @@ type ConfigFile struct { LdapServerAddr string `json:"ldap_server_addr"` LdapTLS bool `json:"ldap_tls"` - BaseDN string `json:"base_dn"` - UserBaseDN string `json:"user_base_dn"` - UserNameAttr string `json:"user_name_attr"` - GroupBaseDN string `json:"group_base_dn"` - GroupNameAttr string `json:"group_name_attr"` - MailingBaseDN string `json:"mailing_list_base_dn"` - MailingNameAttr string `json:"mailing_list_name_attr"` + BaseDN string `json:"base_dn"` + UserBaseDN string `json:"user_base_dn"` + UserNameAttr string `json:"user_name_attr"` + GroupBaseDN string `json:"group_base_dn"` + GroupNameAttr string `json:"group_name_attr"` + + MailingBaseDN string `json:"mailing_list_base_dn"` + MailingNameAttr string `json:"mailing_list_name_attr"` + MailingGuestsBaseDN string `json:"mailing_list_guest_user_base_dn"` InvitationBaseDN string `json:"invitation_base_dn"` InvitationNameAttr string `json:"invitation_name_attr"` diff --git a/templates/admin_create.html b/templates/admin_create.html index 9971aaf..1ea6fee 100644 --- a/templates/admin_create.html +++ b/templates/admin_create.html @@ -30,33 +30,40 @@ --> + {{if eq .Template "ml"}} +
+ + +
+ {{else}} +
+ + +
+ {{end}}
- - -
-
- +
{{ if eq .Template "user" }}
- +
{{ else }}
- +
{{ end }}
- +
- +
diff --git a/templates/admin_mailing.html b/templates/admin_mailing.html index d81545f..16bdd61 100644 --- a/templates/admin_mailing.html +++ b/templates/admin_mailing.html @@ -4,7 +4,7 @@

Mailing lists

- Nouvelle mailing list + Nouvelle mailing list Menu principal
diff --git a/templates/admin_mailing_list.html b/templates/admin_mailing_list.html index c5903b6..1b947b2 100644 --- a/templates/admin_mailing_list.html +++ b/templates/admin_mailing_list.html @@ -20,6 +20,10 @@ {{end}} +{{with $desc := .MailingList.GetAttributeValue "description"}}{{if $desc}} +

{{$desc}}

+{{end}}{{end}} + @@ -46,16 +50,20 @@ {{end}} {{end}} + {{if not .Members}} + + {{end}}
Adresse
(aucun abonné)
-
-
Ajouter un destinataire
-
- -
-
Utilisateur existant : -
+
+
Ajouter un destinataire
+ +
+ + +
+
Utilisateur existant :
@@ -67,7 +75,43 @@
- + +
+
+ + + {{if .AllowGuest}} +
+
OU
+
+ +
+ +
+
E-mail :
+
+
- +
+
+
+
+
Nom (optionnel) :
+
+ +
+
+ +
+
+
+ + Si un utilisateur existe déjà avec l'email spécifiée, celui-ci sera ajouté à la liste. + Sinon, un utilisateur invité sera créé. + +
+ + {{end}} +
+ {{end}} diff --git a/templates/layout.html b/templates/layout.html index 212ce5e..0a887ce 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -6,7 +6,7 @@ - {{template "title"}} Guichet + {{template "title" .}} Guichet
-- cgit v1.2.3