diff options
author | MrArmonius <mrarmonius@gmail.com> | 2021-07-12 17:08:56 +0200 |
---|---|---|
committer | MrArmonius <mrarmonius@gmail.com> | 2021-07-19 15:59:26 +0200 |
commit | 0ceca4ab387eeb36dcf1d033900f1f98279893c1 (patch) | |
tree | 1136de36be78342f556840a6cd9e0d54fc95f5ca | |
parent | bfeccfe191d6e6ed518452663b11fd665f785460 (diff) | |
download | guichet-LDAP_Page_Add_DataList.tar.gz guichet-LDAP_Page_Add_DataList.zip |
Add Datalist to help search users or group in LDAP admin pageLDAP_Page_Add_DataList
-rw-r--r-- | admin.go | 109 | ||||
-rw-r--r-- | templates/admin_ldap.html | 14 |
2 files changed, 75 insertions, 48 deletions
@@ -132,6 +132,8 @@ type AdminLDAPTplData struct { HasGroups bool Groups []EntryName + ListMemGro map[string]string + Error string Success bool } @@ -360,32 +362,30 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) { } members := []EntryName{} - if len(members_dn) > 0 { - mapDnToName := make(map[string]string) - searchRequest = ldap.NewSearchRequest( - config.UserBaseDN, - ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, - fmt.Sprintf("(objectClass=organizationalPerson)"), - []string{"dn", "displayname", "description"}, - nil) - sr, err := login.conn.Search(searchRequest) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - for _, ent := range sr.Entries { - mapDnToName[ent.DN] = ent.GetAttributeValue("displayname") - if mapDnToName[ent.DN] == "" { - mapDnToName[ent.DN] = ent.GetAttributeValue("description") - } - } - for _, memdn := range members_dn { - members = append(members, EntryName{ - DN: memdn, - Name: mapDnToName[memdn], - }) + mapDnToNameMember := make(map[string]string) + searchRequest = ldap.NewSearchRequest( + config.UserBaseDN, + ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, + fmt.Sprintf("(objectClass=organizationalPerson)"), + []string{"dn", "displayname", "description"}, + nil) + sr, err = login.conn.Search(searchRequest) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + for _, ent := range sr.Entries { + mapDnToNameMember[ent.DN] = ent.GetAttributeValue("displayname") + if mapDnToNameMember[ent.DN] == "" { + mapDnToNameMember[ent.DN] = ent.GetAttributeValue("description") } } + for _, memdn := range members_dn { + members = append(members, EntryName{ + DN: memdn, + Name: mapDnToNameMember[memdn], + }) + } groups_dn := []string{} if gp, ok := props["memberof"]; ok { @@ -394,28 +394,26 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) { } groups := []EntryName{} - if len(groups_dn) > 0 { - mapDnToName := make(map[string]string) - searchRequest = ldap.NewSearchRequest( - config.GroupBaseDN, - ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, - fmt.Sprintf("(objectClass=groupOfNames)"), - []string{"dn", "description"}, - nil) - sr, err := login.conn.Search(searchRequest) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - for _, ent := range sr.Entries { - mapDnToName[ent.DN] = ent.GetAttributeValue("description") - } - for _, grpdn := range groups_dn { - groups = append(groups, EntryName{ - DN: grpdn, - Name: mapDnToName[grpdn], - }) - } + mapDnToNameGroup := make(map[string]string) + searchRequest = ldap.NewSearchRequest( + config.GroupBaseDN, + ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, + fmt.Sprintf("(objectClass=groupOfNames)"), + []string{"dn", "description"}, + nil) + sr, err = login.conn.Search(searchRequest) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + for _, ent := range sr.Entries { + mapDnToNameGroup[ent.DN] = ent.GetAttributeValue("description") + } + for _, grpdn := range groups_dn { + groups = append(groups, EntryName{ + DN: grpdn, + Name: mapDnToNameGroup[grpdn], + }) } // Get children @@ -465,6 +463,23 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) { } } + //Get the members or groups existing + var ExistList map[string]string + if hasMembers { + ExistList = mapDnToNameMember + //Suppress the members already in the group + for _, value := range members { + delete(ExistList, value.DN) + } + } else if hasGroups { + ExistList = mapDnToNameGroup + //Delete the groups where the user is already a member + for _, value := range groups { + delete(ExistList, value.DN) + } + } + + templateAdminLDAP.Execute(w, &AdminLDAPTplData{ DN: dn, @@ -479,6 +494,8 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) { HasGroups: len(groups) > 0 || hasGroups, Groups: groups, + ListMemGro: ExistList, + Error: dError, Success: dSuccess, }) diff --git a/templates/admin_ldap.html b/templates/admin_ldap.html index 7b274dc..d1aab29 100644 --- a/templates/admin_ldap.html +++ b/templates/admin_ldap.html @@ -146,7 +146,12 @@ <div class="col-md-3"><strong>Ajouter au groupe :</strong> </div> <div class="col-md-5"> - <input class="form-control" type="text" name="values" placeholder="Utilisateur..." /> + <input class="form-control" type="text" list="users" name="values" placeholder="Utilisateur..." /> + <datalist id="users"> + {{ range $key, $value := .ListMemGro}} + <option value={{$key}}>{{$value}}</option> + {{end}} + </datalist> </div> <div class="col-md-2"> <input type="submit" value="Ajouter" class="form-control btn btn-success btn-sm" /> @@ -182,7 +187,12 @@ <div class="col-md-3"><strong>Nouveau groupe :</strong> </div> <div class="col-md-5"> - <input class="form-control" type="text" name="group" placeholder="Groupe..." /> + <input class="form-control" list="groups" type="text" name="group" placeholder="Groupe..." /> + <datalist id="groups"> + {{ range $key, $value := .ListMemGro}} + <option value={{$key}}>{{$value}}</option> + {{end}} + </datalist> </div> <div class="col-md-2"> <input type="submit" value="Ajouter" class="form-control btn btn-success btn-sm" /> |