Exemplo n.º 1
0
def _remove_hgrc_single(login, path):
    if os.path.isfile(path):
        hgrc = HGWeb(path)
    else:
        if not repository.is_repository(path):
            return
        hgrc_path = os.path.join(path, ".hg", "hgrc")
        if not os.path.exists(hgrc_path):
            return
        hgrc = HGWeb(hgrc_path)
    required_keys = ["allow_read", "allow_push", "deny_read", "deny_push"]
    for key in required_keys:
        val = hgrc.get_web_key(key)
        if not val is None:
            raw_login_list = val.split(",")
            login_list = [item.strip() for item in raw_login_list]
            try:
                login_list.remove(login)
                logins = ",".join(login_list)
                hgrc.set_web_key(key, logins)
            except ValueError:
                continue
Exemplo n.º 2
0
def hgweb(request):
    hgweb = HGWeb(settings.HGWEB_CONFIG)
    tree = prepare_tree(
        modhg.repository.get_tree(hgweb.get_paths(), hgweb.get_collections()))
    is_raw_mode = False

    allow_read_list = _split_users(hgweb.get_web_key('allow_read'))
    allow_push_list = _split_users(hgweb.get_web_key('allow_push'))
    deny_read_list = _split_users(hgweb.get_web_key('deny_read'))
    deny_push_list = _split_users(hgweb.get_web_key('deny_push'))

    user_list = users.login_list(settings.AUTH_FILE)
    add_to_allow_read_list = [
        val for val in user_list if val.strip() not in allow_read_list
    ]
    add_to_allow_push_list = [
        val for val in user_list if val.strip() not in allow_push_list
    ]
    add_to_deny_read_list = [
        val for val in user_list if val.strip() not in deny_read_list
    ]
    add_to_deny_push_list = [
        val for val in user_list if val.strip() not in deny_push_list
    ]

    model = {
        "tree": tree,
        "global": True,
        "add_to_allow_read_list": add_to_allow_read_list,
        "add_to_allow_push_list": add_to_allow_push_list,
        "add_to_deny_read_list": add_to_deny_read_list,
        "add_to_deny_push_list": add_to_deny_push_list,
        "allow_read_list": allow_read_list,
        "allow_push_list": allow_push_list,
        "deny_read_list": deny_read_list,
        "deny_push_list": deny_push_list
    }
    file_hash = md5_for_file(settings.HGWEB_CONFIG)

    form = RepositoryForm(file_hash)
    repo_field_delete_form = FileHashForm(file_hash)

    with open(settings.HGWEB_CONFIG, 'r') as f:
        hgrc_content = f.read()
    raw_mode_form = RawModeForm(file_hash, initial={"hgrc": hgrc_content})

    if request.method == 'POST':
        if 'save' in request.POST:
            form = RepositoryForm(file_hash, request.POST)
            if form.is_valid():
                form.export_values(hgweb, request.POST)
                messages.success(request,
                                 _("Global settings saved successfully."))
                return HttpResponseRedirect(reverse("hgweb"))
        elif 'raw_save' in request.POST:
            is_raw_mode = True
            raw_mode_form = RawModeForm(file_hash, request.POST)
            if raw_mode_form.is_valid():
                with open(settings.HGWEB_CONFIG, 'w') as f:
                    f.write(raw_mode_form.cleaned_data['hgrc'])
                messages.success(request,
                                 _("Global settings saved successfully."))
                return HttpResponseRedirect(reverse("hgweb"))

        # re-set errors if any occurs in the is_valid method.
        file_hash = md5_for_file(settings.HGWEB_CONFIG)
        repo_field_delete_form = FileHashForm(file_hash)

        # raw_mode form may have _errors set, so just update data in it
        with open(settings.HGWEB_CONFIG, 'r') as f:
            hgrc_content = f.read()
        raw_mode_form.data['hgrc'] = hgrc_content
        raw_mode_form.data['file_hash'] = file_hash

        # re-set errors if any occurs in the is_valid method.
        errors = form._errors
        form = RepositoryForm(file_hash)
        form._errors = errors

    form.set_default(hgweb, None)
    model["form"] = form
    model["repo_field_delete_form"] = repo_field_delete_form
    model["raw_mode_form"] = raw_mode_form
    model["is_raw_mode"] = is_raw_mode
    return model