Unverified Commit 629d527d authored by IKEDA Soji's avatar IKEDA Soji Committed by GitHub
Browse files

Tentative fix for issue #11 (#221)

A tentative fix for issue #11.
  - Override owner/editor in edit_list page by information on database.
  - Don't use memory cache when admin is updated by sync_include_admin().
Fundamental fix will be done after the next stable.
parent d8f9e842
......@@ -10765,6 +10765,29 @@ sub do_edit_list_request {
 
return 1 unless $in{'group'};
 
# Sync owner/editor in list config with database.
# FIXME: TENTATIVE FIX.
my @static_admins =
grep {$_ and $_->{'subscribed'}} @{$list->_get_admins || []};
my @subparams;
# Current static owners.
my $static_owner =
[grep { $->{'role'} and $->{'role'} eq 'owner' } @static_admins];
@subparams = qw(email gecos info profile reception visibility);
foreach my $u (@$static_owner) {
$u = {map { $_ => $u->{$_} } @subparams};
}
$list->{'admin'}{'owner'} = $static_owner;
# Current static editors.
my $static_editor =
[grep { $->{'role'} and $->{'role'} eq 'editor' } @static_admins];
@subparams = qw(email gecos info reception visibility);
foreach my $u (@$static_editor) {
$u = {map { $_ => $u->{$_} } @subparams};
}
$list->{'admin'}{'editor'} = $static_editor;
# FIXME: END OF TENTATIVE FIX.
my $config = Sympa::List::Config->new($list, config => $list->{'admin'});
my $schema = $config->get_schema($param->{'user'}{'email'});
 
......
......@@ -920,7 +920,7 @@ my %full_db_struct = (
'included_admin' => {
'struct' => 'int(1)',
'doc' =>
'set to 1 if user is admin by an external data source',
'set to 1 if user is admin by an external data source. Note that included_admin and subscribed_admin can both value 1',
'order' => 12,
},
'include_sources_admin' => {
......
......@@ -2774,7 +2774,7 @@ sub get_next_list_member {
=over
=item get_admins ( $role, [ filter => \@filters ] )
=item get_admins ( $role, [ filter =E<gt> \@filters ] )
I<Instance method>.
Gets users of the list with one of following roles.
......@@ -2835,7 +2835,16 @@ sub get_admins {
my $role = lc(shift || '');
my %options = @_;
my $admin_user = $self->_get_admins;
my $admin_user = $self->_cache_get('admin_user');
unless ($admin_user and @{$admin_user || []}) {
$admin_user = $self->_get_admins; # Get recent admins from database
if ($admin_user) {
$self->_cache_put('admin_user', $admin_user);
} else {
# If failed, reuse cache probably outdated.
$admin_user = $self->{_cached}{admin_user};
}
}
return unless $admin_user; # Returns void.
my %query = @{$options{filter} || []};
......@@ -2890,13 +2899,10 @@ sub get_admins {
return wantarray ? @users : [@users];
}
# Get recent admins from database.
sub _get_admins {
my $self = shift;
my $admin_user = $self->_cache_get('admin_user');
return $admin_user
if $admin_user and @{$admin_user || []};
my $sdm = Sympa::DatabaseManager->instance;
my $sth;
......@@ -2923,10 +2929,9 @@ sub _get_admins {
)
) {
$log->syslog('err', 'Unable to get admins for list %s', $self);
# Return cache probably outdated.
return $self->{_cached}{admin_user};
return undef;
}
$admin_user = $sth->fetchall_arrayref({}) || [];
my $admin_user = $sth->fetchall_arrayref({}) || [];
$sth->finish;
foreach my $user (@$admin_user) {
......@@ -2939,7 +2944,7 @@ sub _get_admins {
$user->{'update_date'} ||= $user->{'date'};
}
return $self->_cache_put('admin_user', $admin_user);
return $admin_user;
}
=over
......@@ -6949,9 +6954,12 @@ sub sync_include_admin {
## don't care about listmaster role
foreach my $role ('owner', 'editor') {
## Load a hash with the old admin users
my $old_admin_users =
{map { ($_->{'email'} => $_) } $self->get_admins($role)};
# Load a hash with the old admin users.
my $old_admin_users = {
map { ($_->{'email'} => $_) }
grep { $_ and $_->{'role'} and $_->{'role'} eq $role }
@{$self->_get_admins || []}
};
## Load a hash with the new admin user list from an include source(s)
my $new_admin_users_include;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment