Central access control for submitting things related to assignments.

def can_create_submission(self, user=None):
        '''
            Central access control for submitting things related to assignments.
        '''
        if user:
            # Super users, course owners and tutors should be able to test their validations
            # before the submission is officially possible.
            # They should also be able to submit after the deadline.
            if user.is_superuser or user is self.course.owner or self.course.tutors.filter(pk=user.pk).exists():
                return True
            if self.course not in user.profile.user_courses():
                # The user is not enrolled in this assignment's course.
                logger.debug('Submission not possible, user not enrolled in the course.')
                return False

            if user.authored.filter(assignment=self).exclude(state=Submission.WITHDRAWN).count() > 0:
                # User already has a valid submission for this assignment.
                logger.debug('Submission not possible, user already has one for this assignment.')
                return False

        if self.hard_deadline and self.hard_deadline < timezone.now():
            # Hard deadline has been reached.
            logger.debug('Submission not possible, hard deadline passed.')
            return False

        if self.publish_at > timezone.now() and not user.profile.can_see_future():
            # The assignment has not yet been published.
            logger.debug('Submission not possible, assignment has not yet been published.')
            return False

        return True