
from itertools import chain
from rest_framework import permissions
from django.utils import timezone
from seven23 import settings

class CanWriteAccount(permissions.BasePermission):
    """
        Object-level permission to only allow owners of an object to edit it.
        Assumes the model instance has an `owner` attribute.
    """

    def has_object_permission(self, request, view, obj):
        # Read permissions are allowed to any request,
        # so we'll always allow GET, HEAD or OPTIONS requests.
        # Instance must have an attribute named `owner`.
        return obj.account.id in list(chain(
            request.user.accounts.values_list('id', flat=True),
            request.user.guests.values_list('account__id', flat=True)
        ))

class IsPaid(permissions.BasePermission):
    """
        Check if user has a paid formula
    """

    def has_permission(self, request, view):
        # Read permissions are allowed to any request,
        # so we'll always allow GET, HEAD or OPTIONS requests.

        if not settings.SAAS:
            return True

        if request.method in permissions.SAFE_METHODS:
            return True

        return request.user.profile.valid_until > timezone.now()

from itertools import chain
from rest_framework import permissions
from datetime import datetime
from seven23 import settings

class CanWriteAccount(permissions.BasePermission):
    """
        Object-level permission to only allow owners of an object to edit it.
        Assumes the model instance has an `owner` attribute.
    """

    def has_object_permission(self, request, view, obj):
        # Read permissions are allowed to any request,
        # so we'll always allow GET, HEAD or OPTIONS requests.
        # Instance must have an attribute named `owner`.
        return obj.account.id in list(chain(
            request.user.accounts.values_list('id', flat=True),
            request.user.guests.values_list('account__id', flat=True)
        ))

class IsPaid(permissions.BasePermission):
    """
        Check if user has a paid formula
    """

    def has_permission(self, request, view):
        # Read permissions are allowed to any request,
        # so we'll always allow GET, HEAD or OPTIONS requests.

        if not settings.SAAS:
            return True

        if request.method in permissions.SAFE_METHODS:
            return True

        return request.user.profile.valid_until > datetime.today()
Fix issue with imezone on IsPaid Permission
Fix issue with imezone on IsPaid Permission

  
  from itertools import chain
  from rest_framework import permissions
- from django.utils import timezone
+ from datetime import datetime
  from seven23 import settings
  
  class CanWriteAccount(permissions.BasePermission):
      """
          Object-level permission to only allow owners of an object to edit it.
          Assumes the model instance has an `owner` attribute.
      """
  
      def has_object_permission(self, request, view, obj):
          # Read permissions are allowed to any request,
          # so we'll always allow GET, HEAD or OPTIONS requests.
          # Instance must have an attribute named `owner`.
          return obj.account.id in list(chain(
              request.user.accounts.values_list('id', flat=True),
              request.user.guests.values_list('account__id', flat=True)
          ))
  
  class IsPaid(permissions.BasePermission):
      """
          Check if user has a paid formula
      """
  
      def has_permission(self, request, view):
          # Read permissions are allowed to any request,
          # so we'll always allow GET, HEAD or OPTIONS requests.
  
          if not settings.SAAS:
              return True
  
          if request.method in permissions.SAFE_METHODS:
              return True
  
-         return request.user.profile.valid_until > timezone.now()
+         return request.user.profile.valid_until > datetime.today()
Fix issue with imezone on IsPaid Permission
## Code Before:

from itertools import chain
from rest_framework import permissions
from django.utils import timezone
from seven23 import settings

class CanWriteAccount(permissions.BasePermission):
    """
        Object-level permission to only allow owners of an object to edit it.
        Assumes the model instance has an `owner` attribute.
    """

    def has_object_permission(self, request, view, obj):
        # Read permissions are allowed to any request,
        # so we'll always allow GET, HEAD or OPTIONS requests.
        # Instance must have an attribute named `owner`.
        return obj.account.id in list(chain(
            request.user.accounts.values_list('id', flat=True),
            request.user.guests.values_list('account__id', flat=True)
        ))

class IsPaid(permissions.BasePermission):
    """
        Check if user has a paid formula
    """

    def has_permission(self, request, view):
        # Read permissions are allowed to any request,
        # so we'll always allow GET, HEAD or OPTIONS requests.

        if not settings.SAAS:
            return True

        if request.method in permissions.SAFE_METHODS:
            return True

        return request.user.profile.valid_until > timezone.now()
## Instruction:
Fix issue with imezone on IsPaid Permission
## Code After:

from itertools import chain
from rest_framework import permissions
from datetime import datetime
from seven23 import settings

class CanWriteAccount(permissions.BasePermission):
    """
        Object-level permission to only allow owners of an object to edit it.
        Assumes the model instance has an `owner` attribute.
    """

    def has_object_permission(self, request, view, obj):
        # Read permissions are allowed to any request,
        # so we'll always allow GET, HEAD or OPTIONS requests.
        # Instance must have an attribute named `owner`.
        return obj.account.id in list(chain(
            request.user.accounts.values_list('id', flat=True),
            request.user.guests.values_list('account__id', flat=True)
        ))

class IsPaid(permissions.BasePermission):
    """
        Check if user has a paid formula
    """

    def has_permission(self, request, view):
        # Read permissions are allowed to any request,
        # so we'll always allow GET, HEAD or OPTIONS requests.

        if not settings.SAAS:
            return True

        if request.method in permissions.SAFE_METHODS:
            return True

        return request.user.profile.valid_until > datetime.today()