<commit_before>from girder.api.describe import Description, autoDescribeRoute
from girder.api import access
from girder.api.rest import Resource
from girder.api.rest import RestException
from girder.api.rest import getCurrentUser

from girder.constants import AccessType
from girder.constants import TokenScope

from .models.geometry import Geometry as GeometryModel


class Geometry(Resource):

    def __init__(self):
        super(Geometry, self).__init__()
        self.resourceName = 'geometry'
        self.route('GET', (), self.find_geometries)
        self.route('POST', (), self.create)
        self.route('DELETE', (':id',), self.delete)

        self._model = GeometryModel()

    @access.public
    @autoDescribeRoute(
        Description('Find geometries of a given molecule.')
        .param('moleculeId', 'The id of the parent molecule.')
    )
    def find_geometries(self, params):
        user = getCurrentUser()

        moleculeId = params['moleculeId']
        geometries = self._model.find_geometries(moleculeId)

        # Filter based upon access level.
        return [self._model.filter(x, user) for x in geometries]

    @access.user(scope=TokenScope.DATA_WRITE)
    @autoDescribeRoute(
        Description('Create a geometry.')
        .param('moleculeId', 'The id of the parent molecule.')
        .jsonParam('cjson', 'The chemical json of the geometry.')
    )
    def create(self, params):
        self.requireParams(['moleculeId', 'cjson'], params)

        user = getCurrentUser()

        moleculeId = params['moleculeId']
        cjson = params['cjson']

        return self._model.create(moleculeId, cjson, 'user', user['_id'])

    @access.user(scope=TokenScope.DATA_WRITE)
    @autoDescribeRoute(
        Description('Delete a geometry.')
        .param('id', 'The id of the geometry to be deleted.')
        .errorResponse('Geometry not found.', 404)
    )
    def delete(self, id):
        user = self.getCurrentUser()
        geometry = GeometryModel().load(id, user=user, level=AccessType.WRITE)

        if not geometry:
            raise RestException('Geometry not found.', code=404)

        return GeometryModel().remove(geometry)<commit_msg>Clean geometry of access level before returning<commit_after>from girder.api.describe import Description, autoDescribeRoute
from girder.api import access
from girder.api.rest import Resource
from girder.api.rest import RestException
from girder.api.rest import getCurrentUser

from girder.constants import AccessType
from girder.constants import TokenScope

from .models.geometry import Geometry as GeometryModel


class Geometry(Resource):

    def __init__(self):
        super(Geometry, self).__init__()
        self.resourceName = 'geometry'
        self.route('GET', (), self.find_geometries)
        self.route('POST', (), self.create)
        self.route('DELETE', (':id',), self.delete)

        self._model = GeometryModel()

    def _clean(self, doc):
        if 'access' in doc:
            del doc['access']

        return doc

    @access.public
    @autoDescribeRoute(
        Description('Find geometries of a given molecule.')
        .param('moleculeId', 'The id of the parent molecule.')
    )
    def find_geometries(self, params):
        user = getCurrentUser()

        moleculeId = params['moleculeId']
        geometries = self._model.find_geometries(moleculeId)

        # Filter based upon access level.
        return [self._clean(self._model.filter(x, user)) for x in geometries]

    @access.user(scope=TokenScope.DATA_WRITE)
    @autoDescribeRoute(
        Description('Create a geometry.')
        .param('moleculeId', 'The id of the parent molecule.')
        .jsonParam('cjson', 'The chemical json of the geometry.')
    )
    def create(self, params):
        self.requireParams(['moleculeId', 'cjson'], params)

        user = getCurrentUser()

        moleculeId = params['moleculeId']
        cjson = params['cjson']

        return self._clean(self._model.create(user, moleculeId, cjson, 'user',
                                              user['_id']))

    @access.user(scope=TokenScope.DATA_WRITE)
    @autoDescribeRoute(
        Description('Delete a geometry.')
        .param('id', 'The id of the geometry to be deleted.')
        .errorResponse('Geometry not found.', 404)
    )
    def delete(self, id):
        user = self.getCurrentUser()
        geometry = GeometryModel().load(id, user=user, level=AccessType.WRITE)

        if not geometry:
            raise RestException('Geometry not found.', code=404)

        return GeometryModel().remove(geometry)
{'fraction_non_alphanumeric': 0.11314186248912098, 'fraction_numerical': 0.0026109660574412533, 'mean_word_length': 2.9391602399314483, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4105273', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1257, 'n_words': 339}