Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def assertAccessDenied(self, response, level, modelName, user=None):
if level == AccessType.READ:
ls = 'Read'
elif level == AccessType.WRITE:
ls = 'Write'
else:
ls = 'Admin'
if user is None:
self.assertStatus(response, 401)
else:
self.assertStatus(response, 403)
self.assertEqual('%s access denied for %s.' % (ls, modelName),
response.json['message'])
model='project', plugin='hpccloud', level=AccessType.READ)
)
@access.user
def get_access(self, project):
return project.get('access', {'groups': [], 'users': []})
@loadmodel(model='item', level=AccessType.READ)
def getDataset(self, item, params):
meta = item['meta']
if 'minerva' in meta:
return meta['minerva']
else:
return {}
getDataset.description = (
def getAdjacentImages(self, currentImage):
folderModel = Folder()
folder = folderModel.load(
currentImage['folderId'], user=self.getCurrentUser(), level=AccessType.READ)
allImages = [item for item in folderModel.childItems(folder) if _isLargeImageItem(item)]
try:
index = allImages.index(currentImage)
except ValueError:
raise RestException('Id is not an image', 404)
return {
'previous': allImages[index - 1],
'next': allImages[(index + 1) % len(allImages)]
}
def search(self, params):
self.requireParams(('q', 'types'), params)
mode = params.get('mode', 'text')
level = AccessType.validate(params.get('level', AccessType.READ))
user = self.getCurrentUser()
limit = int(params.get('limit', 10))
offset = int(params.get('offset', 0))
if mode == 'text':
method = 'textSearch'
elif mode == 'prefix':
method = 'prefixSearch'
else:
raise RestException(
'The search mode must be either "text" or "prefix".')
try:
types = json.loads(params['types'])
except ValueError:
def initialize(self):
self.name = 'group'
self.ensureIndices(['lowerName'])
self.ensureTextIndex({
'name': 10,
'description': 1
})
self.exposeFields(level=AccessType.READ, fields=(
'_id', 'name', 'public', 'description', 'created', 'updated',
'addAllowed', '_addToGroupPolicy'))
events.bind('model.group.save.created',
CoreEventHandler.GROUP_CREATOR_ACCESS,
self._grantCreatorAccess)
def search(self, q, mode, types, level, limit, offset):
"""
Perform a search using one of the registered search modes.
"""
level = AccessType.validate(level)
user = self.getCurrentUser()
handler = getSearchModeHandler(mode)
if handler is None:
raise RestException('Search mode handler %r not found.' % mode)
results = handler(
query=q,
types=types,
user=user,
limit=limit,
offset=offset,
level=level
)
return results
level=AccessType.WRITE, paramType='formData', model=Item)
)
def copy(self, file, item):
return self._model.copyFile(file, self.getCurrentUser(), item=item)
([
('itemId', SortDir.ASCENDING),
('_active', SortDir.ASCENDING),
], {}),
([
('_annotationId', SortDir.ASCENDING),
('_version', SortDir.DESCENDING),
], {}),
'updated',
])
self.ensureTextIndex({
'annotation.name': 10,
'annotation.description': 1,
})
self.exposeFields(AccessType.READ, (
'annotation', '_version', '_elementQuery', '_active',
) + self.baseFields)
events.bind('model.item.remove', 'large_image_annotation', self._onItemRemove)
events.bind('model.item.copy.prepare', 'large_image_annotation', self._prepareCopyItem)
events.bind('model.item.copy.after', 'large_image_annotation', self._handleCopyItem)
self._historyEnabled = Setting().get(
constants.PluginSettings.LARGE_IMAGE_ANNOTATION_HISTORY)
# Listen for changes to our relevant settings
events.bind('model.setting.save.after', 'large_image_annotation', self._onSettingChange)
events.bind('model.setting.remove', 'large_image_annotation', self._onSettingChange)
@access.admin
@loadmodel(model='slide', plugin='digital_slide_archive',
level=AccessType.WRITE)
@describeRoute(
Description('Remove a slide')
.param('id', 'The id of the slide', paramType='path')
)
def deleteSlide(self, slide, params):
return self.model('slide', 'digital_slide_archive').removeTCGA(slide)