Skip to content

Commit

Permalink
This adds the create_new_list service to the PHP client, and finished…
Browse files Browse the repository at this point in the history
… up the implementation of the service for everyone
  • Loading branch information
justingit committed Sep 15, 2021
1 parent 34b986f commit 999f4be
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 54 deletions.
80 changes: 27 additions & 53 deletions dada/DADA/App/WebServices.pm
Expand Up @@ -116,22 +116,14 @@ 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
$DADA::Config::GLOBAL_API_OPTIONS->{public_key} )
)
{

warn 'here.';

$self->ls_obj(
DADA::MailingList::Settings->new( { -list => $self->r_list } ) );
$self->global_level(1);
Expand All @@ -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} )
)
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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;
}
Expand All @@ -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(
Expand Down Expand Up @@ -712,22 +711,14 @@ 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}
) <= 0
)
{

warn 'yes.';

$status = 0;
$errors = { clone_list_no_exists => 1 };
return {
Expand All @@ -739,8 +730,6 @@ sub create_new_list {
}
else {

warn 'yes.';

$ls = DADA::MailingList::Create(
{
-list => $settings->{list},
Expand All @@ -754,8 +743,6 @@ sub create_new_list {
}
else {

warn 'yes.';

$ls = DADA::MailingList::Create(
{
-list => $settings->{list},
Expand Down Expand Up @@ -814,12 +801,10 @@ sub create_new_list {
};
}

use Data::Dumper;

return {
status => 1,
results => {
settings => Dumper($settings),
settings => $settings,
}
};
}
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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};
Expand Down
Expand Up @@ -455,6 +455,38 @@ String, B<default: undef>. If a valid list short name is password, list settings

=back

B<Note>: Pass a blank/undefined value for the, "list" in the C<request> method for both the Perl and PHP clients! The C<list> you want the new list to have will be passed in the C<settings> 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

Expand Down
15 changes: 14 additions & 1 deletion dada/extras/scripts/webservices/DadaMailWebService.php
Expand Up @@ -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']);
Expand Down

0 comments on commit 999f4be

Please sign in to comment.