Skip to content

Commit

Permalink
simplify scope
Browse files Browse the repository at this point in the history
  • Loading branch information
kdudkov committed Mar 14, 2024
1 parent c502471 commit a2e84ad
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
7 changes: 1 addition & 6 deletions cmd/goatak_server/udpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,7 @@ func (app *App) ListenUDP(ctx context.Context, addr string) error {
continue
}

scope := ev.Access
if scope == "" {
scope = "broadcast"
}

c, err := cot.EventToProtoExt(ev, "", scope)
c, err := cot.EventToProtoExt(ev, "", "BROADCAST")
if err != nil {
app.logger.Error("error", "error", err.Error())
}
Expand Down
10 changes: 1 addition & 9 deletions internal/client/client_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (h *ConnClientHandler) handleRead(ctx context.Context) {
}

msg.From = h.addr
msg.Scope = h.getScope()
msg.Scope = h.GetUser().GetScope()

// add new contact uid
if msg.IsContact() {
Expand Down Expand Up @@ -482,11 +482,3 @@ func (h *ConnClientHandler) tryAddPacket(msg []byte) bool {

return true
}

func (h *ConnClientHandler) getScope() string {
if h.user == nil {
return ""
}

return h.user.Scope
}
6 changes: 3 additions & 3 deletions internal/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type User struct {
Role string `yaml:"role,omitempty"`
Typ string `yaml:"type,omitempty"`
Password string `yaml:"password"`
Scope string `yaml:"scope,omitempty"`
Scope string `yaml:"scope"`
ReadScope []string `yaml:"read_scope,omitempty"`
}

Expand All @@ -29,10 +29,10 @@ func (u *User) GetScope() string {

func (u *User) CanSeeScope(scope string) bool {
if u == nil {
return true
return scope == ""
}

if u.Scope == "" || u.Scope == scope {
if u.GetScope() == scope {
return true
}

Expand Down
2 changes: 2 additions & 0 deletions users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
# role: HQ, Team Lead, Team Member, K9, Forward Observer, Sniper, Medic, RTO
- user: user
password: $2a$14$r9/RteHNKtwH.sdc9WmBHe49.MZe8fU8DrCuT4yAGTxIM/fB0mAP2
scope: test
read_scope: [ ]

0 comments on commit a2e84ad

Please sign in to comment.