snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
110
server/auth/handlers/handle_authorized-clients.go
Normal file
110
server/auth/handlers/handle_authorized-clients.go
Normal file
@@ -0,0 +1,110 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/auth/request"
|
||||
"github.com/cortezaproject/corteza/server/pkg/errors"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
)
|
||||
|
||||
type (
|
||||
authClients []authClient
|
||||
authClient struct {
|
||||
ID uint64
|
||||
Name string
|
||||
Description string
|
||||
ConfirmedAt time.Time
|
||||
}
|
||||
)
|
||||
|
||||
// Will sort clients - in order of creation
|
||||
var _ sort.Interface = authClients{}
|
||||
|
||||
func (set authClients) Len() int { return len(set) }
|
||||
func (set authClients) Swap(i, j int) { set[i], set[j] = set[j], set[i] }
|
||||
func (set authClients) Less(i, j int) bool {
|
||||
return strings.Compare(set[i].Name, set[i].Name) < 0
|
||||
}
|
||||
|
||||
func (h *AuthHandlers) clientsView(req *request.AuthReq) error {
|
||||
req.Template = TmplAuthorizedClients
|
||||
|
||||
ss, err := h.getAuthorizedClients(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sort.Sort(ss)
|
||||
req.Data["authorizedClients"] = ss
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *AuthHandlers) clientsProc(req *request.AuthReq) error {
|
||||
switch {
|
||||
case len(req.Request.PostFormValue("revoke")) > 0:
|
||||
clientID, err := strconv.ParseUint(req.Request.PostFormValue("revoke"), 10, 64)
|
||||
if clientID == 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = h.TokenService.DeleteByID(req.Context(), clientID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = h.ClientService.Revoke(req.Context(), req.AuthUser.User.ID, clientID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
t := translator(req, "auth")
|
||||
req.NewAlerts = append(req.NewAlerts, request.Alert{
|
||||
Type: "primary",
|
||||
Text: t("authorized-clients.alerts.removed"),
|
||||
})
|
||||
}
|
||||
|
||||
req.RedirectTo = GetLinks().AuthorizedClients
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *AuthHandlers) getAuthorizedClients(req *request.AuthReq) (ss authClients, err error) {
|
||||
var (
|
||||
set types.AuthConfirmedClientSet
|
||||
client *types.AuthClient
|
||||
)
|
||||
if set, err = h.ClientService.Confirmed(req.Context(), req.AuthUser.User.ID); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
ss = make(authClients, 0, len(set))
|
||||
|
||||
for i := range set {
|
||||
client, err = h.ClientService.Lookup(req.Context(), set[i].ClientID)
|
||||
if errors.IsNotFound(err) {
|
||||
err = nil
|
||||
continue
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
ac := authClient{
|
||||
ID: set[i].ClientID,
|
||||
Name: client.Handle,
|
||||
ConfirmedAt: set[i].ConfirmedAt,
|
||||
}
|
||||
|
||||
if client.Meta != nil {
|
||||
ac.Name = client.Meta.Name
|
||||
}
|
||||
|
||||
ss = append(ss, ac)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user