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)
Ejemplo n.º 2
0
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 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()})
Ejemplo n.º 4
0
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 ping(args):
    host = config.get('host', 'selected')
    user = config.username()
    status = Fore.LIGHTGREEN_EX + 'Online' + Fore.RESET
    try:
        version = get_version()
    except McmdError:
        status = Fore.LIGHTRED_EX + 'Offline' + Fore.RESET
        version = None

    print('   Host:  ' + highlight(host))
    print(' Status:  ' + status)
    if version:
        print('Version:  ' + highlight(version))
    print('   User:  ' + highlight(user))
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
def _install(default_config):
    mcmd.io.info(
        "Looks like this is your first time running {}!\n  "
        "Let's take a moment to set things up. It's OK to leave some fields empty, you can always change "
        "them later.".format(highlight("Molgenis Commander")))
    mcmd.io.newline()

    for configurer in property_configurers().values():
        configurer(default_config)

    config.set_config(default_config)

    mcmd.io.newline()
    mcmd.io.info('The configuration file has been created at {}'.format(
        highlight(str(get_properties_file()))))
    exit(0)
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))
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
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 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):
    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})
Ejemplo n.º 13
0
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
Ejemplo n.º 14
0
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)
Ejemplo n.º 16
0
def _upgrade(default_config, user_config):
    mcmd.io.info(
        "Some properties haven't been configured yet. Let's take a moment to fix that."
    )
    mcmd.io.newline()

    for prop, configurer in property_configurers().items():
        if prop not in user_config:
            configurer(default_config)

    config.set_config(default_config)

    mcmd.io.newline()
    mcmd.io.info(
        'The configuration file has been updated succesfully ({})'.format(
            highlight(str(get_properties_file()))))
    exit(0)
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
Ejemplo n.º 18
0
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
        })
Ejemplo n.º 19
0
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)
Ejemplo n.º 20
0
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'))
Ejemplo n.º 21
0
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)
Ejemplo n.º 23
0
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)
Ejemplo n.º 24
0
def _delete_entity_type(entity):
    io.start('Deleting entity {}'.format(highlight(entity)))
    _delete_row('sys_md_EntityType', entity)
Ejemplo n.º 25
0
def _delete_all_data(entity):
    io.start('Deleting all data from entity {}'.format(highlight(entity)))
    url = '{}{}'.format(config.api('rest1'), entity)
    delete(url)