forked from stmansour/phonebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadminEditCo.go
53 lines (48 loc) · 1.39 KB
/
adminEditCo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"net/http"
"phonebook/authz"
"phonebook/db"
"phonebook/sess"
"strconv"
)
func adminEditCompanyHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
var ssn *sess.Session
var ui uiSupport
ssn = nil
if 0 < initHandlerSession(ssn, &ui, w, r) {
return
}
ssn = ui.X
// SECURITY
if !ssn.ElemPermsAny(authz.ELEMCOMPANY, authz.PERMMOD) {
ulog("Permissions refuse adminEditCo page on userid=%d (%s), role=%s\n", ssn.UID, ssn.Firstname, ssn.PMap.Urole.Name)
http.Redirect(w, r, "/search/", http.StatusFound)
return
}
var c db.Company
path := "/adminEditCo/"
CoCodestr := r.RequestURI[len(path):]
if len(CoCodestr) == 0 {
fmt.Fprintf(w, "the RequestURI needs the Company Code. It was not found on the URI: %s\n", r.RequestURI)
return
}
CoCode, err := strconv.Atoi(CoCodestr)
if err != nil {
fmt.Fprintf(w, "Error converting Company Code to a number: %v. URI: %s\n", err, r.RequestURI)
return
}
breadcrumbAdd(ssn, "AdminEdit Company", fmt.Sprintf("/adminEditCo/%d", CoCode))
getCompanyInfo(CoCode, &c)
ui.C = &c
filterSecurityRead(ui.C, authz.ELEMCOMPANY, ssn, authz.PERMMOD, 0)
err = renderTemplate(w, ui, "adminEditCo.html")
if nil != err {
errmsg := fmt.Sprintf("adminEditCompanyHandler: err = %v\n", err)
ulog(errmsg)
fmt.Println(errmsg)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}