from rest_framework.permissions import BasePermission

from course_discovery.apps.publisher.mixins import check_course_organization_permission, check_roles_access
from course_discovery.apps.publisher.models import OrganizationExtension
from course_discovery.apps.publisher.utils import is_internal_user, is_publisher_user


class CanViewAssociatedCourse(BasePermission):
    """ Permission class to check user can view a publisher course or also if
    user has view permission on organization.
    """

    def has_object_permission(self, request, view, obj):
        user = request.user
        return (
            check_roles_access(user) or
            check_course_organization_permission(user, obj.course, OrganizationExtension.VIEW_COURSE)
        )


class InternalUserPermission(BasePermission):
    """ Permission class to check user is an internal user. """

    def has_object_permission(self, request, view, obj):
        return is_internal_user(request.user)


class PublisherUserPermission(BasePermission):
    """ Permission class to check user is a publisher user. """

    def has_object_permission(self, request, view, obj):
        return is_publisher_user(request.user)

    def has_permission(self, request, view):
        return is_publisher_user(request.user)

@@ -936,16 +936,41 @@
  return 
+request.user.is_staff or 
 is_inter
@@ -1170,32 +1170,57 @@
 %0A        return 
+request.user.is_staff or 
 is_publisher_use
@@ -1296,16 +1296,41 @@
  return 
+request.user.is_staff or 
 is_publi

Allow staff access to Publisher APIs