EPrints Technical Mailing List Archive

See the EPrints wiki for instructions on how to join this mailing list and related information.

Message: #09673


< 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


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

image.png
User dengan spesifik user roles diatas 2 unggahan

image.png
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/