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:
96
server/pkg/envoy/resource/user.go
Normal file
96
server/pkg/envoy/resource/user.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package resource
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
)
|
||||
|
||||
type (
|
||||
// User represents a User
|
||||
User struct {
|
||||
*base
|
||||
Res *types.User
|
||||
|
||||
RoleMembership []Identifiers
|
||||
RefRoles RefSet
|
||||
}
|
||||
)
|
||||
|
||||
func NewUser(u *types.User, roles ...string) *User {
|
||||
r := &User{base: &base{}}
|
||||
r.SetResourceType(types.UserResourceType)
|
||||
r.Res = u
|
||||
|
||||
r.AddIdentifier(identifiers(u.Handle, u.Email, u.Name, u.ID)...)
|
||||
|
||||
// Role membership
|
||||
for _, role := range roles {
|
||||
rid := MakeIdentifiers(role)
|
||||
r.RoleMembership = append(r.RoleMembership, rid)
|
||||
|
||||
r.RefRoles = append(r.RefRoles, r.AddRef(types.RoleResourceType, role))
|
||||
}
|
||||
|
||||
// Initial timestamps
|
||||
r.SetTimestamps(MakeTimestampsCUDAS(&u.CreatedAt, u.UpdatedAt, u.DeletedAt, nil, u.SuspendedAt))
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func (u *User) AddRoles(roles ...*types.Role) *User {
|
||||
for _, r := range roles {
|
||||
idf := firstOkString(r.Handle, strconv.FormatUint(r.ID, 10))
|
||||
rid := MakeIdentifiers(idf)
|
||||
u.RoleMembership = append(u.RoleMembership, rid)
|
||||
|
||||
u.RefRoles = append(u.RefRoles, u.AddRef(types.RoleResourceType, idf))
|
||||
}
|
||||
|
||||
return u
|
||||
}
|
||||
|
||||
func (r *User) Resource() interface{} {
|
||||
return r.Res
|
||||
}
|
||||
|
||||
func (r *User) SysID() uint64 {
|
||||
return r.Res.ID
|
||||
}
|
||||
|
||||
func (r *User) RBACParts() (resource string, ref *Ref, path []*Ref) {
|
||||
ref = r.Ref()
|
||||
path = nil
|
||||
resource = fmt.Sprintf(types.UserRbacResourceTpl(), types.UserResourceType, firstOkString(strconv.FormatUint(r.Res.ID, 10), r.Res.Handle, r.Res.Username))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// FindUser looks for the user in the resources
|
||||
func FindUser(rr InterfaceSet, ii Identifiers) (u *types.User) {
|
||||
var uRes *User
|
||||
|
||||
rr.Walk(func(r Interface) error {
|
||||
ur, ok := r.(*User)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
if ur.Identifiers().HasAny(ii) {
|
||||
uRes = ur
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
// Found it
|
||||
if uRes != nil {
|
||||
return uRes.Res
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func UserErrUnresolved(ii Identifiers) error {
|
||||
return fmt.Errorf("user unresolved %v", ii.StringSlice())
|
||||
}
|
||||
Reference in New Issue
Block a user