feat(profile): persist candidate edits and enforce company access
This commit is contained in:
1 parent
3ab6bd91a3
commit
73c7caa225
67 files changed
+5286
-229
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package organization
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// CompanyAccess is a request-scoped capability issued after the current
|
||||
// account has been checked as an active owner. Business operations still
|
||||
// repeat authorization inside their transaction before reading or writing.
|
||||
type CompanyAccess struct {
|
||||
actorID uuid.UUID
|
||||
organizationID uuid.UUID
|
||||
membershipID uuid.UUID
|
||||
}
|
||||
|
||||
// Matches reports whether this capability was issued for actorID and
|
||||
// organizationID.
|
||||
func (access CompanyAccess) Matches(actorID, organizationID uuid.UUID) bool {
|
||||
return access.actorID != uuid.Nil && access.organizationID != uuid.Nil && access.membershipID != uuid.Nil &&
|
||||
access.actorID == actorID && access.organizationID == organizationID
|
||||
}
|
||||
|
||||
type companyAccessContextKey struct{}
|
||||
|
||||
// WithCompanyAccess attaches a validated company capability to a request
|
||||
// context. An empty capability is ignored.
|
||||
func WithCompanyAccess(ctx context.Context, access CompanyAccess) context.Context {
|
||||
if !access.Matches(access.actorID, access.organizationID) {
|
||||
return ctx
|
||||
}
|
||||
return context.WithValue(ctx, companyAccessContextKey{}, access)
|
||||
}
|
||||
|
||||
// CompanyAccessFromContext returns the capability attached by the HTTP
|
||||
// boundary, if one is present and valid.
|
||||
func CompanyAccessFromContext(ctx context.Context) (CompanyAccess, bool) {
|
||||
access, ok := ctx.Value(companyAccessContextKey{}).(CompanyAccess)
|
||||
if !ok || !access.Matches(access.actorID, access.organizationID) {
|
||||
return CompanyAccess{}, false
|
||||
}
|
||||
return access, true
|
||||
}
|
||||
Reference in new issue
Block a user