Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add /permission/module/Foo and /permission/distribution/Foo
- Loading branch information
Showing
5 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package MetaCPAN::Web::Controller::Permission; | ||
|
||
use Moose; | ||
use namespace::autoclean; | ||
|
||
BEGIN { extends 'MetaCPAN::Web::Controller' } | ||
|
||
sub distribution : Local Args(1) { | ||
my ( $self, $c, $distribution ) = @_; | ||
|
||
$c->forward( 'get', $c, [ 'distribution', $distribution ] ); | ||
} | ||
|
||
sub module : Local Args(1) { | ||
my ( $self, $c, $module ) = @_; | ||
|
||
$c->forward( 'get', $c, [ 'module', $module ] ); | ||
} | ||
|
||
sub get : Private { | ||
my $self = shift; | ||
my $c = shift; | ||
my ( $type, $name ) = @_; | ||
|
||
my $perms = $c->model('API::Permission')->get( $type, $name ); | ||
|
||
if ( !$perms ) { | ||
$c->stash( | ||
{ | ||
message => 'Permissions not found for ' . $name | ||
} | ||
); | ||
$c->detach('/not_found'); | ||
} | ||
|
||
$c->stash( { name => $name, permission => $perms } ); | ||
} | ||
|
||
__PACKAGE__->meta->make_immutable; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package MetaCPAN::Web::Model::API::Permission; | ||
|
||
use Moose; | ||
|
||
extends 'MetaCPAN::Web::Model::API'; | ||
|
||
use MetaCPAN::Web::Model::API::Release (); | ||
|
||
=head1 NAME | ||
MetaCPAN::Web::Model::Permission - Catalyst Model for 06perms | ||
=cut | ||
|
||
sub get { | ||
my ( $self, $type, $name ) = @_; | ||
|
||
if ( $type eq 'module' ) { | ||
my $module = $self->request( '/permission/' . $name )->recv; | ||
|
||
# return undef if there's a 404 | ||
return $module->{code} ? undef : $module; | ||
} | ||
|
||
my $release = $self->request( '/release/' . $name )->recv; | ||
|
||
# ugh | ||
my $model = MetaCPAN::Web::Model::API::Release->new( | ||
api_secure => $self->{api_secure} ); | ||
|
||
my $pkg_search = { | ||
query => { | ||
bool => { | ||
must => [ | ||
{ term => { distribution => $release->{distribution} } }, | ||
{ term => { dist_version => $release->{version} } }, | ||
] | ||
}, | ||
}, | ||
size => 1_000, | ||
}; | ||
|
||
my $found_modules | ||
= $self->request( '/package/_search', $pkg_search )->recv; | ||
|
||
my @modules = map { $_->{_source}->{module_name} } | ||
@{ $found_modules->{hits}->{hits} }; | ||
|
||
return undef unless @modules; | ||
|
||
my @perm_search | ||
= map { +{ term => { module_name => $_ } } } @modules; | ||
|
||
my $search = { | ||
query => { bool => { should => \@perm_search } }, | ||
size => 1_000, | ||
}; | ||
|
||
my $perms_found = $self->request( '/permission/_search', $search )->recv; | ||
my @perms = sort { $a->{module_name} cmp $b->{module_name} } | ||
map { $_->{_source} } @{ $perms_found->{hits}->{hits} }; | ||
return \@perms; | ||
} | ||
|
||
__PACKAGE__->meta->make_immutable; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<% title = 'module permissions for ' . name %> | ||
|
||
<h1>Module Permissions</h1> | ||
|
||
<table class="table table-striped"> | ||
<tr> | ||
<th>Name</th> | ||
<th>Owner</th> | ||
<th>Co-Maintainers</th> | ||
</tr> | ||
<% FOREACH module IN permission %> | ||
<tr> | ||
<td> | ||
<a href="/pod/<% module.module_name %>"><% module.module_name %></a> | ||
</td> | ||
<td> | ||
<a href="/author/<% module.owner %>"><% module.owner %></a> | ||
</td> | ||
<td> | ||
<% FOREACH co_maintainer IN module.co_maintainers %> | ||
<a href="/author/<% co_maintainer %>"><% co_maintainer %></a> | ||
<% END %> | ||
</td> | ||
</tr> | ||
<% END %> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<% title = 'module permissions for ' . name %> | ||
|
||
<h1>Module Permissions</h1> | ||
|
||
<p> | ||
<a href="/pod/<% permission.module_name %>"><% permission.module_name %></a> is owned by <a href="/author/<% permission.owner %>"><% permission.owner %></a>. | ||
</p> | ||
|
||
<p> | ||
This module is also maintained by | ||
</p> | ||
|
||
<ul> | ||
<% FOREACH co_maintainer IN permission.co_maintainers %> | ||
<li><a href="/author/<% co_maintainer %>"><% co_maintainer %></a></li> | ||
<% END %> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use MetaCPAN::Web::Test; | ||
|
||
test_psgi app, sub { | ||
my $cb = shift; | ||
|
||
{ | ||
ok( my $res = $cb->( GET '/permission/module/DOESNTEXIST' ), | ||
'GET /permission/module/DOESNTEXIST' ); | ||
is( $res->code, 404, 'not found' ); | ||
} | ||
{ | ||
ok( my $res = $cb->( GET '/permission/module/Moose' ), | ||
'GET /permission/module/Moose' ); | ||
is( $res->code, 200, 'found' ); | ||
like( $res->content, qr{ETHER}, 'ETHER in content' ); | ||
} | ||
{ | ||
ok( my $res = $cb->( GET '/permission/distribution/DOESNTEXIST' ), | ||
'GET /permission/distribution/DOESNTEXIST' ); | ||
is( $res->code, 404, 'not found' ); | ||
} | ||
{ | ||
ok( my $res = $cb->( GET '/permission/distribution/Moose' ), | ||
'GET /permission/distribution/Moose' ); | ||
is( $res->code, 200, 'found' ); | ||
like( $res->content, qr{ETHER}, 'ETHER in content' ); | ||
} | ||
}; | ||
|
||
done_testing; |