def package_info(dsname, context): """ if package exists, returns dictionary containing: 'view': True or False (can the user view the package) 'edit': True or False (can the user edit the package) 'package' the contents of the package Returns None if package doesn't exist """ l = {'view': False, 'edit': False} #check package exists try: package_name_exists(dsname, context) print 'package_info: package_exists' package_id = convert_to_id(dsname, context) except Exception: #package doesn't exist l = None print 'package_info: package doesn\'t exist' #check user can view/edit if l: #view try: l['package'] = plugins.toolkit.get_action('package_show')( context, { 'id': package_id }) l['view'] = True print 'package_info: user can view' #edit try: l['edit'] = plugins.toolkit.check_access( 'package_update', context, data_dict={'id': package_id}) print 'package_info: user can edit' except plugins.toolkit.NotAuthorized: print 'package_infop: not authorised to edit' except Exception: #print 'package_info: user can\'t view' pass return l
def update_default_view(context, data_dict): # noinspection PyUnresolvedReferences """ Updates the default view for a given cube :param cubeId: cube id :type cubeId: str :param defaultView: default view id :type defaultView: str :return: dict """ cube_id = _get_or_bust(data_dict, 'cubeId') default_view = _get_or_bust(data_dict, 'defaultView') try: validators.package_name_exists('cube-'+cube_id, context) except validators.Invalid, e: raise _ValidationError({'cubeId': e.error})
def package_info(dsname, context): """ if package exists, returns dictionary containing: 'view': True or False (can the user view the package) 'edit': True or False (can the user edit the package) 'package' the contents of the package Returns None if package doesn't exist """ l = {'view': False, 'edit': False} #check package exists try: package_name_exists(dsname, context) print 'package_info: package_exists' package_id = convert_to_id(dsname, context) except Exception: #package doesn't exist l = None print 'package_info: package doesn\'t exist' #check user can view/edit if l: #view try: l['package'] = plugins.toolkit.get_action('package_show')(context, {'id': package_id}) l['view'] = True print 'package_info: user can view' #edit try: l['edit'] = plugins.toolkit.check_access('package_update', context, data_dict={'id': package_id}) print 'package_info: user can edit' except plugins.toolkit.NotAuthorized: print 'package_infop: not authorised to edit' except Exception: #print 'package_info: user can\'t view' pass return l
def test_package_name_exists(self): name = 'pne_validation_test' dataset = factories.Dataset(name=name) ctx = self._make_context() v = validators.package_name_exists(name, ctx) assert v == name
def test_package_name_exists_empty(self): ctx = self._make_context() v = validators.package_name_exists('', ctx)
def test_package_name_exists(): name = "pne_validation_test" dataset = factories.Dataset(name=name) v = validators.package_name_exists(name, _make_context()) assert v == name
def test_package_name_exists_empty(): with pytest.raises(df.Invalid): validators.package_name_exists("", _make_context())
def test_package_name_exists(): name = factories.Dataset()["name"] v = validators.package_name_exists(name, _make_context()) assert v == name