def add_theme(args): """ add_theme adds a theme to the stylesheet table :param args: commandline arguments containing bootstrap3_theme and optionally bootstrap4_theme :return: None """ _validate_args(args) valid_types = {'text/css'} api = config.api('add_theme') paths = [] bs3_name = args.bootstrap3 bs4 = args.bootstrap4 paths = [bs3_name] names = ['bootstrap3-style'] if bs4: paths.append(bs4) names.append('bootstrap4-style') bs4_name = get_file_name_from_path(bs4) io.start( 'Adding bootstrap 3 theme {} and bootstrap 4 theme {} to bootstrap themes' .format(highlight(bs3_name), highlight(bs4_name))) else: io.start('Adding bootstrap 3 theme {} to bootstrap themes'.format( highlight(bs3_name))) if not args.from_path: paths = [_get_path_from_quick_folders(theme) for theme in paths] files = _prepare_files_for_upload(paths, names, valid_types) post_files(files, api)
def make(args): io.start('Making user %s a member of role %s' % (highlight(args.user), highlight(args.role.upper()))) group_name = _find_group(args.role) url = config.api('member').format(group_name) post(url, {'username': args.user, 'roleName': args.role.upper()})
def make(args): io.start('Making user %s a member of role %s' % (highlight(args.user), highlight(args.role.upper()))) group_name = _find_group(args.role) url = config().get('api', 'member') % group_name post(url, {'username': args.user, 'roleName': args.role.upper()})
def _remove_script(script_name): path = get_scripts_folder().joinpath(script_name) _check_script_exists(path) try: io.start('Removing script %s' % highlight(script_name)) path.unlink() except OSError as e: raise McmdError('Error removing script: %s' % str(e))
def add_package(args): io.start('Adding package %s' % highlight(args.id)) data = {'id': args.id, 'label': args.id} if args.parent: data['parent'] = args.parent post(config().get('api', 'rest1') + 'sys_md_Package', data)
def config_set_host(args): if args.url: url = args.url else: auths = config.get('host', 'auth') urls = [auth['url'] for auth in auths] url = io.multi_choice('Please select a host:', urls) io.start("Switching to host {}".format(highlight(url))) config.set_host(url)
def enable_rls(args): io.start('Enabling row level security on entity type %s' % highlight(args.entity)) ensure_resource_exists(args.entity, ResourceType.ENTITY_TYPE) post(config().get('api', 'rls'), data={ 'id': args.entity, 'rlsEnabled': True })
def enable_rls(args): if not io.confirm( 'Are you sure you want to disable row level security on %s?' % args.entity): return io.start('Disabling row level security on entity type %s' % highlight(args.entity)) ensure_resource_exists(args.entity, ResourceType.ENTITY_TYPE) post(config.api('rls'), data={'id': args.entity, 'rlsEnabled': False})
def add_token(args): io.start('Adding token %s for user %s' % (highlight(args.token), highlight(args.user))) user = get(config().get('api', 'rest2') + 'sys_sec_User?attrs=id&q=username==%s' % args.user) if user.json()['total'] == 0: raise McmdError('Unknown user %s' % args.user) user_id = user.json()['items'][0]['id'] data = {'User': user_id, 'token': args.token} post(config().get('api', 'rest1') + 'sys_sec_Token', data)
def _do_import(file_path, package): io.start('Importing %s' % (highlight(file_path.name))) params = {'action': _get_import_action(file_path.name), 'metadataAction': 'upsert'} if package: params['packageId'] = package response = post_file(config().get('api', 'import'), file_path.resolve(), params) import_run_url = urljoin(config().get('api', 'host'), response.text) status, message = _poll_for_completion(import_run_url) if status == 'FAILED': raise McmdError(message)
def add_logo(args): """ add_logo uploads a logo to add to the left top of the menu :param args: commandline arguments containing path to logo :return: None """ io.start('Adding logo from path {}'.format(highlight(args.logo))) api = config.api('logo') valid_types = {'image/jpeg', 'image/png', 'image/gif'} logo = [args.logo] if not args.from_path: logo = [_get_path_from_quick_folders(args.logo)] files = _prepare_files_for_upload(logo, ['logo'], valid_types) post_files(files, api)
def give(args): # Convert synonyms to correct permission type if args.permission in _PERMISSION_SYNONYMS: args.permission = _PERMISSION_SYNONYMS[args.permission] # The PermissionManagerController always gives 200 OK so we need to validate everything ourselves resource_type = _get_resource_type(args) principal_type = _get_principal_type(args) io.start('Giving %s %s permission to %s on %s %s' % (principal_type.value, highlight( args.receiver), highlight(args.permission), resource_type.get_label().lower(), highlight(args.resource))) grant(principal_type, args.receiver, resource_type, args.resource, args.permission)
def _add_host(): url = io.input_("Enter the URL of the host", required=True) if config.host_exists(url): raise McmdError("A host with URL {} already exists.".format(url)) username = io.input_( "Enter the username of the superuser (Default: admin)") password = io.password( "Enter the password of the superuser (Default: admin)") username = '******' if len(username) == 0 else username password = '******' if len(password) == 0 else password io.start("Adding host {}".format(highlight(url))) config.add_host(url, username, password) io.succeed() return url
def add_user(args): io.start('Adding user %s' % highlight(args.username)) password = args.set_password if args.set_password else args.username email = args.with_email if args.with_email else args.username + '@molgenis.org' active = not args.is_inactive superuser = args.is_superuser ch_pwd = args.change_password post( config().get('api', 'rest1') + 'sys_sec_User', { 'username': args.username, 'password_': password, 'changePassword': ch_pwd, 'Email': email, 'active': active, 'superuser': superuser })
def _import_from_url(args): file_url = args.from_url file_name = file_url.split("/")[-1] io.start('Importing from URL %s' % highlight(file_url)) params = {'action': _get_import_action(file_name), 'metadataAction': 'upsert'} if args.to_package: params['packageId'] = args.to_package params['url'] = file_url response = import_by_url(params) import_run_url = urljoin(config().get('api', 'host'), response.text) status, message = _poll_for_completion(import_run_url) if status == 'FAILED': raise McmdError(message)
def _download_attachment(attachment, issue_num): issue_folder = get_issues_folder().joinpath(issue_num) issue_folder.mkdir(parents=True, exist_ok=True) file_path = issue_folder.joinpath(attachment.name) if file_path.exists(): overwrite = io.confirm('File %s already exists. Re-download?' % file_path.name) if not overwrite: return file_path io.start('Downloading %s from GitHub issue %s' % (highlight(attachment.name), highlight('#' + issue_num))) try: r = requests.get(attachment.url) r.raise_for_status() with file_path.open('wb') as f: f.write(r.content) except (OSError, requests.RequestException, requests.HTTPError) as e: raise McmdError('Error downloading GitHub attachment: %s' % str(e)) io.succeed() return file_path
def enable_theme(args): """ enable_theme enables a bootstrap theme :param args: commandline arguments containing the id of the theme (without .css) :exception McmdError: when applying the theme fails :return None """ theme = args.theme.replace('.css', '').replace('.min', '') io.start('Applying theme {}'.format(highlight(theme))) # Resource can be bootstrap-name.min.css (if molgenis theme), or name.min.css (if uploaded .min.css), or # name.css (if uploaded as .css). if one_resource_exists([theme + '.min.css', theme + '.css', 'bootstrap-' + theme + '.min.css'], ResourceType.THEME): # Molgenis themes start with bootstrap- but this is stripped from the name in the theme manager try: post(config.api('set_theme'), theme) except: post(config.api('set_theme'), theme.split('bootstrap-')[1]) else: raise McmdError( 'Applying theme failed. No themes found containing {} in the name'.format(args.theme, 'sys_set_StyleSheet'))
def add_group(args): io.start('Adding group %s' % highlight(args.name)) post(config().get('api', 'group'), { 'name': args.name.lower(), 'label': args.name })
def _switch_to_new_host(url): if io.confirm("Do you want to switch to the new host?"): io.start("Switching to host {}".format(highlight(url))) config.set_host(url)
def _import_from_path(args): io.start('Importing from path %s' % highlight(args.file)) file = Path(args.file) if not file.is_file(): raise McmdError("File %s doesn't exist" % str(file.resolve())) _do_import(file, args.to_package)
def _delete_entity_type(entity): io.start('Deleting entity {}'.format(highlight(entity))) _delete_row('sys_md_EntityType', entity)
def _delete_all_data(entity): io.start('Deleting all data from entity {}'.format(highlight(entity))) url = '{}{}'.format(config.api('rest1'), entity) delete(url)