Skip to content

Commit

Permalink
Merge pull request #46 from travelgateX/add_HasRoleInOrg
Browse files Browse the repository at this point in the history
Add func HasRoleInOrg
  • Loading branch information
bloodyrafo75 committed May 24, 2024
2 parents 8401782 + 141f699 commit f758689
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ func GetOrgsServiceFilter(ctx context.Context, role Role, service Service) []str
return user.GetOrgsServiceFilter(role, &service)
}

func HasRoleInOrg(ctx context.Context, org string, role Role, service *Service) bool {
user, _ := ctx.Value(activeUser).(*User)
orgsBearer := user.GetOrgsServiceFilter(role, service)

return Contains(orgsBearer, org)

}

func GetOrgs(ctx context.Context, role Role) []string {
user, _ := ctx.Value(activeUser).(*User)
return user.GetOrgs(role)
Expand Down Expand Up @@ -189,6 +197,15 @@ func ContextCopyUser(parent, background context.Context) context.Context {
return background
}

func Contains(a []string, e string) bool {
for _, x := range a {
if x == e {
return true
}
}
return false
}

type contextKey struct{}

var activeUser = contextKey{}

0 comments on commit f758689

Please sign in to comment.