Example #1
0
def get_roles(user=None):
    """Get the global defined roles of the user

    Code extracted from `IRoleManager.manage_getUserRolesAndPermissions`

    :param user: A user ID, user object or None (for the current user)
    :returns: List of global granted roles
    """
    user = get_user(user)
    return sorted(user.getRoles())
Example #2
0
    def get_other_contacts(self, sample):
        """Returns a list with additional contacts the alert has to be sent to
        """
        contacts = set()
        contacts.add(api.get_user_contact(api_user.get_user()))

        # Get the responsibles of departments
        in_panic = self.get_analyses_in_panic(sample)
        departments = map(lambda an: an.getDepartment(), in_panic)
        managers = map(lambda dept: dept.getManager(), departments)
        for manager in managers:
            if manager:
                contacts.add(manager)
        return list(contacts)
Example #3
0
def get_allowed_permissions_for(brain_or_object, user=None):
    """Get the allowed permissions for the given object

    Code extracted from `IRoleManager.manage_getUserRolesAndPermissions`

    :param brain_or_object: Catalog brain or object
    :param user: A user ID, user object or None (for the current user)
    :returns: List of allowed permissions
    """
    allowed = []
    user = get_user(user)
    obj = api.get_object(brain_or_object)
    for permission in get_mapped_permissions_for(brain_or_object):
        if user.has_permission(permission, obj):
            allowed.append(permission)
    return allowed