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>`
This commit is contained in:
MrArmonius 2021-07-26 23:01:48 +02:00 committed by Alex Auvolat
parent cf4918e901
commit 815e9bfe2a
No known key found for this signature in database
GPG key ID: EDABF9711E244EB1
6 changed files with 32 additions and 5 deletions

View file

@ -25,6 +25,7 @@ type SearchResult struct {
Identifiant string `json:"identifiant"` Identifiant string `json:"identifiant"`
Name string `json:"name"` Name string `json:"name"`
Email string `json:"email"` Email string `json:"email"`
Description string `json:"description"`
DN string `json:"dn"` DN string `json:"dn"`
} }
@ -47,12 +48,12 @@ func handleSearch(w http.ResponseWriter, r *http.Request) {
return return
} }
//Search value with ldap and filter //Search values with ldap and filter
searchRequest := ldap.NewSearchRequest( searchRequest := ldap.NewSearchRequest(
config.UserBaseDN, config.UserBaseDN,
ldap.ScopeSingleLevel, ldap.NeverDerefAliases, 0, 0, false, ldap.ScopeSingleLevel, ldap.NeverDerefAliases, 0, 0, false,
"(&(objectclass=organizationalPerson)(visibility=all))", "(&(objectclass=organizationalPerson)(visibility=on))",
[]string{config.UserNameAttr, "displayname", "mail"}, []string{config.UserNameAttr, "displayname", "mail", "description"},
nil) nil)
sr, err := login.conn.Search(searchRequest) sr, err := login.conn.Search(searchRequest)
@ -71,6 +72,7 @@ func handleSearch(w http.ResponseWriter, r *http.Request) {
Identifiant: values.GetAttributeValue("cn"), Identifiant: values.GetAttributeValue("cn"),
Name: values.GetAttributeValue("displayname"), Name: values.GetAttributeValue("displayname"),
Email: values.GetAttributeValue("email"), Email: values.GetAttributeValue("email"),
Description: values.GetAttributeValue("description"),
DN: values.DN, 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_Raw, ok_raw := session.Values["MessageID"]; ok_raw {
if val, ok := val_Raw.(uint32); ok { if val, ok := val_Raw.(uint32); ok {
val += 1 val += 1

View file

@ -244,7 +244,7 @@ func checkLogin(w http.ResponseWriter, r *http.Request) *LoginStatus {
login_info.DN, login_info.DN,
ldap.ScopeBaseObject, ldap.NeverDerefAliases, 0, 0, false, ldap.ScopeBaseObject, ldap.NeverDerefAliases, 0, 0, false,
requestKind, requestKind,
[]string{"dn", "displayname", "givenname", "sn", "mail", "memberof"}, []string{"dn", "displayname", "givenname", "sn", "mail", "memberof", "visibility", "description"},
nil) nil)
sr, err := l.Search(searchRequest) sr, err := l.Search(searchRequest)

View file

@ -16,6 +16,8 @@ type ProfileTplData struct {
DisplayName string DisplayName string
GivenName string GivenName string
Surname string Surname string
Visibility string
Description string
} }
func handleProfile(w http.ResponseWriter, r *http.Request) { 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.DisplayName = login.UserEntry.GetAttributeValue("displayname")
data.GivenName = login.UserEntry.GetAttributeValue("givenname") data.GivenName = login.UserEntry.GetAttributeValue("givenname")
data.Surname = login.UserEntry.GetAttributeValue("sn") data.Surname = login.UserEntry.GetAttributeValue("sn")
data.Visibility = login.UserEntry.GetAttributeValue("visibility")
data.Description = login.UserEntry.GetAttributeValue("description")
if r.Method == "POST" { if r.Method == "POST" {
r.ParseForm() 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.DisplayName = strings.TrimSpace(strings.Join(r.Form["display_name"], ""))
data.GivenName = strings.TrimSpace(strings.Join(r.Form["given_name"], "")) data.GivenName = strings.TrimSpace(strings.Join(r.Form["given_name"], ""))
data.Surname = strings.TrimSpace(strings.Join(r.Form["surname"], "")) 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 := ldap.NewModifyRequest(login.Info.DN, nil)
modify_request.Replace("displayname", []string{data.DisplayName}) modify_request.Replace("displayname", []string{data.DisplayName})
modify_request.Replace("givenname", []string{data.GivenName}) modify_request.Replace("givenname", []string{data.GivenName})
modify_request.Replace("sn", []string{data.Surname}) 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) err := login.conn.Modify(modify_request)
if err != nil { if err != nil {

View file

@ -23,9 +23,13 @@ function searchDirectory() {
var identifiant = row.insertCell(0); var identifiant = row.insertCell(0);
var name = row.insertCell(1); var name = row.insertCell(1);
var email = row.insertCell(2); 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>` identifiant.innerHTML = `<a href="/admin/ldap/${jsonResponse.search[i].dn}">${jsonResponse.search[i].identifiant}</a>`
name.innerHTML = jsonResponse.search[i].name name.innerHTML = jsonResponse.search[i].name
email.innerHTML = jsonResponse.search[i].email email.innerHTML = jsonResponse.search[i].email
description.innerHTML = `${jsonResponse.search[i].description}`
} }
old_table.parentNode.replaceChild(table, old_table) old_table.parentNode.replaceChild(table, old_table)

View file

@ -22,6 +22,7 @@
<th scope="col">Identifiant</th> <th scope="col">Identifiant</th>
<th scope="col">Nom complet</th> <th scope="col">Nom complet</th>
<th scope="col">Email</th> <th scope="col">Email</th>
<th scope="col">Description</th>
</thead> </thead>
<tbody id="users"> <tbody id="users">

View file

@ -37,6 +37,18 @@
<label for="surname">Nom de famille:</label> <label for="surname">Nom de famille:</label>
<input type="text" id="surname" name="surname" class="form-control" value="{{ .Surname }}" /> <input type="text" id="surname" name="surname" class="form-control" value="{{ .Surname }}" />
</div> </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> <button type="submit" class="btn btn-primary">Enregistrer les modifications</button>
</form> </form>
{{end}} {{end}}