<commit_before>from flask_jwt_extended import get_jwt_identity
from flask_restful import Resource
from marshmallow import fields
from sqlalchemy import func

from scuevals_api.models import Permission, Course, Department, School, Professor
from scuevals_api.auth import auth_required
from scuevals_api.utils import use_args


class SearchResource(Resource):
    args = {'q': fields.String(required=True), 'limit': fields.Integer()}

    @auth_required(Permission.WriteEvaluations)
    @use_args(args)
    def get(self, args):
        jwt_data = get_jwt_identity()

        if 'limit' not in args or args['limit'] > 50:
            args['limit'] = 50

        # strip any characters that would cause matching issues
        q = args['q'].replace(',', '')

        courses = Course.query.join(Course.department).filter(
            Course.department.has(Department.school.has(School.university_id == jwt_data['university_id']))
        ).filter(
            func.concat(Department.abbreviation, ' ', Course.number, ' ', Course.title).ilike('%{}%'.format(q))
        ).limit(args['limit'])

        professors = Professor.query.filter(
            func.concat(Professor.last_name, ' ', Professor.first_name).ilike('%{}%'.format(q)) |
            func.concat(Professor.first_name, ' ', Professor.last_name).ilike('%{}%'.format(q))
        ).limit(args['limit'])

        return {
            'courses': [
                course.to_dict() for course in courses.all()
            ],
            'professors': [
                professor.to_dict() for professor in professors.all()
            ]
        }
<commit_msg>Change permission for search endpoint<commit_after>from flask_jwt_extended import get_jwt_identity
from flask_restful import Resource
from marshmallow import fields
from sqlalchemy import func

from scuevals_api.models import Permission, Course, Department, School, Professor
from scuevals_api.auth import auth_required
from scuevals_api.utils import use_args


class SearchResource(Resource):
    args = {'q': fields.String(required=True), 'limit': fields.Integer()}

    @auth_required(Permission.ReadEvaluations)
    @use_args(args)
    def get(self, args):
        jwt_data = get_jwt_identity()

        if 'limit' not in args or args['limit'] > 50:
            args['limit'] = 50

        # strip any characters that would cause matching issues
        q = args['q'].replace(',', '')

        courses = Course.query.join(Course.department).filter(
            Course.department.has(Department.school.has(School.university_id == jwt_data['university_id']))
        ).filter(
            func.concat(Department.abbreviation, ' ', Course.number, ' ', Course.title).ilike('%{}%'.format(q))
        ).limit(args['limit'])

        professors = Professor.query.filter(
            func.concat(Professor.last_name, ' ', Professor.first_name).ilike('%{}%'.format(q)) |
            func.concat(Professor.first_name, ' ', Professor.last_name).ilike('%{}%'.format(q))
        ).limit(args['limit'])

        return {
            'courses': [
                course.to_dict() for course in courses.all()
            ],
            'professors': [
                professor.to_dict() for professor in professors.all()
            ]
        }

{'fraction_non_alphanumeric': 0.13066255778120184, 'fraction_numerical': 0.002465331278890601, 'mean_word_length': 2.8967587034813924, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3606854', 'n_tokens_mistral': 979, 'n_tokens_neox': 920, 'n_words': 194}