<commit_before>from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response
from django.conf import settings
import pymongo
import uuid
import jsonschema
from . import permissions
from . import sequences
from .schemas import swagger_schema
from .file_parser import file_parser


candidate_keys = ('id', 'name', 'email', 'phone', 'status', 'roomId', 'record')


@api_view(['POST', 'GET'])
def get_set_candidate(request, **kwargs):
    '''
    'id': 3001,
    'name': 'Mike',
    'email': '<EMAIL>',
    'phone': '1300000000',
    'status': 'weimianshi',
    'roomId': 1001,
    'record':{
        'video': 'string',
        'board': 'string',
        'chat' : 'string',
        'code' : 'string',
        'report':'string'
    }
    '''

    # Check user permission
    if permissions.check(request, ('hr', 'interviewer')) != permissions.PASS:
        return Response(
            {
                'error': 'Access denied.'
            },
            status.HTTP_403_FORBIDDEN
        )

    client = pymongo.MongoClient()
    db = client[settings.DB_NAME]

    if request.method == 'POST':
        candidate_data = request.data

        # Check key error
        try:
            jsonschema.validate(candidate_data,
                                swagger_schema['definitions']['PostCandidate'])
        except:
            return Response(
                {
                    'error': 'Key error'<commit_msg>Fix candidate api permission<commit_after>from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response
from django.conf import settings
import pymongo
import uuid
import jsonschema
from . import permissions
from . import sequences
from .schemas import swagger_schema
from .file_parser import file_parser


candidate_keys = ('id', 'name', 'email', 'phone', 'status', 'roomId', 'record')


@api_view(['POST', 'GET'])
def get_set_candidate(request, **kwargs):
    '''
    'id': 3001,
    'name': 'Mike',
    'email': '<EMAIL>',
    'phone': '1300000000',
    'status': 'weimianshi',
    'roomId': 1001,
    'record':{
        'video': 'string',
        'board': 'string',
        'chat' : 'string',
        'code' : 'string',
        'report':'string'
    }
    '''

    # Check user permission
    if permissions.check(request, ['hr']) != permissions.PASS:
        return Response(
            {
                'error': 'Access denied.'
            },
            status.HTTP_403_FORBIDDEN
        )

    client = pymongo.MongoClient()
    db = client[settings.DB_NAME]

    if request.method == 'POST':
        candidate_data = request.data

        # Check key error
        try:
            jsonschema.validate(candidate_data,
                                swagger_schema['definitions']['PostCandidate'])
        except:
            return Response(
                {
                    'error': 'Key error'
{'fraction_non_alphanumeric': 0.12694651320243738, 'fraction_numerical': 0.014218009478672985, 'mean_word_length': 2.346545866364666, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '1353301', 'n_tokens_mistral': 887, 'n_tokens_neox': 838, 'n_words': 213}