from oscar.core.loading import get_class

BaseDashboardPermission = get_class("dashboard.permissions", "DashboardPermission")


class DashboardPermission(BaseDashboardPermission):
    @classmethod
    def get_all_permissions(cls):
        """
        Retrieve set of unique permissions defined in this class.
        """
        return set(
            [
                permission
                for permissions in cls.permissions.values()
                for permission in permissions
            ]
        )

    @classmethod
    def has_dashboard_perms(cls, user):
        """
        Check if user has any of the dashboard permissions.
        """
        return len(cls.get_all_permissions() & user.get_all_permissions()) > 0
