rattail.auth

Auth Handler

See also Auth Handler.

class rattail.auth.AuthHandler(*args, **kwargs)[source]
class rattail.auth.RattailAuthHandler(config)[source]

Default auth handler for Rattail.

This is a subclass of wuttjamaican.auth.AuthHandler but adds various methods and logic for Rattail.

add_api_token(user, description, **kwargs)[source]

Add a new API token for the user.

authenticate_user_token(session, token)[source]

Authenticate the given user API token string, and if valid, return the corresponding User object.

delete_api_token(token, **kwargs)[source]

Delete a new API token for the user.

delete_user(user, **kwargs)[source]

Delete the given user account. Use with caution! As this generally cannot be undone.

Default behavior here is of course to delete the account, but it also tries to remove the user association from various places, in particular the continuum transactions table.

Warning

Please note that if the user was associated with any continuum transactions, the “author” for those transactions will be set to null.

Depending on the DB schema and data present, deleting the user may still fail with an error (i.e. if the user is still referenced by other tables).

generate_raw_api_token()[source]

Generate a new raw API token string.

get_merge_preview_data(user, **kwargs)[source]

Must return a data dictionary for the given object, which can be presented to the user during a merge preview.

get_merge_preview_fields(**kwargs)[source]

Returns a sequence of fields which will be used during a merge preview.

get_merge_resulting_data(removing, keeping, **kwargs)[source]

Must return a dictionary to represent what the final data would look like, should the proposed merge occur. Note that we’re still in preview mode here, this doesn’t actually cause any particular data to become final.

Parameters:
get_short_display_name(user, **kwargs)[source]

Returns “short display name” for the user. This is for convenience of mobile view, at least…

merge_update_keeping_object(removing, keeping)[source]

Update the object to be kept, with any relevant data from the object to be removed, in the context of a merge.

remove_user_from_continuum_transactions(user)[source]

Remove the given user from all Continuum transactions, i.e. all data versioning tables.

You probably will not need to invoke this directly; it is invoked as needed from within delete_user().

Parameters:

user – A User instance which should be purged from the versioning tables.

why_not_merge(removing, keeping, **kwargs)[source]

Evaluate the given merge candidates and if there is a reason not to merge them, return that reason.

Parameters:
  • removing – Object which will be removed, should the merge happen.

  • keeping – Object which will be kept, should the merge happen.

Returns:

String indicating reason not to merge, or None.