Sub-user Hooks
The seven hooks over inviting, accepting, updating and removing sub-users.
Overview
Somebody else reaching an account starts with an invitation and ends with an acceptance. Every step between has its own hook: inviting, resending, accepting, updating, suspending and removing.
Three separate numbers must be kept apart: the account, the person reaching it and the sub-user record. Mixing them grants rights on the wrong account.
Reference
Following a sub-user invitation
Runs when a sub-user is invited to an account. There is no access yet: the invitation waits until it is accepted.
Hook::add('action:user.subuser_invited', 10, function ($owner_id, $subuser_id, $email, $perms) {
// There is NO access yet: the invitation is waiting.
Acme::noteInvite($owner_id, $email);
});Following an invitation being accepted
Runs when a sub-user accepts an invitation. Access begins at this point.
Hook::add('action:user.subuser_accepted', 10, function ($owner_id, $user_id, $subuser_id) {
// Three separate numbers: the account, the person, the record.
Acme::grantAccess($owner_id, $user_id);
});Following a sub-user being added
Runs when a sub-user is added to an account.
Hook::add('action:user.subuser_added', 10, function ($user_id, $subuser) {
Acme::syncTeam($user_id, $subuser);
});Following a sub-user update
Runs when the details or permissions of a sub-user change.
Hook::add('action:user.subuser_updated', 10, function ($owner_id, $subuser) {
Acme::syncPermissions($owner_id, $subuser);
});Following a sub-user status change
Runs when a sub-user is suspended or brought back.
active or inactive.Hook::add('action:user.subuser_status_changed', 10,
function ($owner_id, $subuser_id, $status) {
if ($status === 'inactive') Acme::revokeTokens($subuser_id);
});Following an invitation being sent again
Runs when a waiting invitation is sent again.
Hook::add('action:user.subuser_invite_resent', 10, function ($owner_id, $subuser_id) {
Acme::noteResend($owner_id, $subuser_id);
});Following a sub-user being removed
Runs after a sub-user is removed from an account.
Hook::add('action:user.subuser_deleted', 10, function ($owner_id, $subuser) {
Acme::revokeAllAccess($owner_id, $subuser['email'] ?? '');
});Pitfalls
The acceptance hook carries three ids: the account access was granted on, the person signing in and the sub-user record. Using the wrong one writes rights against another account.
When the invitation hook runs the other party can reach nothing yet. Access begins at the acceptance hook. A listener that opens rights on invitation turns an unaccepted invitation into real access.
Related Articles
Merci pour votre retour !
Notre équipe d'assistance est disponible 24h/24 pour tout ce que vous ne trouvez pas ci-dessus.