HasOrganizationMembership reports whether the subject has explicit membership in organizationID through an org-scoped role. Site-wide roles alone do not count as organization membership.
(organizationID uuid.UUID)
| 178 | // membership in organizationID through an org-scoped role. Site-wide roles |
| 179 | // alone do not count as organization membership. |
| 180 | func (s Subject) HasOrganizationMembership(organizationID uuid.UUID) (bool, error) { |
| 181 | roles, err := s.Roles.Expand() |
| 182 | if err != nil { |
| 183 | return false, xerrors.Errorf("expand user authorization roles: %w", err) |
| 184 | } |
| 185 | |
| 186 | organizationIDString := organizationID.String() |
| 187 | for _, role := range roles { |
| 188 | if _, ok := role.ByOrgID[organizationIDString]; ok { |
| 189 | return true, nil |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | return false, nil |
| 194 | } |
| 195 | |
| 196 | type Authorizer interface { |
| 197 | // Authorize will authorize the given subject to perform the given action |
no test coverage detected