| 1 | package Kwiki::PagePrivacy; | ||||||||||||||||||||
| 2 | 1 | ▶ | use Kwiki::Plugin -Base; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | ▶ | use mixin 'Kwiki::Installer'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | our $VERSION = '0.10'; | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | const class_id => 'page_privacy'; | ||||||||||||||||||||
| 7 | const cgi_class => 'Kwiki::PagePrivacy::CGI'; | ||||||||||||||||||||
| 8 | const config_file => 'page_privacy.yaml'; | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 0 | ▶ | sub register { | ||||||||||||||||||
|
Subroutine
register: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 11 | 0 | my $registry = shift; | |||||||||||||||||||
| 12 | 0 | $registry->add(action => 'page_privacy_set'); | |||||||||||||||||||
| 13 | 0 | $registry->add(widget => 'page_privacy_select', | |||||||||||||||||||
| 14 | template => 'page_privacy_select.html', | ||||||||||||||||||||
| 15 | show_for => 'display', | ||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||
| 17 | 0 | $registry->add(hook => 'page:is_readable', | |||||||||||||||||||
| 18 | post => 'is_readable', | ||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||
| 20 | 0 | $registry->add(hook => 'page:is_writable', | |||||||||||||||||||
| 21 | post => 'is_writable', | ||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||
| 23 | 0 | $registry->add(hook => 'page:to_html', | |||||||||||||||||||
| 24 | pre => 'linked_page_formatter', | ||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 0 | ▶ | sub linked_page_formatter { | ||||||||||||||||||
|
Subroutine
linked_page_formatter: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 29 | 0 | my $page = $self; | |||||||||||||||||||
| 30 | 0 | ▶ | return unless io($page->file_path)->is_link; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | 0 | my $hook = pop; | |||||||||||||||||||
| 32 | 0 | $hook->cancel; | |||||||||||||||||||
| 33 | 0 | return '<pre>' . $self->html_escape($page->content) . '</pre>'; | |||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 0 | ▶ | sub is_readable { | ||||||||||||||||||
|
Subroutine
is_readable: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 37 | 0 | my $page = $self; | |||||||||||||||||||
| 38 | 0 | my $hook = pop; | |||||||||||||||||||
| 39 | 0 | ▶ | return unless $hook->returned_true; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 0 | $self = $self->hub->page_privacy; | |||||||||||||||||||
| 41 | 0 | my $privacy = $self->page_privacy($page); | |||||||||||||||||||
| 42 | 0 | ▶ | return 1 unless $privacy eq 'private'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 0 | $self->privacy_group eq $self->page_group($page); | |||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 0 | ▶ | sub is_writable { | ||||||||||||||||||
|
Subroutine
is_writable: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 47 | 0 | my $page = $self; | |||||||||||||||||||
| 48 | 0 | my $hook = pop; | |||||||||||||||||||
| 49 | 0 | ▶ | return unless $hook->returned_true; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 0 | $self = $self->hub->page_privacy; | |||||||||||||||||||
| 51 | 0 | my $privacy = $self->page_privacy($page); | |||||||||||||||||||
| 52 | 0 | ▶ | return 1 if $privacy eq 'public'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | 0 | $self->privacy_group eq $self->page_group($page); | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 0 | ▶ | sub page_privacy_set { | ||||||||||||||||||
|
Subroutine
page_privacy_set: not called CC=5 SCAR=34.0
| |||||||||||||||||||||
| 57 | 0 | ▶ | return unless $self->page_privacy_selectable; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 0 | my $privacy = $self->cgi->privacy; | |||||||||||||||||||
| 59 | 0 | my $dir = $self->plugin_directory; | |||||||||||||||||||
| 60 | 0 | my $id = $self->pages->current->id; | |||||||||||||||||||
| 61 | 0 | my $group = $self->privacy_group; | |||||||||||||||||||
| 62 | 0 | ▶ | if ($privacy eq 'public') { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 63 | 0 | io->dir("$dir/$id")->rmtree; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | elsif ($privacy eq 'protected') { | ||||||||||||||||||||
| 66 | 0 | io->file("$dir/$id/group")->assert->print("$group\n"); | |||||||||||||||||||
| 67 | 0 | io->file("$dir/$id/protected")->assert->touch; | |||||||||||||||||||
| 68 | 0 | io->file("$dir/$id/private")->unlink; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | elsif ($privacy eq 'private') { | ||||||||||||||||||||
| 71 | 0 | io->file("$dir/$id/group")->assert->print("$group\n"); | |||||||||||||||||||
| 72 | 0 | io->file("$dir/$id/private")->assert->touch; | |||||||||||||||||||
| 73 | 0 | io->file("$dir/$id/protected")->unlink; | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 0 | ▶ | sub page_privacy_selectable { | ||||||||||||||||||
|
Subroutine
page_privacy_selectable: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 78 | 0 | ▶ | my $group = $self->privacy_group | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | or return; | ||||||||||||||||||||
| 80 | 0 | ▶ | my $page_group = $self->page_group | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | or return 1; | ||||||||||||||||||||
| 82 | 0 | $group eq $page_group; | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 0 | ▶ | sub privacy_group { | ||||||||||||||||||
|
Subroutine
privacy_group: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 86 | 0 | $self->config->privacy_group; | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 0 | ▶ | sub page_group { | ||||||||||||||||||
|
Subroutine
page_group: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 90 | 0 | ▶ | my $id = (shift || $self->pages->current)->id; | ||||||||||||||||||
|
Condition0%0/3
shift() || $self->pages->current
MC/DC0%0/2
shift() || $self->pages->current
shift()
$self->pages->current
Truth table0%0/3
A || B
A= shift()B= $self->pages->current
| |||||||||||||||||||||
| 91 | 0 | my $dir = $self->plugin_directory; | |||||||||||||||||||
| 92 | 0 | my $group_file = "$dir/$id/group"; | |||||||||||||||||||
| 93 | 0 | ▶ | -f $group_file ? io($group_file)->chomp->getline : ''; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 0 | ▶ | sub page_privacy { | ||||||||||||||||||
|
Subroutine
page_privacy: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 97 | 0 | ▶ | my $id = (shift || $self->pages->current)->id; | ||||||||||||||||||
|
Condition0%0/3
shift() || $self->pages->current
MC/DC0%0/2
shift() || $self->pages->current
shift()
$self->pages->current
Truth table0%0/3
A || B
A= shift()B= $self->pages->current
| |||||||||||||||||||||
| 98 | 0 | my $dir = $self->plugin_directory; | |||||||||||||||||||
| 99 | 0 | ▶ | -e "$dir/$id/private" ? 'private' : | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 100 | -e "$dir/$id/protected" ? 'protected' : | ||||||||||||||||||||
| 101 | 'public'; | ||||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | package Kwiki::PagePrivacy::CGI; | ||||||||||||||||||||
| 105 | 0 | ▶ | use Kwiki::CGI -base; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||||||||||||||||||||
| 106 | cgi 'privacy'; | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | package Kwiki::PagePrivacy; | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | __DATA__ | ||||||||||||||||||||