sub (/list/*/...) {
my $list = $current_user->get_list($_[1]);
return unless $list;
+ my $error;
sub (/) {
- $self->_list_dispatchers($list),
- sub () { $self->_render_list_page($list) };
+ $self->_list_dispatchers($list, \$error),
+ sub () { $self->_render_list_page($list, $error) };
},
sub (/deny/|/allow/|/mod/|/digest/) {
sub (/*/) {
my $sublist = $list->${\$_[1]};
- $self->_list_dispatchers($sublist),
- sub () { $self->_render_sublist_page($sublist) };
+ $self->_list_dispatchers($sublist, \$error),
+ sub () { $self->_render_sublist_page($sublist, $error) };
},
},
}
}
sub _list_dispatchers {
- my ($self, $list) = @_;
+ my ($self, $list, $error_ref) = @_;
sub (POST) {
sub (%add=) {
- $list->add_member($_[1]);
+ eval { $list->add_member($_[1]); 1 }
+ or ${$error_ref} = $@;
return;
},
sub (%remove=) {
- $list->remove_member($_[1]);
+ eval { $list->remove_member($_[1]); 1 }
+ or ${$error_ref} = $@;
return;
},
}
}
sub _render_list_page {
- my ($self, $list) = @_;
- $self->_render_listcore_page(
- $list, [
+ shift->_render_listcore_page(
+ @_, [
map [ ucfirst($_)." list", "${_}/" ], qw(allow deny mod digest)
]
);
}
sub _render_sublist_page {
- my ($self, $list) = @_;
- $self->_render_listcore_page(
- $list, [ [ "Back to list", "../" ] ],
+ shift->_render_listcore_page(
+ @_, [ [ "Back to list", "../" ] ],
);
}
sub _render_listcore_page {
- my ($self, $list, $links) = @_;
+ my ($self, $list, $error, $links) = @_;
$self->_render_page(list => sub {
$_->replace_content('.list-name', $list->name)
+ ->replace_content('.error', $error||'')
->repeat('.list-link', [
map {
my ($name, $href) = @$_;
like($res->content, qr{/list/$_/}, "List $_ on /")
for qw(list1 list2 list3);
+$res = $app->run_test_request(GET => 'mst:boromir@/list/list1/');
+
+like($res->content, qr{name="remove" value="$_"}, "Member $_ ok")
+ for qw(bob@example.com joe@example.com);
+
+$res = $app->run_test_request(GET => 'mst:boromir@/list/list1/deny/');
+
+like($res->content, qr{name="remove" value="$_"}, "Member $_ ok")
+ for qw(evil@monkey.com evil@gibbon.com);
+
+$res = $app->run_test_request(
+ POST => 'mst:boromir@/list/list1/deny/', add => 'hamster'
+);
+
+like(
+ $res->content, qr{address does not contain \@},
+ 'And your father smells of elderberries'
+);
+
+$res = $app->run_test_request(
+ POST => 'mst:boromir@/list/list1/deny/', add => 'evil@marmoset.com'
+);
+
+like($res->content, qr{name="remove" value="$_"}, "Member $_ ok")
+ for qw(evil@monkey.com evil@gibbon.com evil@marmoset.com);
+
+$res = $app->run_test_request(
+ POST => 'mst:boromir@/list/list1/deny/', remove => 'evil@monkey.com'
+);
+
+like($res->content, qr{name="remove" value="$_"}, "Member $_ ok")
+ for qw(evil@gibbon.com evil@marmoset.com);
+
+unlike($res->content, qr{name="remove" value="$_"}, "Member $_ gone")
+ for qw(evil@monkey.com);
+
done_testing;