eprints / eprints3.4

EPrints 3.4 core and releases
http://www.eprints.org/uk/index.php/eprints-3-4/
GNU Lesser General Public License v3.0
31 stars 28 forks source link

get_users_owned_eprints breaks eprint_status filters on Items page #395

Closed jesusbagpuss closed 3 months ago

jesusbagpuss commented 3 months ago

The User dataobject references a get_users_owned_eprints config method that can control the items considered 'owned' by a user: https://github.com/eprints/eprints3.4/blob/e08862948a02c4c3fde5acba50af1976b0031d5f/perl_lib/EPrints/DataObj/User.pm#L941-L966

If this method is defined, the status checkboxes on the Items page break, and all items are displayed.

To recreate, add the following to ~/archives/ARCHIVEID/cfg/cfg.d/z_get_users_owned_eprints.pl

# map some usernames to other user's items
my %connector_users = (
        editor => 1,
        editor2 => 2,
);

$c->{'get_users_owned_eprints'} = sub
{
    my( $session, $user, $dataset ) = @_;

    my $searchexp = $dataset->prepare_search( );

    my $username = $user->value( "username" );

    if( $user->value( "usertype" ) ne "editor" || !exists $connector_users{$username} )
    {
        $searchexp->add_field( $opts{dataset}->field( "userid" ), $user->id );
        return $searchexp->perform_search;
    }

    $searchexp->add_field( $dataset->field( "userid" ), $user->id . " " . $connector_users{$username}, "IN", "ANY" );
    return $searchexp->perform_search;
};

If you log in as a normal (non-editor) user, on the Manage deposits page, the status-filter checkboxes no longer work.

The solution is to pass the %opts hash into the config method, but I think it might be worth abstracting the default behaviour to a get_users_owned_eprints_actual method, so retaining the default behaviour for some cases is easier.

jesusbagpuss commented 3 months ago

NB I'll submit a possible fix for this in a mo'.

drn05r commented 3 months ago

Surely you just need to pass the $searchexp as well?

jesusbagpuss commented 3 months ago

Yes - and remove the intersect. My proposal passes the %opts, but I think having an 'actual' method (similar to some MetaFields) would make using the config function cleaner/easier.

See: https://github.com/eprints/eprints3.4/compare/master...jesusbagpuss:eprints3.4:issue-395?expand=1

I wasn't sure where the best place to put the example function was - in an extension, I'd add a blah.pl.example file, but in the core, I guessed adding it to the documentation was right.

drn05r commented 3 months ago

I have added description of all potential configuration options that do not appear in files at:

https://wiki.eprints.org/w/Miscellaneous_Config_Options

This includes get_users_owned_eprints. I don't think this wiki page is necessary a good place to add example functions but maybe create a sub page like:

https://wiki.eprints.org/w/Miscellaneous_Config_Options/get_users_owned_eprints

drn05r commented 3 months ago

I have now added https://wiki.eprints.org/w/Miscellaneous_Config_Options/get_users_owned_eprints