EPrints Technical Mailing List Archive
See the EPrints wiki for instructions on how to join this mailing list and related information.
Message: #09674
< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First
Re: [EP-tech] Limit user create new item
- To: Agung Prasetyo W. <prazetyo@gmail.com>
- Subject: Re: [EP-tech] Limit user create new item
- From: David R Newman <drn@ecs.soton.ac.uk>
- Date: Thu, 7 Mar 2024 14:22:56 +0000
Hi Agung,
If you do want to hide the import bar, a slightly different approach is needed. You still need a local version of the screen plugin put this time you need to add the file cfg/plugins/EPrints/Plugin/Screen/LocalImport.pm to your archive with the following contents:
package
EPrints::Plugin::Screen::LocalImport;
use EPrints::Plugin::Screen::Import;
our @ISA = qw/ EPrints::Plugin::Screen::Import /;
sub render_import_bar
{
my( $self ) = @_;
my $user = $self->{session}->current_user;
if ( $user->get_value( 'usertype' ) eq "user" &&
$user->owned_eprints_list->count >= 2 )
{
return $self->{session}->make_doc_fragment;
}
return $self->SUPER::render_import_bar();
}
1;
Basically this renders and empty import bar if a regular user has two or more items. (Again you will need to adapt the logic if the user needs to match a specific role). Like with adding the other local plugin, you need to add the following two lines to your archive's cfg/cfg.d/plugins.pl or a new configuration file in the same directory:
$c->{plugin_alias_map}->{"Screen::Import"}
= "Screen::LocalImport";
$c->{plugin_alias_map}->{"Screen::LocalImport"} = undef;
Regards
David Newman
CAUTION: This e-mail originated outside the University of Southampton.Hi,
User dengan spesifik user roles diatas 2 unggahan --> Users with specific user roles above 2 uploads
User dengan spesifik user roles dibawah 2 unggahan --> Users with specific user roles below 2 uploads
Regards,Agung PW
On Thu, 7 Mar 2024 at 20:57, Agung Prasetyo W. <prazetyo@gmail.com> wrote:
Hi David,I've tried the script you suggested , and it runs successfully. However, the import from the menu still appears, but this is not a problem.Below is the screenshot
User dengan spesifik user roles diatas 2 unggahan
User dengan spesifik user roles dibawah 2 unggahan
Thank you David. It's working.
Best regards,Agung PW
On Thu, 7 Mar 2024 at 19:37, David R Newman <drn@ecs.soton.ac.uk> wrote:
Hi Agung,
You should just be able to change the "if" line from:
if ( $user->get_value( 'usertype' ) eq "user" && $user->owned_eprints_list->count >= 2 )
To:
if ( $user->has_role( "staff-view" ) && $user->owned_eprints_list->count >= 2 )
You may need to change the role to the appropriate role (currently staff-view) for your requirements. The following page lists the default roles and privileges and how they are assigned to different user types:
https://wiki.eprints.org/w/Listings_of_User_Roles_and_Privileges
Regards
David Newman
On 07/03/2024 11:03, Agung Prasetyo W. wrote:
CAUTION: This e-mail originated outside the University of Southampton.Hi David,
Thank you very much for your help.But I want to ask a little more. Is it possible to apply it specifically to certain user roles?
Thank you.
Regards,Agung Prasetyo W.
On Thu, 7 Mar 2024 at 17:30, David R Newman <drn@ecs.soton.ac.uk> wrote:
Hi Agung,
I think you can implement a "soft" restriction, which just removes the "New Item" button on the "Manage Deposits" page. However, this would still allow new items to be created from Import or by using the "New Version" button under an item they has already created. So you may want to use a similar approach to as below disable those buttons.
Create a file in your local archive called cfg/plugins/EPrints/Plugin/Screen/LocalNewEPrint.pm with the following code:
package EPrints::Plugin::Screen::LocalNewEPrint;
use EPrints::Plugin::Screen::NewEPrint;
our @ISA = qw/ EPrints::Plugin::Screen::NewEPrint /;
sub allow_create
{
my ( $self ) = @_;
my $user = $self->{session}->current_user;
if ( $user->get_value( 'usertype' ) eq "user" && $user->owned_eprints_list->count >= 2 )
{
return 0;
}
return $self->allow( "create_eprint" );
}
1;
The you need to either edit your archive's cfg/cfg.d/plugins.pl or create a new config file under your archive (e.g. cfg/cfg.d/z_restrict_new_items.pl) and add the following two lines:
$c->{plugin_alias_map}->{"Screen::NewEPrint"} = "Screen::LocalNewEPrint";
$c->{plugin_alias_map}->{"Screen::LocalNewEPrint"} = undef;
Run "epadmin test" and then reload you web server and this should prevent users of regular user type from seeing the "New Item" button on their "Manage Deposits" page if they already have two or more items. If you want to restrict other types of user as well you will need to modify LocalNewEPrint.pm appropriately.
Regards
David Newman
On 07/03/2024 04:06, Agung Prasetyo W. wrote:
CAUTION: This e-mail originated outside the University of Southampton.CAUTION: This e-mail originated outside the University of Southampton.Hi,
Is it possible to limit creating new items per user to only 2 times. If there is, please tell me how to do it.
Thank you.
Regards,Agung PW
*** Options: https://wiki.eprints.org/w/Eprints-tech_Mailing_List *** Archive: https://www.eprints.org/tech.php/ *** EPrints community wiki: https://wiki.eprints.org/
- Follow-Ups:
- Re: [EP-tech] Limit user create new item
- From: "Agung Prasetyo W." <prazetyo@gmail.com>
- Re: [EP-tech] Limit user create new item
- References:
- [EP-tech] Limit user create new item
- From: "Agung Prasetyo W." <prazetyo@gmail.com>
- Re: [EP-tech] Limit user create new item
- From: David R Newman <drn@ecs.soton.ac.uk>
- Re: [EP-tech] Limit user create new item
- From: "Agung Prasetyo W." <prazetyo@gmail.com>
- Re: [EP-tech] Limit user create new item
- From: David R Newman <drn@ecs.soton.ac.uk>
- Re: [EP-tech] Limit user create new item
- From: "Agung Prasetyo W." <prazetyo@gmail.com>
- Re: [EP-tech] Limit user create new item
- From: "Agung Prasetyo W." <prazetyo@gmail.com>
- [EP-tech] Limit user create new item
- Prev by Date: Re: [EP-tech] Limit user create new item
- Next by Date: Re: [EP-tech] Limit user create new item
- Previous by thread: Re: [EP-tech] Limit user create new item
- Next by thread: Re: [EP-tech] Limit user create new item
- Index(es):