Skip to content

Commit

Permalink
Fix small bugs that arose from updating api
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed May 29, 2024
1 parent 03e49b7 commit a732568
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 35 deletions.
2 changes: 1 addition & 1 deletion pkg/control/server/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func getUserGroups(w http.ResponseWriter, r *http.Request) {
return
}

user, err := users.GetUser(username)
user, err := data.GetUserGroupMembership(username)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down
6 changes: 3 additions & 3 deletions pkg/control/wagctl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (c *CtrlClient) ListAllGroups() (groups []control.GroupData, err error) {

func (c *CtrlClient) UserGroups(username string) (userGroups []string, err error) {

response, err := c.httpClient.Get("http://unix/user/groups?username=" + url.QueryEscape(username))
response, err := c.httpClient.Get("http://unix/users/groups?username=" + url.QueryEscape(username))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -269,7 +269,7 @@ func (c *CtrlClient) ResetUserMFA(username string) error {

func (c *CtrlClient) GetUsersAcls(username string) (acl acls.Acl, err error) {

response, err := c.httpClient.Get("http://unix/user/acls?username=" + url.QueryEscape(username))
response, err := c.httpClient.Get("http://unix/users/acls?username=" + url.QueryEscape(username))
if err != nil {
return acls.Acl{}, err
}
Expand Down Expand Up @@ -549,7 +549,7 @@ func (c *CtrlClient) GetAllSettings() (allSettings data.AllSettings, err error)

func (c *CtrlClient) GetLockout() (lockout int, err error) {

response, err := c.httpClient.Get("http://unix/config/settings")
response, err := c.httpClient.Get("http://unix/config/settings/lockout")
if err != nil {
return 0, err
}
Expand Down
8 changes: 1 addition & 7 deletions ui/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ import (
"encoding/json"
"log"
"net/http"

"github.com/NHAS/wag/internal/data"
)

func devicesMgmtUI(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
http.NotFound(w, r)
return
}

_, u := sessionManager.GetSessionFromRequest(r)
if u == nil {
Expand Down Expand Up @@ -54,7 +48,7 @@ func devicesMgmt(w http.ResponseWriter, r *http.Request) {
return
}

lockout, err := data.GetLockout()
lockout, err := ctrl.GetLockout()
if err != nil {
log.Println("error getting lockout: ", err)

Expand Down
34 changes: 13 additions & 21 deletions ui/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,28 +128,20 @@ func aclsTest(w http.ResponseWriter, r *http.Request) {
return
}

var username string
switch r.Method {
case http.MethodPost:
username = r.PostFormValue("username")
case http.MethodGet:
username = ""
default:
http.NotFound(w, r)
return
}
var (
username string
acl string
)
if r.Method == http.MethodPost {

acls, err := ctrl.GetUsersAcls(username)
if err != nil {
log.Println("unable to get users acls: ", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

acl := ""
if username != "" {
b, _ := json.MarshalIndent(acls, "", " ")
acl = string(b)
username = r.PostFormValue("username")
acls, err := ctrl.GetUsersAcls(username)
if err == nil {
b, _ := json.MarshalIndent(acls, "", " ")
acl = string(b)
} else {
acl = err.Error()
}
}

d := struct {
Expand Down
2 changes: 1 addition & 1 deletion ui/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func registrationTokens(w http.ResponseWriter, r *http.Request) {
return
}

var tokens []TokensData
tokens := []TokensData{}

for _, reg := range registrations {
tokens = append(tokens, TokensData{
Expand Down
3 changes: 1 addition & 2 deletions ui/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ func manageUsers(w http.ResponseWriter, r *http.Request) {
return
}

var usersData []UsersData

usersData := []UsersData{}
for _, u := range users {
devices, err := ctrl.ListDevice(u.Username)
if err != nil {
Expand Down

0 comments on commit a732568

Please sign in to comment.