Esempio n. 1
0
def set_(args):
    """
    set sets the specified row of the specified table (or setting of specified settings table) to the specified value
    :param args: command line arguments containing: the settings type, the setting to set, and the value to set it to,
    if not a setting also the --for (which row to alter)
    if --from-path or --from-resource is passed the value is assumed to be a file containing the value data to be set
    :return: None
    """
    value = args.value
    value_desc = highlight(value)

    if args.from_path:
        path = Path(args.value)
        value = files.read_file(path)
        value_desc = 'contents of {}'.format(highlight(args.value))
    elif args.from_resource:
        path = files.select_file_from_folders(context().get_resource_folders(),
                                              args.value)
        value = files.read_file(path)
        value_desc = 'contents of {}'.format(highlight(args.value))

    if args.for_:
        entity = args.type
        row = args.for_
        io.start('Updating {} of {} for id {} to {}'.format(
            highlight(args.attribute), highlight(args.type),
            highlight(args.for_), value_desc))
    else:
        entity = _get_settings_entity(args.type)
        io.start('Updating {} of {} settings to {}'.format(
            highlight(args.attribute), highlight(args.type), value_desc))
        row = _get_first_row_id(entity)

    url = api.rest1('{}/{}/{}'.format(entity, row, args.attribute))
    put(url, json.dumps(value))
Esempio n. 2
0
def _include_group_role(subject: Role, target_role: Role):
    if not target_role.group:
        raise McmdError('Role {} is not a group role'.format(target_role.name))
    if subject.name == target_role.name:
        raise McmdError("A role can't include itself")

    io.start('Including role {} in role {}'.format(highlight(target_role.name),
                                                   highlight(subject.name)))
    include = {'role': target_role.name}
    put(api.role(target_role.group.name, subject.name),
        data=json.dumps(include))
Esempio n. 3
0
def set_(args):
    """
    set sets the specified row of the specified table (or setting of specified settings table) to the specified value
    :param args: command line arguments containing: the settings type, the setting to set, and the value to set it to,
    if not a setting also the --for (which row to alter)
    :return: None
    """
    if args.for_:
        entity = args.type
        row = args.for_
        io.start('Updating {} of {} for id {} to {}'.format(
            highlight(args.attribute), highlight(args.type),
            highlight(args.for_), highlight(args.value)))
    else:
        entity = _get_settings_entity(args.type)
        io.start('Updating {} of {} settings to {}'.format(
            highlight(args.attribute), highlight(args.type),
            highlight(args.value)))
        row = _get_first_row_id(entity)

    url = api.rest1('{}/{}/{}'.format(entity, row, args.attribute))
    put(url, json.dumps(args.value))
Esempio n. 4
0
def _update_group_role_membership(user: User, group: Group, role: Role):
    io.start('Making user {} a member of role {}'.format(
        highlight(user.username), highlight(role.name)))
    url = urljoin(api.member(group.name), user.username)
    put(url, data=json.dumps({'roleName': role.name}))
Esempio n. 5
0
def disable_language(args):
    io.start('Disabling language {}'.format(highlight(args.language)))
    url = api.rest1('sys_Language/{}/active'.format(args.language))
    put(url, 'false')