adding new event code
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 5 Dec 2005 22:51:21 +0000 (22:51 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 5 Dec 2005 22:51:21 +0000 (22:51 +0000)
check_perm utility method on AppUtils new returns an OpenILS::Event.. this should be the method of choice
moving forward for permission checks
added a DATADIR var to the install process (ils_events.xml lives here)

git-svn-id: svn://svn.open-ils.org/ILS/trunk@2233 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
Open-ILS/src/perlmods/OpenILS/Event.pm [new file with mode: 0644]
config.sh
install.sh

index c768415..d58fb1d 100644 (file)
@@ -2,6 +2,7 @@ package OpenILS::Application::Actor;
 use base qw/OpenSRF::Application/;
 use strict; use warnings;
 use Data::Dumper;
+use OpenILS::Event;
 
 use Digest::MD5 qw(md5_hex);
 
index 17036e2..a625f5f 100644 (file)
@@ -64,7 +64,7 @@ sub check_user_perms {
 sub check_perms {
        my( $self, $user_id, $org_id, @perm_types ) = @_;
        my $t = $self->check_user_perms( $user_id, $org_id, @perm_types );
-       return OpenILS::Perm->new($t) if $t;
+       return OpenILS::Event->new('PERM_FAILURE', perm => $t, permloc => $org_id ) if $t;
        return undef;
 }
 
diff --git a/Open-ILS/src/perlmods/OpenILS/Event.pm b/Open-ILS/src/perlmods/OpenILS/Event.pm
new file mode 100644 (file)
index 0000000..dcb518f
--- /dev/null
@@ -0,0 +1,68 @@
+package OpenILS::Event;
+use strict; use warnings;
+use XML::LibXML;
+use OpenSRF::Utils::SettingsClient;
+use OpenSRF::Utils::Logger;
+my $logger = "OpenSRF::Utils::Logger";
+
+
+# Creates a new Event object.  
+# The first param is the event name
+# Following the first param is an optional hash of params:
+#              perm => the name of the permission error for permimssion errors
+#              permloc => the location of the permission error for permission errors
+#              payload => the payload to be returned on successfull events
+
+
+my $events = undef;
+sub new {
+       my( $class, $event, %params ) = @_;
+
+       my $perm = $params{perm};
+       my $permloc = $params{permloc};
+       my $payload = $params{payload};
+
+       _load_events() unless $events;
+
+       if( $event ne 'SUCCESS' ) {
+               my $p = (defined $perm) ? $perm : "(none)";
+               my $pl = (defined $permloc) ? $permloc  : "(none)";
+               my $pa = (defined $payload) ? $payload : "(none)";
+               $logger->warn("Returning event object $event " . 
+                       "{ ilsperm => $p, ilspermloc => $pl, payload => $pa }");
+       }
+
+       my $e = $events->{$event};
+       throw OpenSRF::EX 
+               ("No event defined with textcode: $event") unless defined $e;
+
+       my $h = { ilsevent => $e };
+       $h->{paylod}            = $payload if defined $payload;
+       $h->{ilsperm}           = $perm if defined $perm;
+       $h->{ilspermloc}        = $permloc if defined $permloc;
+       $h->{textcode}          = $event;
+
+       return $h;
+}
+
+sub _load_events {
+       my $settings_client = OpenSRF::Utils::SettingsClient->new();
+       my $eventsxml =  $settings_client->config_value( "ils_events" );
+#      my $eventsxml =  "/openils/conf/ils_events.xml";
+
+       if(!$eventsxml) { 
+               throw OpenSRF::EX ("No ils_events file found in settings config"); 
+       }
+
+       $logger->info("Loading events xml file $eventsxml");
+
+       my $doc = XML::LibXML->new->parse_file($eventsxml);
+
+       my @nodes = $doc->documentElement->findnodes('//event');
+       for my $node (@nodes) {
+               $events->{$node->getAttribute('textcode')} = 
+                       $node->getAttribute('code');
+       }
+}
+
+1;
index c053245..6c53001 100755 (executable)
--- a/config.sh
+++ b/config.sh
@@ -46,6 +46,7 @@ function buildConfig {
        INCLUDEDIR="$PREFIX/include/";
        ETCDIR="$PREFIX/conf";
        WEBDIR="$PREFIX/var/web";
+       DATADIR="$PREFIX/var/data";
        CGIDIR="$PREFIX/var/cgi-bin";
        TEMPLATEDIR="$PREFIX/var/templates";
        CIRCRULESDIR="$PREFIX/var/circ";
@@ -113,6 +114,7 @@ function writeConfig {
        _write "SOCK=\"$PREFIX/var/sock\"";
        _write "PID=\"$PREFIX/var/pid\"";
        _write "LOG=\"$PREFIX/var/log\"";
+       _write "DATADIR=\"$DATADIR\"";
 
        _write "TMP=\"$TMP\"";
        _write "APXS2=\"$APXS2\"";
index b101a5c..b142eee 100755 (executable)
@@ -121,7 +121,7 @@ function runInstall {
                        BINDIR=$BINDIR LIBDIR=$LIBDIR PERLDIR=$PERLDIR INCLUDEDIR=$INCLUDEDIR \
                        WEBDIR=$WEBDIR TEMPLATEDIR=$TEMPLATEDIR ETCDIR=$ETCDIR REPORTERDIR=$REPORTERDIR\
                        OPENSRFDIR=$OPENSRFDIR OPENILSDIR=$OPENILSDIR EVERGREENDIR=$EVERGREENDIR \
-                       CIRCRULESDIR=$CIRCRULESDIR CGIDIR=$CGIDIR DBDRVR=$DBDRVR DBHOST=$DBHOST \
+                       CIRCRULESDIR=$CIRCRULESDIR CGIDIR=$CGIDIR DBDRVR=$DBDRVR DBHOST=$DBHOST DATADIR=$DATADIR\
                        DBNAME=$DBNAME DBUSER=$DBUSER DBPW=$DBPW XSLDIR=$XSLDIR NEW_OPAC_URL=$NEW_OPAC_URL \
                        NEW_XUL_PACKAGE_NAME=$NEW_XUL_PACKAGE_NAME NEW_XUL_PACKAGE_LABEL=$NEW_XUL_PACKAGE_LABEL";