Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of moveUser SOAP method (#1903) #1904

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions default/sympa.wsdl
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,15 @@
<part name="return" type="xsd:boolean"/>
</message>

<message name="moveUserRequest">
<part name="current_email" type="xsd:string"/>
<part name="email" type="xsd:string"/>
</message>

<message name="moveUserResponse">
<part name="return" type="xsd:boolean"/>
</message>

<!-- portType part -->

<portType name="SympaPort">
Expand Down Expand Up @@ -411,6 +420,9 @@
<operation name="setCustom">
<input message="tns:setCustomRequest" />
<output message="tns:setCustomResponse" />
<operation name="moveUser">
<input message="tns:moveUserRequest" />
<output message="tns:moveUserResponse" />
</operation>
</portType>

Expand Down Expand Up @@ -717,6 +729,19 @@
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="moveUser">
<soap:operation soapAction="urn:sympasoap#moveUser"/>
<input>
<soap:body use="encoded"
namespace="urn:sympasoap"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded"
namespace="urn:sympasoap"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>

<!-- service part -->
Expand Down
95 changes: 94 additions & 1 deletion src/lib/Sympa/WWW/SOAP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
# Copyright 2017, 2018, 2019, 2020, 2021, 2022, 2023 The Sympa Community.
# Copyright 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 The Sympa Community.
# See the AUTHORS.md file at the top-level directory of this distribution
# and at <https://github.com/sympa-community/sympa.git>.
#
Expand Down Expand Up @@ -1568,6 +1568,99 @@ sub _get_reason_string {
return $string;
}

sub moveUser {
$log->syslog(
'info',
'(%s, current_email=%s, email=%s)',
@_
);
my $class = shift;
my $current_email = shift;
my $email = shift;


my $sender = $ENV{'USER_EMAIL'};
my $robot = $ENV{'SYMPA_ROBOT'};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting with the next release (maybe 6.2.73b.1 or 6.2.74), $ENV{SYMPA_ROBOT} will be replaced by $ENV{SYMPA_DOMAIN} (cf. this change).

my $remote_application_name = $ENV{'remote_application_name'};

unless ($sender) {
die SOAP::Fault->faultcode('Client')
->faultstring('User not specified')
->faultdetail('Use a trusted proxy or login first ');
}

unless ($email) {
die SOAP::Fault->faultcode('Client')
->faultstring('Incorrect number of parameters')
->faultdetail('Use : <current_email> <email>');
}

my $reject;
unless (Sympa::is_listmaster($robot, $sender)) {
$reject .= ', sender must be listmaster';
}

$current_email = Sympa::Tools::Text::canonic_email($current_email);
$email = Sympa::Tools::Text::canonic_email($email);

unless (Sympa::Tools::Text::valid_email($current_email)) {
$reject .= ', invalid current_email';
}
unless (Sympa::Tools::Text::valid_email($email)) {
$reject .= ', invalid email';
}

if ($reject) {
$log->syslog('info',
'change_email %s -> %s from %s refused%s',
$current_email, $email, $sender, $reject);
die SOAP::Fault->faultcode('Server')
->faultstring('Incorrect parameter')
->faultdetail("Incorrect parameter(s)$reject");
}

# Do the move_user
my $spindle = Sympa::Spindle::ProcessRequest->new(
context => $robot,
action => 'move_user',
current_email => $current_email,
email => $email,
sender => $sender,
md5_check => 1,
scenario_context => {
sender => $sender,
remote_host => $ENV{'REMOTE_HOST'},
remote_addr => $ENV{'REMOTE_ADDR'},
remote_application_name => $ENV{'remote_application_name'},
current_email => $current_email,
email => $email,
}
);

unless ($spindle and $spindle->spin) {
die SOAP::Fault->faultcode('Server')->faultstring('Internal error');
}

foreach my $report (@{$spindle->{stash} || []}) {
my $reason_string = get_reason_string($report, $robot);
if ($report->[1] eq 'auth') {
die SOAP::Fault->faultcode('Server')->faultstring('Not allowed.')
->faultdetail($reason_string);
} elsif ($report->[1] eq 'intern') {
die SOAP::Fault->faultcode('Server')
->faultstring('Internal error');
} elsif ($report->[1] eq 'notice') {
return SOAP::Data->name('result')->type('boolean')->value(1);
} elsif ($report->[1] eq 'user') {
die SOAP::Fault->faultcode('Server')->faultstring('Undef')
->faultdetail($reason_string);
}
}

return SOAP::Data->name('result')->type('boolean')->value(1);
}


1;
__END__

Loading