Documentation ¶
Overview ¶
Package hooks is middleware to alter the graphql mutation
Index ¶
- Variables
- func AddPostMutationHook[T any](hook func(ctx context.Context, v T) error)
- func Decrypt(ctx context.Context, k *secrets.Keeper, u *generated.Hush) error
- func EmitEventHook(e *Eventer) ent.Hook
- func HookCreateAPIToken() ent.Hook
- func HookCreatePersonalAccessToken() ent.Hook
- func HookDeleteUser() ent.Hook
- func HookEmailVerificationToken() ent.Hook
- func HookEnableTFA() ent.Hook
- func HookEntityCreate() ent.Hook
- func HookGroup() ent.Hook
- func HookGroupAuthz() ent.Hook
- func HookGroupMembers() ent.Hook
- func HookHush() ent.Hook
- func HookInvite() ent.Hook
- func HookInviteAccepted() ent.Hook
- func HookObjectOwnedTuples(parents []string, skipUser bool) ent.Hook
- func HookOrgMembers() ent.Hook
- func HookOrgMembersDelete() ent.Hook
- func HookOrgOwnedTuples(skipUser bool) ent.Hook
- func HookOrganization() ent.Hook
- func HookOrganizationDelete() ent.Hook
- func HookPasswordResetToken() ent.Hook
- func HookProgramAuthz() ent.Hook
- func HookProgramMembers() ent.Hook
- func HookRelationTuples(objects map[string]string, relation fgax.Relation) ent.Hook
- func HookSubcontrolUpdate() ent.Hook
- func HookSubscriber() ent.Hook
- func HookTaskAssignee() ent.Hook
- func HookTaskCreate() ent.Hook
- func HookUpdateAPIToken() ent.Hook
- func HookUpdatePersonalAccessToken() ent.Hook
- func HookUser() ent.Hook
- func HookUserPermissions() ent.Hook
- func HookUserSetting() ent.Hook
- func IsUniqueConstraintError(err error) bool
- func RegisterGlobalHooks(client *entgen.Client, e *Eventer)
- func RegisterListeners(e *Eventer) error
- type EventID
- type Eventer
- type EventerOpts
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInternalServerError is returned when an internal error occurs. ErrInternalServerError = errors.New("internal server error") // ErrInvalidInput is returned when the input is invalid. ErrInvalidInput = errors.New("invalid input") // ErrPersonalOrgsNoChildren is returned when personal org attempts to add a child org ErrPersonalOrgsNoChildren = errors.New("personal organizations are not allowed to have child organizations") // ErrPersonalOrgsNoMembers is returned when personal org attempts to add members ErrPersonalOrgsNoMembers = errors.New("personal organizations are not allowed to have members other than the owner") // ErrPersonalOrgsNoUser is returned when personal org has no user associated, so no permissions can be added ErrPersonalOrgsNoUser = errors.New("personal organizations missing user association") // ErrUserNotInOrg is returned when a user is not a member of an organization when trying to add them to a group ErrUserNotInOrg = errors.New("user not in organization") // ErrUnsupportedFGARole is returned when a role is assigned that is not supported in our fine grained authorization system ErrUnsupportedFGARole = errors.New("unsupported role") // ErrMissingRole is returned when an update request is made that contains no role ErrMissingRole = errors.New("missing role in update") // ErrUserAlreadyOrgMember is returned when an user attempts to be invited to an org they are already a member of ErrUserAlreadyOrgMember = errors.New("user already member of organization") // ErrUserAlreadySubscriber is returned when an user attempts to subscribe to an organization but is already a subscriber ErrUserAlreadySubscriber = errors.New("user already a subscriber") // ErrEmailRequired is returned when an email is required but not provided ErrEmailRequired = errors.New("email is required but not provided") // ErrMaxAttempts is returned when a user has reached the max attempts to resend an invitation to an org ErrMaxAttempts = errors.New("too many attempts to resend org invitation") // ErrMissingRecipientEmail is returned when an email is required but not provided ErrMissingRecipientEmail = errors.New("recipient email is required but not provided") // ErrMissingRequiredName is returned when a name is required but not provided ErrMissingRequiredName = errors.New("name or display name is required but not provided") // ErrTooManyAvatarFiles is returned when a user attempts to upload more than one avatar file ErrTooManyAvatarFiles = errors.New("too many avatar files uploaded, only one is allowed") // ErrFailedToRegisterListener is returned when a listener fails to register ErrFailedToRegisterListener = errors.New("failed to register listener") // ErrNoControls is returned when a subcontrol has no controls assigned ErrNoControls = errors.New("subcontrol must have at least one control assigned") // ErrUnableToCast is returned when a type assertion fails ErrUnableToCast = errors.New("unable to cast") )
var OrganizationSettingCreate = "OrganizationSetting.OpCreate"
TODO [MKA]: create better methods for constructing object + event topic names; possibly update soiree to make topic management more friendly OrganizationSettingCreate and OrganizationSettingUpdateOne are the topics for the organization setting events
var OrganizationSettingUpdateOne = "OrganizationSetting.OpUpdateOne"
Functions ¶
func AddPostMutationHook ¶ added in v0.5.0
The `AddPostMutationHook` function is used to add a post-mutation hook to the list of runtime hooks. This function takes a hook function as a parameter, which will be executed after a mutation operation is performed. The hook function is expected to take a context and a value of type `T` as input parameters and return an error if any
func EmitEventHook ¶ added in v0.4.1
EmitEventHook emits an event to the event pool when a mutation is performed
func HookCreateAPIToken ¶
HookCreateAPIToken runs on api token mutations and sets the owner id
func HookCreatePersonalAccessToken ¶
HookCreatePersonalAccessToken runs on access token mutations and sets the owner id
func HookDeleteUser ¶
HookDeleteUser runs on user deletions to clean up personal organizations
func HookEmailVerificationToken ¶
HookEmailVerificationToken runs on email verification mutations and sets expires
func HookEnableTFA ¶
func HookEntityCreate ¶
HookEntityCreate runs on entity mutations to set default values that are not provided
func HookGroupAuthz ¶
HookGroupAuthz runs on group mutations to setup or remove relationship tuples
func HookGroupMembers ¶
func HookInviteAccepted ¶
HookInviteAccepted adds the user to the organization when the status is accepted
func HookObjectOwnedTuples ¶ added in v0.3.4
HookObjectOwnedTuples is a hook that adds object owned tuples for the object being created given a set of parent id fields, it will add the user and parent permissions to the object on creation by default, it will always add a user permission to the object
func HookOrgMembers ¶
func HookOrgMembersDelete ¶
HookOrgMembersDelete is a hook that runs during the delete operation of an org membership
func HookOrgOwnedTuples ¶ added in v0.4.2
HookOrgOwnedTuples is a hook that adds organization owned tuples for the object being created it will add the user and parent (organization owner_id) permissions to the object on creation by default, it will always add an admin user permission to the object
func HookOrganization ¶
HookOrganization runs on org mutations to set default values that are not provided
func HookOrganizationDelete ¶
HookOrganizationDelete runs on org delete mutations to ensure the org can be deleted
func HookPasswordResetToken ¶
HookPasswordResetToken runs on reset token mutations and sets expires
func HookProgramAuthz ¶ added in v0.3.5
HookProgramAuthz runs on program mutations to setup or remove relationship tuples
func HookProgramMembers ¶ added in v0.3.5
HookProgramMembers is a hook that ensures that the user is a member of the organization before allowing them to be added to a program TODO (sfunk): can this be generic across all edges with users that are owned by an organization?
func HookRelationTuples ¶ added in v0.4.2
HookRelationTuples is a hook that adds tuples for the object being created the objects input is a map of object id fields to the object type these tuples based are based on the direct relation, e.g. a group#member to another object
func HookSubcontrolUpdate ¶ added in v0.5.0
HookSubcontrolUpdate ensures that there is at least 1 control assigned to the subcontrol
func HookSubscriber ¶
HookSubscriber runs on subscriber create mutations
func HookTaskAssignee ¶ added in v0.3.4
HookTaskAssignee runs on task create and update mutations to add and remove the assignee tuple
func HookTaskCreate ¶ added in v0.3.4
HookTaskCreate runs on task create mutations to set default values that are not provided this will set the assigner to the current user if it is not provided
func HookUpdateAPIToken ¶
HookUpdateAPIToken runs on api token update and redacts the token
func HookUpdatePersonalAccessToken ¶
HookUpdatePersonalAccessToken runs on access token update and redacts the token
func HookUser ¶
HookUser runs on user mutations validate and hash the password and set default values that are not provided
func HookUserPermissions ¶ added in v0.3.1
func HookUserSetting ¶
HookUserSetting runs on user settings mutations and validates input on update
func IsUniqueConstraintError ¶
IsUniqueConstraintError reports if the error resulted from a DB uniqueness constraint violation. e.g. duplicate value in unique index.
func RegisterGlobalHooks ¶ added in v0.4.1
RegisterGlobalHooks registers global event hooks for the entdb client and expects a pointer to an Eventer
func RegisterListeners ¶ added in v0.4.1
RegisterListeners is currently used to globally register what listeners get applied on the entdb client
Types ¶
type EventID ¶ added in v0.4.1
type EventID struct {
ID string `json:"id,omitempty"`
}
EventID is used to marshall and unmarshall the ID out of a ent mutation
type Eventer ¶ added in v0.5.0
type Eventer struct { Emitter *soiree.EventPool Listeners []soiree.Listener Topics map[string]interface{} }
Eventer is a wrapper struct for having a soiree as well as a list of listeners
func NewEventer ¶ added in v0.5.0
func NewEventer(opts ...EventerOpts) *Eventer
NewEventer creates a new Eventer with the provided options
func NewEventerPool ¶ added in v0.5.0
func NewEventerPool(client interface{}) *Eventer
NewEventerPool initializes a new Eventer and takes a client to be used as the client for the soiree pool
type EventerOpts ¶ added in v0.5.0
type EventerOpts (func(*Eventer))
EventerOpts is a functional options wrapper
func WithEventerEmitter ¶ added in v0.5.0
func WithEventerEmitter(emitter *soiree.EventPool) EventerOpts
WithEventerEmitter sets the emitter for the Eventer if there's an existing soiree pool that needs to be passed in
func WithEventerListeners ¶ added in v0.5.0
func WithEventerListeners(topic string, listeners []soiree.Listener) EventerOpts
WithEventerListeners takes a single topic and appends an array of listeners to the Eventer
func WithEventerTopics ¶ added in v0.5.0
func WithEventerTopics(topics map[string]interface{}) EventerOpts
WithEventerTopics sets the topics for the Eventer
Source Files ¶
- apitoken.go
- authzmutationhelpers.go
- doc.go
- emailverificationtoken.go
- entity.go
- errors.go
- event.go
- group.go
- groupmembers.go
- helpers.go
- hush.go
- invite.go
- objectownedtuples.go
- organization.go
- orgmembers.go
- orgownedtuples.go
- passwordresettoken.go
- personalaccesstoken.go
- program.go
- programmembers.go
- sessions.go
- subcontrol.go
- subscriber.go
- task.go
- tfasettings.go
- tuples.go
- user.go
- usersettings.go