From 999f4be4d476ed34642794522b2b65fb903615cd Mon Sep 17 00:00:00 2001 From: justingit Date: Wed, 15 Sep 2021 15:04:38 -0600 Subject: [PATCH] This adds the create_new_list service to the PHP client, and finished up the implementation of the service for everyone --- dada/DADA/App/WebServices.pm | 80 +++++++------------ .../features-restful_web_services.pod | 32 ++++++++ .../webservices/DadaMailWebService.php | 15 +++- 3 files changed, 73 insertions(+), 54 deletions(-) diff --git a/dada/DADA/App/WebServices.pm b/dada/DADA/App/WebServices.pm index bd94274fa..756f401fb 100644 --- a/dada/DADA/App/WebServices.pm +++ b/dada/DADA/App/WebServices.pm @@ -116,13 +116,7 @@ sub request { $self->r_digest( $args->{-digest} ); $self->r_cgi_obj( $args->{-cgi_obj} ); } - - warn '$self->check_list(): ' . $self->check_list(); - warn '$self->r_list: ' . $self->r_list; - warn '$self->r_public_key: ' . $self->r_public_key; - warn '$DADA::Config::GLOBAL_API_OPTIONS->{public_key}: ' - . $DADA::Config::GLOBAL_API_OPTIONS->{public_key}; - + if ( ( $self->check_list() == 1 ) && ( $self->r_public_key eq @@ -130,8 +124,6 @@ sub request { ) { - warn 'here.'; - $self->ls_obj( DADA::MailingList::Settings->new( { -list => $self->r_list } ) ); $self->global_level(1); @@ -148,7 +140,10 @@ sub request { else { # If there's a list that's passed, but it's invalid, this shouldn't workL if ( - ( $self->r_list eq undef ) + + ($self->r_list eq undef) || (length($self->r_list) <= 0) + + && ( $self->r_public_key eq $DADA::Config::GLOBAL_API_OPTIONS->{public_key} ) ) @@ -545,8 +540,6 @@ sub update_profile_fields { my $profile_fields = $self->r_cgi_obj->param('profile_fields'); $profile_fields = $json->decode($profile_fields); - #warn 'pf:' . $profile_fields; - # check to see if profiles exist? # Actually, it doesnm't matter to me if the profile exists or not, @@ -604,11 +597,20 @@ sub create_new_list { my $status = 0; my $errors = {}; + + if($self->global_level() == 0){ + return { + status => 0, + results => { + error => 'requires_global_keys', + } + }; + } -=pod # OK, so remember we need to do a list quota check: + my @t_lists = available_lists(); if(strip($DADA::Config::LIST_QUOTA) eq '') { $DADA::Config::LIST_QUOTA = undef; } @@ -619,27 +621,24 @@ sub create_new_list { if ( defined($DADA::Config::LIST_QUOTA) && ( ( $#t_lists + 1 ) >= $DADA::Config::LIST_QUOTA ) ) { - return user_error( - { -list => $list, -error => "over_list_quota" } ); + return { + status => 0, + results => { + error => 'over_list_quota', + } + }; } my @available_lists = DADA::App::Guts::available_lists(); my $lists_exist = $#available_lists + 1; -=cut my $settings = $self->r_cgi_obj->param('settings'); $settings = $json->decode($settings); - warn '$self->r_cgi_obj->param(\'options\'): ' - . $self->r_cgi_obj->param('options'); - my $options = $self->r_cgi_obj->param('options'); - $options = $json->decode($options); - - use Data::Dumper; - warn '$options: ' . Dumper($options); + $options = $json->decode($options) // {}; my $list_exists = check_if_list_exists( -List => $settings->{list} ); my ( $list_errors, $flags ) = check_list_setup( @@ -712,13 +711,7 @@ sub create_new_list { my $ls; if ( exists( $options->{clone_settings_from_list} ) ) { - warn 'yes.'; - - warn -'check_if_list_exists(-List => $options->{clone_settings_from_list}: ' - . check_if_list_exists( - -List => $options->{clone_settings_from_list} ); - + if ( check_if_list_exists( -List => $options->{clone_settings_from_list} @@ -726,8 +719,6 @@ sub create_new_list { ) { - warn 'yes.'; - $status = 0; $errors = { clone_list_no_exists => 1 }; return { @@ -739,8 +730,6 @@ sub create_new_list { } else { - warn 'yes.'; - $ls = DADA::MailingList::Create( { -list => $settings->{list}, @@ -754,8 +743,6 @@ sub create_new_list { } else { - warn 'yes.'; - $ls = DADA::MailingList::Create( { -list => $settings->{list}, @@ -814,12 +801,10 @@ sub create_new_list { }; } - use Data::Dumper; - return { status => 1, results => { - settings => Dumper($settings), + settings => $settings, } }; } @@ -845,24 +830,18 @@ sub check_request { $errors->{invalid_digest} = 1; } - warn '$self->check_list(): ' . $self->check_list(); - if ( $self->check_list() == 0 ) { - warn '$self->global_level: ' . $self->global_level; - warn '$self->r_list: ' . $self->r_list; - warn '$self->r_service: ' . $self->r_service; - if ( $self->global_level == 1 - && $self->r_list eq undef + && ( + ($self->r_list eq undef) || (length($self->r_list) <= 0) + ) && $self->r_service eq 'create_new_list' ) { # Special Case - this is fine. } else { - warn 'nope.'; - $status = 0; $errors->{invalid_list} = 1; } @@ -878,9 +857,6 @@ sub check_request { sub check_nonce { my $self = shift; - warn '$self->r_cgi_obj->param(\'nonce\'): ' - . $self->r_cgi_obj->param('nonce'); - my ( $timestamp, $nonce ) = split( ':', $self->r_cgi_obj->param('nonce') ); my $r = 0; @@ -908,8 +884,6 @@ sub check_public_key { # is what's passed in the request, so I guess this sort of makes sense: # - warn '$self->global_level : ' . $self->global_level; - my $tmp_public_key = undef; if ( $self->global_level == 1 ) { $tmp_public_key = $DADA::Config::GLOBAL_API_OPTIONS->{public_key}; diff --git a/dada/extras/documentation/pod_source/features-restful_web_services.pod b/dada/extras/documentation/pod_source/features-restful_web_services.pod index d84072278..b2567626e 100644 --- a/dada/extras/documentation/pod_source/features-restful_web_services.pod +++ b/dada/extras/documentation/pod_source/features-restful_web_services.pod @@ -455,6 +455,38 @@ String, B. If a valid list short name is password, list settings =back +B: Pass a blank/undefined value for the, "list" in the C method for both the Perl and PHP clients! The C you want the new list to have will be passed in the C paramaters. + +Here's an example of using the php client to create a new list: + + # List is undefined + # public and private key are GLOBAL + $ws = new DadaMailWebService( + $server, + $public_key, + $private_key + ); + $params = [ + 'settings' => [ + 'list' => 'newlistname', + 'privacy_policy' => "privacy_policy", + 'list_name' => "New List Name", + 'list_owner_email' => 'listowner@example.com', + 'password' => "password" , + 'info' => "this is my list info", + 'physical_address' => "This is the physical address", + ], + 'options' => [ + 'send_new_list_welcome_email' => 1, + 'send_new_list_welcome_email_with_list_pass' => 1, + 'clone_settings_from_list' => 'existinglist', + ] + ]; + $results = $ws->request( + $list, + 'create_new_list', + $params + ); =head4 validate_subscription diff --git a/dada/extras/scripts/webservices/DadaMailWebService.php b/dada/extras/scripts/webservices/DadaMailWebService.php index e70100ef2..b437c212f 100644 --- a/dada/extras/scripts/webservices/DadaMailWebService.php +++ b/dada/extras/scripts/webservices/DadaMailWebService.php @@ -91,7 +91,20 @@ public function request($list, $service, $params = false) case 'settings': $digest = $this->digest($nonce); break; - case 'validate_subscription': + case 'create_new_list': + + $encoded_settings = json_encode($params['settings']); + $encoded_options = json_encode($params['options']); + $query_params = array( + 'nonce' => $nonce, + 'options' => $encoded_options, + 'settings' => $encoded_settings + ); + $rpd = $this->the_query_string($query_params); + $digest = $this->digest($rpd); + break; + + case 'validate_subscription': case 'subscription': case 'unsubscription': $encoded_addresses = json_encode($params['addresses']);