Changeset - db744cade568
[Not reviewed]
0 2 0
Lance Edgar (lance) - 8 months ago 2023-10-01 19:39:06
lance@edbob.org
Add `get_user()` convenience method for auth, app handlers
2 files changed with 23 insertions and 0 deletions:
0 comments (0 inline, 0 general)
rattail/app.py
Show inline comments
 
@@ -1351,6 +1351,14 @@ class AppHandler(object):
 

	
 
        return prettify(field)
 

	
 
    def get_user(self, obj, **kwargs):
 
        """
 
        Convenience method to locate a User record for the given
 
        object.  This delegates to the
 
        :class:`~rattail.auth.AuthHandler` for actual lookup logic.
 
        """
 
        return self.get_auth_handler().get_user(obj, **kwargs)
 

	
 
    def get_product_key_field(self):
 
        """
 
        Returns the configured fieldname for product key,
rattail/auth.py
Show inline comments
 
@@ -95,6 +95,21 @@ class AuthHandler(GenericHandler, MergeMixin):
 
            if user.active:
 
                return user
 

	
 
    def get_user(self, obj, **kwargs):
 
        """
 
        Return the User associated with the given object, if any.
 
        """
 
        model = self.model
 

	
 
        if isinstance(obj, model.User):
 
            return obj
 

	
 
        else:
 
            person = self.app.get_person(obj)
 
            if person and person.users:
 
                # TODO: what if multiple users / ambiguous?
 
                return person.users[0]
 

	
 
    def has_permission(self, session, principal, permission,
 
                       include_guest=True,
 
                       include_authenticated=True):
0 comments (0 inline, 0 general)