<commit_before>from django.contrib.auth.models import User, Group, Permission

STUDENT_TUTORS_GROUP_NAME = "Student Tutors"
COURSE_OWNERS_GROUP_NAME = "Course Owners"

def check_permission_system():
    '''
        This methods makes sure that:

        1.) All neccessary user groups exist.
        2.) All these groups have the right database permissions assigned.
        3.) Tutors have backend rights.
        4.) Course owners have backend rights.
        5.) Students have no backend rights.

        The permission objects were already generated by the Django database initialization,
        so we can assume them to be given.

        This method is idempotent and does not touch manually assigned permissions.
    '''
    tutor_perms = (  "change_submission", 
                     "delete_submission",
                     "add_submissionfile", 
                     "change_submissionfile", 
                     "delete_submissionfile" )
    owner_perms = (  "add_assignment", 
                     "change_assignment", 
                     "delete_assignment",
                     "add_course", 
                     "change_course", 
                     "delete_course",
                     "add_grading", 
                     "change_grading",  
                     "delete_grading",
                     "add_gradingscheme", 
                     "change_gradingscheme", 
                     "delete_gradingscheme",
                     "add_studyprogram", 
                     "change_studyprogram", 
                     "delete_studyprogram",
                     "change_submission", 
                     "delete_submission",
                     "add_submissionfile", 
                     "change_submissionfile", 
                     "delete_submissionfile",
                     "change_user", 
                     "delete_user")

    # Give all tutor users staff rights and add them to the tutors permission group
    tutors = User.objects.filter(courses_tutoring__isnull=False)
    tutors.update(is_staff=True)
    # If the app crashes here, you may have duplicate group objects, which must be fixed manually in the DB.
    tutor_group, created = Group.objects.get_or_create(name=STUDENT_TUTORS_GROUP_NAME)<commit_msg>Course owners could throw out the super user. Bad.<commit_after>from django.contrib.auth.models import User, Group, Permission

STUDENT_TUTORS_GROUP_NAME = "Student Tutors"
COURSE_OWNERS_GROUP_NAME = "Course Owners"

def check_permission_system():
    '''
        This methods makes sure that:

        1.) All neccessary user groups exist.
        2.) All these groups have the right database permissions assigned.
        3.) Tutors have backend rights.
        4.) Course owners have backend rights.
        5.) Students have no backend rights.

        The permission objects were already generated by the Django database initialization,
        so we can assume them to be given.

        This method is idempotent and does not touch manually assigned permissions.
    '''
    tutor_perms = (  "change_submission", 
                     "delete_submission",
                     "add_submissionfile", 
                     "change_submissionfile", 
                     "delete_submissionfile" )
    owner_perms = (  "add_assignment", 
                     "change_assignment", 
                     "delete_assignment",
                     "add_course", 
                     "change_course", 
                     "delete_course",
                     "add_grading", 
                     "change_grading",  
                     "delete_grading",
                     "add_gradingscheme", 
                     "change_gradingscheme", 
                     "delete_gradingscheme",
                     "add_studyprogram", 
                     "change_studyprogram", 
                     "delete_studyprogram",
                     "change_submission", 
                     "delete_submission",
                     "add_submissionfile", 
                     "change_submissionfile", 
                     "delete_submissionfile")

    # Give all tutor users staff rights and add them to the tutors permission group
    tutors = User.objects.filter(courses_tutoring__isnull=False)
    tutors.update(is_staff=True)
    # If the app crashes here, you may have duplicate group objects, which must be fixed manually in the DB.
    tutor_group, created = Group.objects.get_or_create(name=STUDENT_TUTORS_GROUP_NAME)
{'fraction_non_alphanumeric': 0.06565430995980348, 'fraction_numerical': 0.0022331397945511387, 'mean_word_length': 1.7145454545454546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5752860', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1054, 'n_words': 305}