Ability to delete an object

This commit is contained in:
Alex 2020-02-09 23:20:44 +01:00
parent 54eb5d6239
commit 08a7ec3292
2 changed files with 48 additions and 20 deletions

View File

@ -128,6 +128,7 @@ type AdminLDAPTplData struct {
Children []Child
CanAddChild bool
Props map[string]*PropValues
CanDelete bool
HasMembers bool
Members []EntryName
@ -174,6 +175,27 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
dError := ""
dSuccess := false
// Build path
path := []PathItem{
PathItem{
DN: config.BaseDN,
Identifier: config.BaseDN,
Active: dn == config.BaseDN,
},
}
len_base_dn := len(strings.Split(config.BaseDN, ","))
dn_split := strings.Split(dn, ",")
dn_last_attr := strings.Split(dn_split[0], "=")[0]
for i := len_base_dn + 1; i <= len(dn_split); i++ {
path = append(path, PathItem{
DN: strings.Join(dn_split[len(dn_split)-i:len(dn_split)], ","),
Identifier: dn_split[len(dn_split)-i],
Active: i == len(dn_split),
})
}
// Handle modification operation
if r.Method == "POST" {
r.ParseForm()
action := strings.Join(r.Form["action"], "")
@ -266,29 +288,18 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
} else {
dSuccess = true
}
} else if action == "delete-object" {
del_request := ldap.NewDelRequest(dn, nil)
err := login.conn.Del(del_request)
if err != nil {
dError = err.Error()
} else {
http.Redirect(w, r, "/admin/ldap/" + strings.Join(dn_split[1:], ","), http.StatusFound)
return
}
}
}
// Build path
path := []PathItem{
PathItem{
DN: config.BaseDN,
Identifier: config.BaseDN,
Active: dn == config.BaseDN,
},
}
len_base_dn := len(strings.Split(config.BaseDN, ","))
dn_split := strings.Split(dn, ",")
dn_last_attr := strings.Split(dn_split[0], "=")[0]
for i := len_base_dn + 1; i <= len(dn_split); i++ {
path = append(path, PathItem{
DN: strings.Join(dn_split[len(dn_split)-i:len(dn_split)], ","),
Identifier: dn_split[len(dn_split)-i],
Active: i == len(dn_split),
})
}
// Get object and parse it
searchRequest := ldap.NewSearchRequest(
dn,
@ -445,6 +456,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
Children: children,
Props: props,
CanAddChild: dn_last_attr == "ou",
CanDelete: dn != config.BaseDN && len(children) == 0,
HasMembers: len(members) > 0 || hasMembers,
Members: members,

View File

@ -190,6 +190,22 @@
</div>
{{end}}
{{if .CanDelete}}
<hr class="mt-4">
<h5 class="mt-4">Supprimer l'objet</h5>
<div class="alert alert-danger">
Attention, cette opération est irrévocable !
</div>
<form method="POST" onsubmit="return confirm('Supprimer cet objet DÉFINITIVEMENT ?');">
<div class="form-row">
<input type="hidden" name="action" value="delete-object" />
<div class="col-sm-5"></div>
<input type="submit" value="Supprimer l'objet" class="form-control btn btn-danger col-sm-2" />
<div class="col-sm-5"></div>
</div>
</form>
{{end}}
<hr class="mt-4" />
{{end}}