diff options
author | MrArmonius <mrarmonius@gmail.com> | 2021-07-26 23:01:48 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-08-16 12:54:08 +0200 |
commit | 815e9bfe2a912f0804de4882a11fd349b2f4d796 (patch) | |
tree | 0e9abbaef84d8ef900f217984808821c8234c817 | |
parent | cf4918e901da8f2c388eebd33a500bf737943685 (diff) | |
download | guichet-815e9bfe2a912f0804de4882a11fd349b2f4d796.tar.gz guichet-815e9bfe2a912f0804de4882a11fd349b2f4d796.zip |
Add Description and visibility attributes
Modify in profil's page your description and your choice about show you
on the directory. The default visibility's choice is false. Tthe
description is empty by default.
In the directory, a new row exist to show the description.
Adapt view in column Description
I use the style `word-break: break-all;` on the `<td>`
-rw-r--r-- | directory.go | 10 | ||||
-rw-r--r-- | main.go | 2 | ||||
-rw-r--r-- | profile.go | 8 | ||||
-rw-r--r-- | static/javascript/search.js | 4 | ||||
-rw-r--r-- | templates/directory.html | 1 | ||||
-rw-r--r-- | templates/profile.html | 12 |
6 files changed, 32 insertions, 5 deletions
diff --git a/directory.go b/directory.go index 6a7ade2..6c1ab29 100644 --- a/directory.go +++ b/directory.go @@ -25,6 +25,7 @@ type SearchResult struct { Identifiant string `json:"identifiant"` Name string `json:"name"` Email string `json:"email"` + Description string `json:"description"` DN string `json:"dn"` } @@ -47,12 +48,12 @@ func handleSearch(w http.ResponseWriter, r *http.Request) { return } - //Search value with ldap and filter + //Search values with ldap and filter searchRequest := ldap.NewSearchRequest( config.UserBaseDN, ldap.ScopeSingleLevel, ldap.NeverDerefAliases, 0, 0, false, - "(&(objectclass=organizationalPerson)(visibility=all))", - []string{config.UserNameAttr, "displayname", "mail"}, + "(&(objectclass=organizationalPerson)(visibility=on))", + []string{config.UserNameAttr, "displayname", "mail", "description"}, nil) sr, err := login.conn.Search(searchRequest) @@ -71,6 +72,7 @@ func handleSearch(w http.ResponseWriter, r *http.Request) { Identifiant: values.GetAttributeValue("cn"), Name: values.GetAttributeValue("displayname"), Email: values.GetAttributeValue("email"), + Description: values.GetAttributeValue("description"), DN: values.DN, }), } @@ -78,7 +80,7 @@ func handleSearch(w http.ResponseWriter, r *http.Request) { } - //Convert interface to uint32 with Type Assertions and not a simple convert + //Convert interface to uint32 with Type Assertions and not a simple convert for messageID if val_Raw, ok_raw := session.Values["MessageID"]; ok_raw { if val, ok := val_Raw.(uint32); ok { val += 1 @@ -244,7 +244,7 @@ func checkLogin(w http.ResponseWriter, r *http.Request) *LoginStatus { login_info.DN, ldap.ScopeBaseObject, ldap.NeverDerefAliases, 0, 0, false, requestKind, - []string{"dn", "displayname", "givenname", "sn", "mail", "memberof"}, + []string{"dn", "displayname", "givenname", "sn", "mail", "memberof", "visibility", "description"}, nil) sr, err := l.Search(searchRequest) @@ -16,6 +16,8 @@ type ProfileTplData struct { DisplayName string GivenName string Surname string + Visibility string + Description string } func handleProfile(w http.ResponseWriter, r *http.Request) { @@ -36,6 +38,8 @@ func handleProfile(w http.ResponseWriter, r *http.Request) { data.DisplayName = login.UserEntry.GetAttributeValue("displayname") data.GivenName = login.UserEntry.GetAttributeValue("givenname") data.Surname = login.UserEntry.GetAttributeValue("sn") + data.Visibility = login.UserEntry.GetAttributeValue("visibility") + data.Description = login.UserEntry.GetAttributeValue("description") if r.Method == "POST" { r.ParseForm() @@ -43,11 +47,15 @@ func handleProfile(w http.ResponseWriter, r *http.Request) { data.DisplayName = strings.TrimSpace(strings.Join(r.Form["display_name"], "")) data.GivenName = strings.TrimSpace(strings.Join(r.Form["given_name"], "")) data.Surname = strings.TrimSpace(strings.Join(r.Form["surname"], "")) + data.Description = strings.Trim(strings.Join(r.Form["description"], ""), "") + data.Visibility = strings.TrimSpace(strings.Join(r.Form["visibility"], "")) modify_request := ldap.NewModifyRequest(login.Info.DN, nil) modify_request.Replace("displayname", []string{data.DisplayName}) modify_request.Replace("givenname", []string{data.GivenName}) modify_request.Replace("sn", []string{data.Surname}) + modify_request.Replace("description", []string{data.Description}) + modify_request.Replace("visibility", []string{data.Visibility}) err := login.conn.Modify(modify_request) if err != nil { diff --git a/static/javascript/search.js b/static/javascript/search.js index 7675c0e..9e078be 100644 --- a/static/javascript/search.js +++ b/static/javascript/search.js @@ -23,9 +23,13 @@ function searchDirectory() { var identifiant = row.insertCell(0); var name = row.insertCell(1); var email = row.insertCell(2); + var description = row.insertCell(3); + description.setAttribute("style", "word-break: break-all;"); + identifiant.innerHTML = `<a href="/admin/ldap/${jsonResponse.search[i].dn}">${jsonResponse.search[i].identifiant}</a>` name.innerHTML = jsonResponse.search[i].name email.innerHTML = jsonResponse.search[i].email + description.innerHTML = `${jsonResponse.search[i].description}` } old_table.parentNode.replaceChild(table, old_table) diff --git a/templates/directory.html b/templates/directory.html index bdc587f..e91354d 100644 --- a/templates/directory.html +++ b/templates/directory.html @@ -22,6 +22,7 @@ <th scope="col">Identifiant</th> <th scope="col">Nom complet</th> <th scope="col">Email</th> + <th scope="col">Description</th> </thead> <tbody id="users"> diff --git a/templates/profile.html b/templates/profile.html index bfd79cd..5445d6d 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -37,6 +37,18 @@ <label for="surname">Nom de famille:</label> <input type="text" id="surname" name="surname" class="form-control" value="{{ .Surname }}" /> </div> + <div class="form-group"> + <label for="description">Description (180 caractères maximum)</label> + <textarea id="description" name="description" class="form-control" maxlength="180">{{ .Description }}</textarea> + </div> + <div class="form-group form-check"> + {{if .Visibility}} + <input class="form-check-input" name="visibility" type="checkbox" id="visibility" checked> + {{else}} + <input class="form-check-input" name="visibility" type="checkbox" id="visibility"> + {{end}} + <label class="form-check-label" for="visibility">Apparaît sur l'annuaire</label> + </div> <button type="submit" class="btn btn-primary">Enregistrer les modifications</button> </form> {{end}} |