File Coverage

blib/lib/Catalyst/Plugin/RapidApp/CoreSchemaAdmin.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Catalyst::Plugin::RapidApp::CoreSchemaAdmin;
2 1     1   3696 use Moose::Role;
  1         2  
  1         9  
3 1     1   4930 use namespace::autoclean;
  1         3  
  1         8  
4              
5             with 'Catalyst::Plugin::RapidApp::RapidDbic';
6              
7 1     1   90 use RapidApp::Util qw(:all);
  1         1  
  1         475  
8 1     1   14 use Module::Runtime;
  1         2  
  1         7  
9              
10             before 'setup_components' => sub {
11             my $c = shift;
12             my $config = $c->config->{'Plugin::RapidApp::CoreSchemaAdmin'} || {};
13            
14             my $cmp_class = 'Catalyst::Model::RapidApp::CoreSchema';
15             Module::Runtime::require_module($cmp_class);
16            
17             my $cnf = $config->{RapidDbic} || {};
18              
19             # Unless the 'all_sources' option is set, limit RapidDbic grids to
20             # sources which are actually being used
21             unless($config->{all_sources} || $cnf->{limit_sources}) {
22             my %src = ();
23             ++$src{Session} if ($c->can('session'));
24             ++$src{User} and ++$src{Role} if ($c->can('_authcore_load_plugins'));
25             if ($c->can('_navcore_inject_controller')) {
26             ++$src{DefaultView};
27             ++$src{SavedState};
28             ++$src{NavtreeNode};
29             }
30             my @limit_sources = keys %src;
31             # If none of the above sources were added, don't configure the CoreSchema
32             # tree item for RapidDbic at all:
33             return unless (scalar @limit_sources > 0);
34             $cnf->{limit_sources} = \@limit_sources;
35             }
36            
37             # By default, set 'require_role' to administrator since this is
38             # typically used with AuthCore and only admins should be able to access
39             # these system-level configs. Note that no default role_checker is
40             # setup when there is no Catalyst user auth/sessions, meaning this has
41             # no effect in that case.
42             $cnf->{require_role} ||= 'administrator';
43            
44             $cnf->{grid_params} ||= {
45             '*defaults' => {
46             updatable_colspec => ['*'],
47             creatable_colspec => ['*'],
48             destroyable_relspec => ['*'],
49             },
50             Role => {
51             no_page => 1,
52             persist_immediately => { create => \0, update => \0, destroy => \0 },
53             extra_extconfig => { use_add_form => \0 }
54             },
55             User => {
56             no_page => 1,
57             toggle_edit_cells_init_off => 0
58             }
59             };
60            
61             $cmp_class->config( RapidDbic => $cnf );
62             };
63              
64             1;
65              
66              
67             __END__
68              
69             =head1 NAME
70              
71             Catalyst::Plugin::RapidApp::CoreSchemaAdmin - CRUD access to the CoreSchema via RapidDbic
72              
73             =head1 SYNOPSIS
74              
75             package MyApp;
76            
77             use Catalyst qw/
78             RapidApp::RapidDbic
79             RapidApp::AuthCore
80             RapidApp::CoreSchemaAdmin
81             /;
82              
83             =head1 DESCRIPTION
84              
85             This convenience plugin automatically sets up access to
86             L<Model::RapidApp::CoreSchema|Catalyst::Model::RapidApp::CoreSchema>
87             via the RapidDbic plugin. This is basically just an automatic RapidDbic config.
88              
89             When used with L<AuthCore|Catalyst::Plugin::RapidApp::AuthCore> (which is
90             typically the whole reason you would want this plugin in the first place), the RapidApp
91             Module config option C<require_role> is set by default to C<'administrator'> on the
92             automatically configured tree/grids, since the CoreSchema usually contains the
93             privileged user database for the app (although, not necessarily).
94              
95             Also, by default, only CoreSchema sources which are actually in use by a given
96             Core plugin are configured for access (in the navtree/grids). For instance, the
97             "Sessions" grid is only setup when AuthCore is loaded, "Source Default Views"
98             is only setup with NavCore, and so on.
99              
100             =head1 SEE ALSO
101              
102             =over
103              
104             =item *
105              
106             L<RapidApp::Manual::Plugins>
107              
108             =item *
109              
110             L<Catalyst::Plugin::RapidApp::RapidDbic>
111              
112             =item *
113              
114             L<Catalyst::Plugin::RapidApp::AuthCore>
115              
116             =item *
117              
118             L<Catalyst::Plugin::RapidApp::CoreSchema>
119              
120             =item *
121              
122             L<Catalyst>
123              
124             =back
125              
126             =head1 AUTHOR
127              
128             Henry Van Styn <vanstyn@cpan.org>
129              
130             =head1 COPYRIGHT AND LICENSE
131              
132             This software is copyright (c) 2013 by IntelliTree Solutions llc.
133              
134             This is free software; you can redistribute it and/or modify it under
135             the same terms as the Perl 5 programming language system itself.
136              
137             =cut